How to downgrade python on linux

How to downgrade python from 3.7 to 3.6

I’m trying to install tensorflow but it needs a Python 3.6 installation and I only have Python 3.7 installed. I tried to switch using brew and pyenv but it doesn’t work. Does anyone know of a way to solve this problem?

I recommend you to use Anaconda. Then create new environment for every new project and activate it before using. In your case, conda create -n myenv python=3.6 and source activate myenv

Upgrade tensorflow. Tensorflow 1.14 and 1.15 support Python 3.7 (and earlier) and tensorflow 2.2 supports Python 3.8

15 Answers 15

Here is a canonical summary which sums up different solutions for the variety of operating system Python runs on. What follows are possibilities for Microsoft Windows, Linux, macOS and Misc.

As mentioned those are just possibilities — by no means do I claim to have a complete list whatsoever.

Microsoft Windows

Option 1

In general, it’s suggested to use virtual environments (I highly suggest looking at the official Python documentation). With this approach, you easily can set up project-specific Python versions (as well as libraries). Easily manageable and the best part: There are lots of tutorials on the internet on how to approach this:

1.) Open command prompt («cmd») and enter pip install virtualenv .

2.) Install your desired Python version via https://www.python.org/downloads ; Remember: Do not add to PATH !

3.) Type into the command prompt: virtualenv \path\to\env -p \path\to\python_install.exe , whereas \path\to\env shall be the path where your virtual environment is going to be and \path\to\python_install.exe the one where your freshly (presumably) installed Python version resides.

4.) Done! You now have a virtual environment set up! Now, to activate the virtual environment execute the batch file which is located inside the \path\to\env\Scripts\activate.bat . (cf. this website or an official Python guide)

Option 2

The basic option would be to uninstall the unwanted Python version and re-install the favored one from https://www.python.org/downloads/. To remove the «old» version go to Control Panel -> «Uninstall a program» -> Search for «Python» -> Right-click on the Python name -> Uninstall . Bear in mind that Python usually has a PATH variable stored, hence you should remove it as well — Check the following links for this:

Now double-check whether there are any remaining files where Python used to be stored. Usually, you can find all the Python files at either C:\Program Files (x86)\Pythonxx , C:\Users\username\AppData\Local\Programs\Pythonxx or C:\Pythonxx or all of them. You might have installed it in another directory — check where it once was.

Now after de-installing just re-install the wanted version by going to the download page and follow the usual installation process. I won’t go into details on how to install Python.. Lastly, you might check which version is currently installed by opening the command prompt and typing python -V .

Читайте также:  Linux date utc change

Option 3

This approach is pretty similar to the second one — you basically uninstall the old one and replace it by your favored version. The only thing that changes it the part regarding how to uninstall the unwanted Python distribution: Simply execute the Python3 installer you originally used to install Python (it’s usually stored in your Python directory as mentioned above; for more assistance check out this). There you get an option to repair or uninstall , proceed by choosing uninstall , and follow the steps provided via the uninstaller.

No matter how you uninstall Python (there are many resources on this topic, for example this Stack Overflow question or a problem thread a user by the name of Vincent Tang posted on the Stack Exchange site Super User, etc.), just reinstall the wanted Python version by following the steps mentioned in Option 2 .

Option 4

Option 4 deals with Anaconda. Please refer to this site on how to install Anaconda on Windows. Step 9 is important as you don’t want to install it as your default Python — you want to run multiple versions of Python:

Choose whether to register Anaconda as your default Python. Unless you plan on installing and running multiple versions of Anaconda or multiple versions of Python, accept the default and leave this box checked.

Follow the official tutorial I linked above.

Once done you can create the following commands individually in the anaconda prompt: To overwrite the default python version system-wise use conda install python=3.6 or to create a virtual environment go ahead and use conda create -n $PYTHON36_ENV_NAME python=3.6 anaconda whereas $PYTHON36_ENV_NAME is the custom name you can set. Credit where credit is due — the user @CermakM from this thread strongly influenced this snippet.

In my research I encountered a bunch of useful Stack Overflow threads — you might check them out if you go the tough road with Anaconda:

Option 5

What follows isn’t a downgrade in the classical sense — though for the sake of completeness I decided to mention this approach as well. On Windows you’re also able to run multiple Python versions — an infamous thread on StackOverflow deals with this question, thus I politely refer you to there for further reading purposes.

Linux

Option 1

Pretty analog to the third option for Windows I highly suggest you use a virtual environment such as Anaconda. Anaconda — or short conda — is also available on Linux. Check the official installation documentation here. Once again this thread is highly suggested on how to overwrite a Python version, respectively how to specifically create an environment with your wanted Python version.

Option 2

Another highly suggested virtual environment is Pyenv . The user @Sawan Vaidya described in this Stack Overflow question on how to up-or downgrade a Python version with the help of Pyenv . You can either set a Python version globally or create a local environment — both explained in the mentioned thread.

Option 3

Another user, namely @Jeereddy, has suggested to use the software package management system Homebrew . He explained this option thoroughly in this current question:

$ brew unlink python $ brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/e128fa1bce3377de32cbf11bd8e46f7334dfd7a6/Formula/python.rb $ brew switch python 3.6.5 

Option 5

No need to reinvent the wheel — this thread is filled with lots of beautiful running approaches such as the one by @Sidharth Taneja.

  1. Download your wanted Python version from https://www.python.org/downloads/release and install it as a normal package .
  2. Run cd /Library/Frameworks/Python.framework/Version
  3. Execute ls to list all installed Python versions
  4. Run sudo rm -rf 3.7 , removing Python version 3.7 — can be repeated for whatever version(s) you want to delete
  5. Check python3 -v , it should display the version you originally wanted to have installed

