I usually develop with python 2.7, but would like to start creating some tools in python 3.x. What is the easiest way to have both running side-by-side, while keeping some semblance of control over what libraries I have installed where...
If I use pyenv
to switch between versions, will it propagate to a generic shebang line? Something like
#!/usr/bin/env python
or even better, can I specify which python in the shebang?
#!/usr/bin/env python3
I am anticipating a lot of "Use virtualenv
" replies. Is this really the only way to do it? I feel like I would like to have the "base" python on my system with whatever libraries I have installed so that I can change between the two environments by typing something simple like pyenv global 3.2.3
I am using OSX, Mountain Lion at the moment.
Trying to explain it a little better, I have two alternative questions:
If I use something like virtualenv
, will I lose the ability to run python2 and python3 scripts alternately, without changing the environment (i.e., just via shebang)?
In contrast, if I use two independent version installations, how can I control/know what will be installed by pip
or easy_install
for example.
UPDATE: Currently using python3
in the shebang line, and using pip3
to install packages to python3... Seems to work fine.
You have a few possible methods varing slightly with os:
It may well pay you to look at six and working in python 3 than back converting to 2.7 for older installations.
See also here for both how to install python 3 libraries under python 3 with virtualevn and without, (modify version numbers as appropriate).
Additionally, on Windows, when you install Python 3 you have the option to install the python launchers, (py.exe & pyw.exe), to the Windows directory. The py launcher has the following behaviour:
Associating .py files with py.exe and .pyw files with pyw.exe will result in the shebang line being honoured.
Additionally using py -3.5-32 -m pip install some_package
will specifically install some_package
to the 32 bit python 3.5 installation, etc.
Disclaimer: I am the author of some upcoming enhancements to the python launcher to extend the above options slightly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With