Python Forum
how difficult its to move to Python 3.8 from Python 2.7 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: how difficult its to move to Python 3.8 from Python 2.7 (/thread-23916.html)



how difficult its to move to Python 3.8 from Python 2.7 - dkirandasari - Jan-22-2020

Hello All,
I am working for a health insurance company as a python developer and we were using python 2.7 and willing to move to Python 3.8 as soon as possible due to the EOL of Python 2. We have a big mobile service using Python 2. I am not a big expert in this and would like to know How difficult its and what are the typical issues in this regard.
Thanks in advance,
Kumar


RE: how difficult its to move to Python 3.8 from Python 2.7 - micseydel - Jan-22-2020

It really depends on your project. Start with 2to3, which will do a lot of the tedious work for you, and test thoroughly.

In my experience, half or more of the effort is dealing with bytes vs str. I recommend you use type hinting and mypy to go back and validate those parts of your code.

A lot of people find the migration difficult enough that they've waited this long, so I don't want to suggest that it's going to be easy. I'd love it if you post back here with any findings though, it might inspire a tutorial on doing such a migration.


RE: how difficult its to move to Python 3.8 from Python 2.7 - dkirandasari - Jan-23-2020

(Jan-22-2020, 10:06 PM)micseydel Wrote: It really depends on your project. Start with 2to3, which will do a lot of the tedious work for you, and test thoroughly. In my experience, half or more of the effort is dealing with bytes vs str. I recommend you use type hinting and mypy to go back and validate those parts of your code. A lot of people find the migration difficult enough that they've waited this long, so I don't want to suggest that it's going to be easy. I'd love it if you post back here with any findings though, it might inspire a tutorial on doing such a migration.
Hello micseydel, Thanks for the response. So, does it mean we can use the old code for the existing app?
And also the error we are getting is ERROR: Package 'setuptools' requires a different Python: 2.7.12 not in '>=3.5'
does it mean the issue is with the setuptools only or any others?


RE: how difficult its to move to Python 3.8 from Python 2.7 - rmspacedashrf - Jan-23-2020

can you explain what program, application, script etc you are attempting to run when you generate the error regarding 'setuptools'? I want to know what you are running and how you are running it. what operating system are you using and if you are telnet ssh vm remote etc.. what environment are you remote into? example: "using putty on windows to ssh into a linux server in the cloud running a shell script to install a custom built medical application from source. some of the required libraries are compiled to binary with gcc and some are python2.7 libraries that do not need to be compiled"

you might find that your installer is python but your application is written in something else. they do this because some programmers do not write scripts in bash.

we need a lot more information before we can see where it performs the version check. we can override the check. we also need to check dependencies. then we need to scan the code for functions that can only work in python 2.7. depending on your situation it could be easy or it could be hard.


RE: how difficult its to move to Python 3.8 from Python 2.7 - DeaD_EyE - Jan-23-2020

First you should check all external dependencies (Modules), if they available for Python 3 and still maintained.
If all dependencies still available for Python 3, you've luck. If there is a dependency, which has no candidate for Python 3, you must find a replacement.

Then comes str vs bytes
Improved Syntax for Exceptions
Absolute imports vs relative Imports

The tool 2to3 can help, but in the most cases you have to do the rest by hand.