Option 6

What a goldmine this thread is! As @nondetermistic has described in-depth (direct link to his post):

Читайте также:  Как определить дистрибутив линукс

Install Python source code as it is like this:

#Taken Python 3.6 as an example $ mkdir /home//python3.6 $ ./configure --prefix=/home//python3.6/ $ make altinstall 

You’re now able to either add the downloaded version ( /home//python3.6/bin ) to PATH as well as lib to LD_LIBRARY_PATH or just create a virtual environment by: /home//python3.6/bin/python3.6 -m venv env-python3.6 . A very aesthetic and simple solution to run multiple Python versions on your system.

macOS

Option 1

Using pyenv with Homebrew — credit to @Shayan with his reply here:

1.) Installing pyenv with Homebrew :

brew update brew install pyenv 

2.) Cloning the GitHub repository to get latest pyenv version:

 git clone https://github.com/pyenv/pyenv.git ~/.pyenv 

3.) Defining the environment variables as follows

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile 

4.) Restarting shell so PATH change works

5.) Checking the available Python versions

6.) Installing the wanted Python version, e.g. 3.6

7.) Setting it globally (you can also go ahead and only use it in a certain environment)

8.) Check the Python version the system is using — your wanted / downgraded version should be displayed here.

Option 2

Similar to previous approaches you can download Anaconda on macOS as well. For an installation guide click here. The usage is pretty much the same as I’ve already described in Option 4 of the Windows guide. Please check out above.

Other options

In this case it’s getting pretty repetitive. I kindly suggest you to check the following resources for further reading:

Misc

When writing this post I had the problem of not knowing where to draw the line. When looking up the operating systems Python currently supports you get a huge list, including the ones I mentioned, i.e. Linux, Microsoft Windows and macOS, though obviously different Linux distributions are single-handedly treated, e.g. CentOS, Arch Linux or Fedora should deserve a spot as well — or shall I make separate options for Windows 10, 7, etc.?

Due to the high degree of repetitiveness as far as modules like Homebrew, Conda or alike are concerned I decided to limit my list to the «main three» operating systems — distributions like Ubuntu (How do I downgrade my version of python from 3.7.5 to 3.6.5 on ubuntu), CentOS (How to downgrade python version on CentOS?) can be easily researched on Stack Overflow. Most often than not you can apply solutions from the Linux tab for said distributions. The same goes with Windows and macOS (versions).

Читайте также:  Change user on linux command

Источник

How to downgrade python version in Ubuntu 20.04?

I need to change my python version from 3.8 to 3.6 ? How can I achieve this in Ubuntu 20.04. I tried pyenv, but when I try to use pyenv like pyenv global 3.6.0 then I do python3 and I have still 3.8 verision.

Do you really need to change the python version or do you just need to be able to run certain scripts with a different version?

Please edit your question and clarify that because changing the global python is a very bad idea and really not a good solution if you only need this for certain scripts. Are you just looking for /usr/bin/python3.6 /path/to/script.py ?

2 Answers 2

Do not downgrade the system version: it’s likely that some parts of the system would stop working. Never change /usr/bin/python3 , and avoid putting an older version of python3 before it in the $PATH .

The deadsnakes archive provides packages of most supported Python versions for currently supported Ubuntu LTS versions. To make these packages available, follow the usual instructions to enable a PPA. Then install the package(s) you want.

sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get update sudo apt-get install python3.6 

You can then create a virtual environment for your chosen Python version and with a chosen set of packages.

python3.6 -m venv ~/python/foo-3.6 sh -c '.export PYTHONNOUSERSITE=1; ~/python/foo-3.6/bin/activate; pip install …' 

To run a program in this environment, source the bin/activate script in a shell.

$ bash $ export PYTHONNOUSERSITE=1 $ . ~/python/foo-3.6/bin/activate $ ./my_python_program 

When setting up the venv, it reports and error with ensurepip something non-zero exit status. The package python3.9 installed from deadsnakes doesn’t include pip. How do I solve that?

Alternatively, you can create a virtual environment.

Suppose you have python 3.8 (or higher) installed on the system, but for a specific task, you need python 3.7 (or lower). The best idea is (not to downgrade) to Create a virtual environment with python 3.7(or any 3.x, change the commands below according to your desired version. Below is an implementation of a virtual environment with python 3.7)

Steps: (Checked August 2022)

  1. Install python 3.7 and it’s virtual environment packages. sudo apt-get install python3.7-dev python3.7-venv

NB: If you’ll get errors like: E: Couldn’t find any package by glob ‘python3.7’ , stating that the packages can not be installed.

run the following commands below, then re-run the install command above:

sudo apt install software-properties-common

sudo add-apt-repository ppa:deadsnakes/ppa

  1. Find out where your python 3.7 is located by this command: which python3.7 (Should be something like /usr/bin/python3.7, if not found, then install python 3.7 manually)
  2. Create Virtual Environment in the Home directory. cd mkdir virtual_env /usr/bin/python3.7 -m venv ~/virtual_env/venv_with_python3.7 source ~/virtual_env/venv_with_python3.7/bin/activate
  3. python —version (Should be python 3.7 now)
  4. Done. Python 3.7 can be used in this virtual environment. Type which python , you’ll see you have created python 3.7 in a virtual environment, rather than in the system globally. Run deactivate when you need to deactivate.

Источник

Оцените статью
Adblock
detector