ERPNext + Python 3

Hi,
I’m new to EXPNext but I do know python and I would like to help out by testing new installs on Debian. Here are the steps that I used :slight_smile:

apt update
apt upgrade
locale-gen en_US.UTF-8
apt install -y python3 python3-pip
echo "frappe ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
wget https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py
python3 install.py --production --user frappe --mysql-root-password ***** --admin-password ****

Please let me know if this is the ideal way to do a fresh install

TIA!

GitHub - pyenv/pyenv: Simple Python version management could be used to have our own python version if needed

1 Like

I tried it with PyPy.
It worked seamlessly (almost). I could see some performance improvements too!

Known issues:

  • PyPDF2 merging (using PdfFileWriter class) doesn’t work.
3 Likes

Can you write it up? Maybe a page on the wiki?
And what was the use case for PyPy or was this just an experiment?

Its simple really.

# Add PyPy repository
sudo add-apt-repository ppa:pypy/ppa
sudo apt-get update

# Install relevant packages
sudo apt-get install pypy pypy-dev

# Install dependencies
sudo apt-get install libxml2-dev libxslt1-dev
sudo pip install lxml

# Migrate environment! (execute from your bench instance)
bench migrate-env pypy

This was an experiment, primarily to check out the perfromance of PyPy compared to Python. It advertises 7.6 times faster performance.

I did not test benchmarks, but there was some visible improvement in comparison to Python.

However, it is not as stable as Python. If your instance requires PyPDF2’s merging features, you must use Python. Another alternative might be to make use of both implementations to get a proper balance of performance and stability.

4 Likes

Hello;

I succeeded with bench migrate-env python3 but I am facing problem when I run bench update --reset as I am getting this error:

TypeError: the JSON object must be str, not ‘bytes’

I faced the problem of Command "python setup.py egg_info" failed with error code 1 but the solution was by modifying the setup.py file at the repository of the custom application.
(Reference: [Solved]Command "python setup.py egg_info" failed with error code 1).

And below is the details

Updating Python libraries…
INFO:bench.utils:./env/bin/pip install --upgrade pip
Requirement already up-to-date: pip in ./env/lib/python3.5/site-packages (19.0.1)
INFO:bench.utils:./env/bin/pip install -q -r /home/frappe/.bench/requirements.txt
INFO:bench.app:installing frappe
INFO:bench.utils:./env/bin/pip install -q -e ./apps/frappe
INFO:bench.app:installing erpnext
INFO:bench.utils:./env/bin/pip install -q -e ./apps/erpnext
INFO:bench.app:installing taxi
INFO:bench.utils:./env/bin/pip install -q -e ./apps/taxi
INFO:bench.app:installing travel_agency
INFO:bench.utils:./env/bin/pip install -q -e ./apps/travel_agency
INFO:bench.app:installing notary
INFO:bench.utils:./env/bin/pip install -q -e ./apps/notary
Updating node packages…
INFO:bench.utils:yarn install
yarn install v1.13.0
[1/4] Resolving packages…
success Already up-to-date.
Done in 0.75s.
Backing up sites…
Patching sites…
Migrating site1.local
Updating DocTypes for frappe : [========================================]
Updating DocTypes for erpnext : [========================================]
Updating DocTypes for taxi : [========================================]
Updating DocTypes for travel_agency : [========================================]
Updating DocTypes for notary : [========================================]
Traceback (most recent call last):
File “/usr/lib/python3.5/runpy.py”, line 184, in _run_module_as_main
main”, mod_spec)
File “/usr/lib/python3.5/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 97, in
main()
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 18, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/click/core.py”, line 764, in call
return self.main(*args, **kwargs)
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/click/core.py”, line 717, in main
rv = self.invoke(ctx)
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/click/core.py”, line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/click/core.py”, line 555, in invoke
return callback(*args, **kwargs)
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/init.py”, line 25, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py”, line 227, in migrate
migrate(context.verbose, rebuild_website=rebuild_website)
File “/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py”, line 53, in migrate
router.sync_global_search()
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/router.py”, line 355, in sync_global_search
sync_global_search()
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/global_search.py”, line 314, in sync_global_search
value = json.loads(frappe.cache().lpop(‘global_search_queue’))
File “/usr/lib/python3.5/json/init.py”, line 312, in loads
s.class.name))
TypeError: the JSON object must be str, not ‘bytes’
frappe@Bilal:~/frappe-bench$

ERPNext and Frappe is version 11.1.3 master

Regards
Bilal

This should be fixed with fix(sync_global_search): decode json object as str by Thunderbottom · Pull Request #6867 · frappe/frappe · GitHub

@achillesrasquinha, is it production ready? thanks

1 Like

@achillesrasquinha, is ERPNext with python 3 really not production ready or is it just the python 2 to python 3 migration which is not ready ?
I’m asking because I plan to setup a new “production” ERPNext instance and I would prefer to go directly to python 3 instead of going through the hassle of later migrating…

We’ve been using python3.7 with ERPNext for 4 months now on our production with thousands of transactions per day. Runs as smooth as butter.

7 Likes

Successfully migrated to Python 3 with no issues using these three lines:

sudo apt-get install python3-dev
bench migrate-env python3
bench update
6 Likes

@Shazomii

Thanks for your suggestion, it works on production VM.

Now it works with python3

Installed Apps
ERPNext: v11.1.39 (master)

Frappe Framework: v11.1.36 (master)

1 Like

I got updating …msg when i accessed the site. So for me below steps worked

sudo apt-get install python3-dev
bench migrate-env python3
bench restart
bench update

1 Like

May be it is for development not for production (master). Is the reason you restart bench?

Just migrated to Python3.6 (on ERPNext v12.1.1). Getting an SMTP data error when sending out emails with PDF attachments (smtplib.SMTPDataError: (501, b’Syntax error - line too long’)).

Just wanted to know if you have tested for sending out emails with pdf attachments (of sales order etc) and do not face any issues? Will appreciate clarification as our server on python3 is unable to send emails with pdf attachments of sales orders, invoices, etc. Works fine on Python2.7.

No errorsin log here in a Ubuntu Bionic VM. PDF format not right yet though.

ERPNext: v12.1.1 (version-12)
Frappe Framework: v12.0.11 (version-12)

In [3]: print (sys.version)
3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]

Thank you for sharing the log. Assuming your comment that PDF format is not right - could potentially be causing this issue?

Also not sure how to interpret the log. Does it show a print test (which btw is working for us on python3) or an SMTP test email with PDF attached?

As mentioned above, PDF generation and visual format seem to work fine. We are getting an SMTP error when we send PDF by email. online search of error suggests that error is related to having a data string in email / PDF > 998 chars which is being rejected by the SMTP server.

Did you mean same when you said PDF format is not right?

I don’t think the PDF format problem, since resolved,is causing your problem, In my case it has due to not having the hostname set to the ip of the host in site_config.json.

Can anyone confirm that V12+Python3 is able to send email with pdf attachment?

I can confim this.