Run Python3.4 and Python3.7 simultaneously on Linux

Posted on

Problem :

I have a linux VM with preconfigured Python3.4. I need to have Python3.7 to run my code.

I tried to uninstall Python3.4 but there are some system dependencies, so I kept old version.
Then I downloaded and installed Python3.7.1.tgz (sudo make).

But now I can’t access Python 3.7 instance. When I run a “python3” command, Python 3.4 is run, when “python3.7” then I get a “command not found” message.

How do I proceed? Is it okay to have two versions of Python 3 installed on one machine? What with installation packages by “pip”?

Solution :

I would not recommend manually fiddling around with source code installations and paths. Use pyenv and save yourself the trouble.

All you have to do is:

  • Run the pyenv installer
  • Follow the instructions
  • Install the Python versions you need
  • Choose which Python version you want to use for a given directory, or globally

For example, to install 3.7, check which versions are available:

pyenv install -l | grep 3.7

Then run:

pyenv install 3.7.1

Now, you can choose your Python version:

pyenv global 3.7.1

This switches your python to point to 3.7.1. If you want the system python, run:

pyenv global system

To check which Python versions are available, run pyenv versions.

Leave a Reply

Your email address will not be published. Required fields are marked *