3

I'm working in a shared machine with no root privileges, but Python 2.y installed, but I would like to have both flavors of Python, also I would like to call Python 2.y just typing python (as usual) and for calling Python 3.x, type python3. I understand that this is possible because in my main equipment (whit root access, and the magic of sudo) I can "select" which one to use.

  • I don't know about automatically installing it but if building it from sources you could pass `--prefix` and `--exec-prefix` to `configure`, pointing to a folder where you have r/w/e perms, and then instead of `make install`, `make altinstall`. – CristiFati Nov 24 '17 at 05:00
  • One way is to use virtual environments. Now that python 2 is already there all you need is create a virtual Environment in python 2 and install python 3 inside that. Other way is to use like you said in the question call python 3 as "python3" and "python" or "python2" for python 2. – WaterRocket8236 Nov 24 '17 at 05:49

3 Answers3

8

You can install pyenv with the pyenv installer script and then run pyenv install 2.7.14 and pyenv install 3.6.3.

Some more documentation is here

Imran
  • 11,671
  • 8
  • 60
  • 75
  • 3
    If you are following the `Basic GitHub Checkout`, then on Step 4 restarting the shell with `exec "$SHELL"` may not work depending on how the machine you are connected to is setup. Simply disconnecting from the ssh session and connecting back makes it work, and then you can use `pyenv install`. For example, `pyenv install 3.6.6` installs python3.6.6, then you can do `pyenv global 3.6.6` and now calling `python` or `python3` will take you to python3.6.6. – Guilherme Salomé Oct 20 '18 at 12:57
-1

One can install Anaconda for python3 locally, but it seems to be a little bit overkill :)

andywiecko
  • 178
  • 2
  • 15
-3

Use virtualenv to handle your python dependencies. This way you can manually "select" which python version to use with your project.

Use different Python version with virtualenv

danieltan95
  • 714
  • 6
  • 11