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.
asked Nov 3, 2021 at 18:41
3
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
answered Nov 3, 2021 at 19:11
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]
Install python 3.7 and it’s virtual environment packages.
sudo apt-get install python3.7-dev python3.7-venv
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]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
python --version
[Should be python 3.7 now]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.
answered Aug 19 at 9:16
Created: June-07, 2021 | Updated: July-09, 2021 You can use three effective methods to downgrade the version of Python installed on your device: the The Suppose we are dealing with a project that requires a different version of Python to run. In
that case, we can use the virtualenv
Modulevirtualenv
method, the Control Panel
method, and the Anaconda
method. Here in our tutorial, we’ll provide you with the details and sample codes you need to downgrade your Python
version.Downgrade Python 3.9 to 3.8 With the
virtualenv
Modulevirtualenv
method is used to create and manage different virtual environments for Python on a device; this helps resolve dependency issues, version issues, and permission issues among various projects.virtualenv
module to create a new virtual environment for that specific project and install the required version of Python inside that virtual environment. To create a virtual environment, we first have to install the vritualenv
module. Here’s the command to install this module:
pip install virtualenv
Now, we can create our virtual environment using the virtualenv
module. The command to create a new virtual environment is given
below.
virtualenv \path\to\env -p \path\to\python_install.exe
Here, \path\to\env
is the path of the virtual environment, and \path\to\python_install.exe
is the path where the required version of Python is already installed. For this command to work, we have to install the required version of Python on our device first.
Upon installation, you just have to activate our virtual environment. You can do so by executing the command below:
\path\to\env\Scripts\activate.bat
Here, \path\to\env
is the path of the virtual
environment.
Downgrade Python 3.9 to 3.8 With Anaconda
We can also use Anaconda, just like virtualenv
, to downgrade a Python version. First, you need to install Anaconda on your device. After the installation, we can create a new virtual environment for our project using the conda
package manager. The command to create a virtual environment with conda
is given below:
conda create -n downgrade python=3.8 anaconda
This command creates a new virtual environment
called downgrade
for our project with Python 3.8. The next step is activating our virtual environment. The command to start a virtual environment using conda
is given below.
activate downgrade
The command above activates the downgrade
virtual environment. Now, we can install all the packages required for our special project.
This approach is very similar to the virtualenv
method. However, the conda
method is simpler and easier to use than the previous approach. We don’t even need to install
another Python version manually; the conda
package manager automatically installs it for us.
Downgrade Python 3.9 to 3.8 With the Control Panel
This method only works for devices running the Windows Operating System. This approach involves manually uninstalling the previously existing Python version and then reinstalling the required version.
We can uninstall Python by doing these steps: Go to Control Panel -> Uninstall a program -> Search for Python -> Right Click on the Result -> Select Uninstall
.
Now that the previous version of Python is uninstalled from your device, you can install your desired software version by going to the official Python download page.
This approach is the least preferred one among the ones discussed in this tutorial. It’s because this approach only works for Windows and should only be used when we don’t need the previous version of Python anymore.
The best approach for downgrading Python or using a different Python version, aside from the one already installed on your device, is using Anaconda. The commands for using Anaconda are very simple, and it automates most of the processes for us.