Page 1 of 1

imports 2 to 3

Posted: Thu Apr 27, 2017 10:15 pm
by klintkrossa
Hello,

Is there a way that python3.X.X able to import any python import either a python2 or python3 import?

For you guru's can it be made?

Re: imports 2 to 3

Posted: Fri Apr 28, 2017 8:43 am
by scotty101
Python modules that are written for Python2 won't work with Python3 unless you rewrite them (or someone else has rewritten it). There is no magic command.

Re: imports 2 to 3

Posted: Fri Apr 28, 2017 4:03 pm
by klintkrossa
scotty101 wrote:Python modules that are written for Python2 won't work with Python3 unless you rewrite them (or someone else has rewritten it). There is no magic command.
I though so. Now there would be a python script.

Re: imports 2 to 3

Posted: Fri Apr 28, 2017 6:32 pm
by kusti8
klintkrossa wrote:
scotty101 wrote:Python modules that are written for Python2 won't work with Python3 unless you rewrite them (or someone else has rewritten it). There is no magic command.
I though so. Now there would be a python script.
There is a script called 2to3 that can convert, but many simple scripts already have it done and complex ones are complicated to do.

Re: imports 2 to 3

Posted: Fri Apr 28, 2017 10:56 pm
by paddyg
in pi3d we used the six module functions so the code gets converted 'on the fly' which means the same code runs with py2 or py3 (and pypy) However there is a small processing cost for doing this.

You *could* patch the 'wrong' path to dist packages using sys.path.insert(1,...) but some modules will almost certainly not work and it would end in a horrible mess.