How to downgrade python version

Downgrade Python from 3.11.2 to 3.10 in specifc environment

I am using Python’s virtual environment ‘venv’. My current version is 3.11.2 I need to downgrade it. I have already tried the following steps:

and got the following error: ERROR: Could not find a version that satisfies the requirement python==3.10.10 (from versions: none) ERROR: No matching distribution found for python==3.10.10 I also tried for lower versions like 3.8.0, 3.9.0, . Allways same error. Thanks

Download the Python version of your choice from the official website and install it…?! Or use some package manager which may or may not be available on your OS?!

Also, virtual environments are designed to be cheap and easy to replace. Rather than downgrading an existing virtual environment, discard it (or ignore it) and create a new one with the required version of Python.

2 Answers 2

To answer your question directly

Head straight to https://www.python.org/downloads/ to download the distribution you want.

If I am to guess what problem you are facing, here are some details

When you are running your command prompt, make sure you know which python you are executing. Example:

PS C:\Users\jli8\pythonWork\dpr-data-presenter> conda activate p310 (p310) PS C:\Users\jli8\pythonWork\dpr-data-presenter> .\venv\Scripts\activate (venv) (p310) PS C:\Users\jli8\pythonWork\dpr-data-presenter> where.exe python C:\Users\jli8\pythonWork\dpr-data-presenter\venv\Scripts\python.exe C:\Users\jli8\Anaconda3\envs\p310\python.exe C:\Users\jli8\AppData\Local\Programs\Python\Python311\python.exe C:\Users\jli8\AppData\Local\Microsoft\WindowsApps\python.exe (venv) (p310) PS C:\Users\jli8\pythonWork\dpr-data-presenter> 

From my terminal above, I actually have 3 pythons.

  • Python3.11 installed in AppData\Local\Programs\Python\Python311\python.exe
  • Python3.10 installed in Anaconda env «p310»
  • (which I used to create venv), finally the last venv in use with is in my working folder dpr-data-presenter\venv\Scripts\python.exe
Читайте также:  Создать приложение exe питон

From this limited context here, the most straightforward answer to you would be just download python3.10.10 from python.org. Make sure you understand how to execute from that python3.10.10 that you have installed and create your venv from that python3.10.10.

You need to have a software that can manage python executable. pip manages python packages. If it’s not clear, python is not a package.

pip is the package installer for Python. You can use it to install packages from the Python Package Index and other indexes.

I will present you some solutions for your needs:

  • pyenv: this a manager for python version. It’s lightweight and easy. This is the most straightforward way (opinion here)
  • nix: (proposed by Charles Duffy) this is a general development environment manager. This is widely used and is also lightweight. Also it’s quite easy to set. This is ideal if you want to manage other dependencies other than your Python version (external libraries, software)
  • conda: this is the most used Python environment manager. conda is heavy — it installs a bunch of things — and gave headache. Although, it would be the most documented manager — in terms for troubleshooting, I am not referring to its actual documentation. It works well on Windows. This is a good choice if you just want Python running and you are an absolute beginner in programming in general. Note: there are lightweight version of conda such as miniconda, mamba and so on.
  • docker (and other containers solution): this is an advanced option. Also, arguably it’s the best way to reproduce your development environment. It needs you to dive into a lot of details if you want to customize it. This is a good choice if you are kind of experimented at interacting with your Linux OS and you have third-party library dependencies that can be a pain (CUDA for GPU, for example) and your code should be moved to a node/cluster/server to perform costly computation.

This is not exhaustive also those approach can be cumulative: docker images can have conda or other manager installed on it, you can use a nix env with a pyenv/conda installed inside and so on. I would advise to take the fastest and the lightest solution for your solution. Then, if you need a more powerful (heavy) environment manager, you can move to something else.

Источник

Downgrade Python Version

Downgrade Python Version

  1. Downgrade Python Version on Windows
  2. Downgrade Python Version on Linux
  3. Downgrade Python Version on macOS

Python is maintained and updated regularly. Some new features are added on every update, and some old ones may get deprecated.

Some updates are major, while others might include minor changes. The code written in a specific Python version may or may not be compatible with other versions (the main example being the difference between Python 2 and Python 3).

This tutorial will demonstrate how to downgrade Python according to our needs on different devices. We will discuss methods for Windows, Linux, and Mac devices.

Downgrade Python Version on Windows

Reinstall to Downgrade Python on Windows

The first few methods involve uninstalling the current version of Python and installing the required version. There are several ways to achieve this.

The first method involves uninstalling the current Python version from the Control Panel. We can search for the Add or Remove Programs application in the Control Panel.

This application contains a list of all the programs installed on the device. We can select the installed version of Python from this list, right-click to select the uninstall option, and follow the steps.

Another way to uninstall the installed version of Python is by using the Python package installer used earlier to install Python. We get the repair and uninstall options on running the Python package installer.

We can click on the uninstall option and proceed with the required steps.

After using any of the previous methods, it is necessary to delete the Python files available in the directory of the same name (usually found in the C:\Program Files directory). It is also necessary to make sure that the path from the environment variable is removed.

After carrying out the uninstallation of Python, we can install the required version and download its package installer application from the official website of Python.

Use a Virtual Environment to Downgrade Python on Windows

Python allows us to create different virtual environments. Each virtual environment can have its required version of Python interpreter and packages.

To create a virtual environment, we can use the command pip install virtualenv on the command prompt. We need to download the required version from the official website.

After this, we need to execute virtualenv \pathof\the\env -p \pathof\the\python_install.exe . The former path is the path where we wish to store the environment, and the latter is the path where the installer is present.

Use Anaconda Prompt to Downgrade Python on Windows

This method is limited to the users of Anaconda Navigator. On the Anaconda prompt, we can install the required version of Python and overwrite the previous version using the conda install python= version command.

It is necessary to check if this version is available or not by running the conda search python command and checking for the available versions.

We can also create a new environment very easily in Anaconda. We can run the conda create —name env_name python=python_version command to create an environment.

Downgrade Python Version on Linux

Reinstall to Downgrade Python on Linux

We can remove and install the required version of Python to downgrade it. First, we need to download the package from the official website and install it.

Then, we need to go to the Frameworks\Python.framework\Versions directory and remove the version which is not needed. We will run the sudo rm -rf python_version command in this directory to remove this version.

Use Pyenv to Downgrade Python on Linux

Pyenv allows us to switch between different versions of Python by creating environments.

We can install the required version of Python using the pyenv install python_version command on the terminal. After that, we can view the available versions using the pyenv versions command.

To set the required version as the Python version for the local environment, we can use the pyenv local python_version command.

Next, we can switch to a different folder and set the required Python version globally. To set the version globally for a user, we use the pyenv global python_version command.

Use Homebrew to Downgrade Python on Linux

Homebrew is an application manager that can manage and install open-source applications. It is available on macOS and Linux.

We can clone to the repository of our required version of Python and unlink the previous version using a set of simple commands. These are shown below.

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

Use Anaconda to downgrade Python on Linux

Anaconda is also available on macOS and Linux devices. We can follow the steps discussed in the previous section of Downgrade Python on Windows and use them for these devices.

Downgrade Python Version on macOS

On macOS, we can use the methods involving Pyenv, Homebrew, and Anaconda discussed in the previous section. These methods are valid here as well.

Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.

Related Article — Python Version

Источник

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