How to change python version used by python-green

136 views Asked by At

I have both Python 2.7 and 3.3 installed in my box. How would I change python-green configuration to use one or the other without changing /usr/bin/python symbolic link?

3

There are 3 answers

0
Sharadh On BEST ANSWER

Try venv. This creates a virtual environment where all scripts use a particular python version by default.

pip install virtualenv
virutalenv -p <PATH_TO_PYTHON_3> <VENV_PATH>
source <VENV_PATH>/Scripts/activate

Once you activate venv,

install green
green <MODULE_TO_TEST>

To stop using this environment,

deactivate

Most packages, even the ones which support multiple Python versions, don't have run-time switches. So, you need to install green after you activate venv. Otherwise, the currently active (in your case, global) python version - lets assume 2.7 - calls its globally installed pip, which would install green for Python 2.7.

0
MinchinWeb On

green can now be run directly as a module. To do this, use /path/to/python -m green

0
Nathan Stocks On

Using venv as Sharadh suggests is absolutely the best way to go about this.

Having said that, it can be useful to know that green actually installs three application binaries:

green
greenX
greenX.Y

Where X is the major version of python (2 or 3) and Y is the minor version of python. So lets say you install green under the "system" installation of Python 3.3 and then 3.4. The following would occur:

green    <- Points to green in 3.3
green3   <- Points to green in 3.3
green3.3 <- Points to green in 3.3
green    <- Overwrites the previous green, now points to 3.4
green3   <- Overwrites the previous green3, now points to 3.4
green3.4 <- Points to green in 3.4

So, in summary:

  1. Use venv -- it's much more sane.
  2. If you must use multiple "system" python versions, use greenX.Y in all your commands, and you'll always get the correct one.