How to downgrade python version from 3.11, 3.10, 3.9, 3.8 to 3.x in Ubuntu. Install Django Virtual Environment.

after moving on to Python's latest version arise some problems that may be package dependency error or problems. so read how to downgrade the version
How to downgrade python version from 3.11, 3.10, 3.9, 3.8 to 3.x in Ubuntu. Install Django Virtual Environment. pdfcup.com


When should we Downgrade the version of Python:

Note: The latest version of "Ubuntu 22.04, Ubuntu 20.04, Ubuntu 18.04" comes with the latest version of "Python 3.10, Python 3.9 and Python 3.8". If we are already working on projects that support older Python versions and packages, moving to the latest version of Python may cause some problems, such as package dependency errors or other issues. Basically, Python3.6 is the default version in Ubuntu 18.04, Python 3.8 is the default version in Linux Ubuntu 20.04, and Python 3.10 is the default version in Linux Ubuntu 22.04.

We can change any version of Python by following the steps outlined below. In this tutorial, we will switch from Python3.8 to Python3.6. Remember that all steps work the same way if you want to downgrade or upgrade "ANY" Python version.

Also Read: How to set up Github to clone the Python Django project Repo.

1. Downgrade Python in Linux Ubuntu OS:

(Part A): Change Universal Python Version Manually.

Step 1: Download the required Python version:

tom@hp~$  cd /usr/src
tom@hp:/usr/src$ wget https://www.python.org/ftp/python/3.6.15/Python-3.6.15.tgz  
  

Note:
Replace whatever Python version that you want to install and make sure the version must be accurate otherwise it will arise an error. Check the Python version release from the official python release for more accuracy.
Ex: Replace /3.6.15/ with /3.8.15/ or /3.7.15/ or /3.x.xx/,
and
Python-3.6.15.tgz with Python-3.8.15.tgz or Python-3.7.15.tgz or Python-3.x.xx.tgz
Example: $ wget https://www.python.org/ftp/python/3.7.15/Python-3.7.15.tgz

Step 2: Extract the Downloaded .tar file. If you have downloaded another version so just replace the version:

tom@hp:/usr/src$ sudo tar xzf Python-3.6.15.tgz 
  

Step 3: Now, Check downloaded Python 3.6.15 located inside the path "/usr/src"

tom@hp~$  cd /usr/src
tom@hp:/usr/src $ ls
Python-3.6.15.tgz        Python-3.6.15
  

Step 4: Install Required Packages (Copy all at once and paste in terminal):

tom@hp~$  sudo apt-get install build-essential checkinstall \
libreadline-gplv2-dev libncursesw5-dev libssl-dev \
libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev 
  

Step 5: Install Python on System:

tom@hp~$  cd /usr/src
tom@hp:/usr/src $ ls
Python-3.6.15.tgz        Python-3.6.15
tom@hp:/usr/src $ cd Python-3.6.15/
tom@hp:/usr/src/Python-3.6.15$  
  

Step 6: Step 6: Run Configure Script:

tom@hp:/usr/src/Python-3.6.15$ 
tom@hp:/usr/src/Python-3.6.15$ sudo ./configure
  

Step 7: Run Package Bilder:

tom@hp:/usr/src/Python-3.6.15$ sudo make altinstall 
  

Step 8: Now, Check installed Python3.6 located inside the path "usr/local/bin" repository:

tom@hp:/usr/src/Python-3.6.15$ cd /usr/local/bin/
tom@hp:/usr/local/bin $ ls
2to3-3.6          idle3.6  pydoc3.6   python3.6m         pyvenv-3.6
easy_install-3.6  pip3.6   python3.6  python3.6m-config

tom@hp:/usr/local/bin$  python3.6
Python 3.6.15 (default, Dec  7 2021, 13:04:41) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>  5+5
10
>>>
  

(Part B): Setup New install Python3.6.15 as the default version.

NoteGreate Work!, Now suppose that earlier you had installed python3.8 in your system, so it will again open python3.8 version by default in the new terminal, not the recently downloaded version. To open Python3.6.15 recently changed version as default, we have to point the python file in "/usr/local/bin" directory which is currently located inside this path "usr/bin/" directory.
Let's Do it.

Step 1: Go to /usr/bin/ Directory:

tom@hp~$  cd /usr/bin/
  

Step 2: Check which compiler version pointing by the < Python > interpreter:

tom@hp:/usr/bin/$ ls -lrth python*
lrwxrwxrwx 1 root python2 -> python2.7
lrwxrwxrwx 1 root python-config -> python2-config
lrwxrwxrwx 1 python2.7-config -> x86_64-linux-gnu-python2.7-config
-rwxr-xr-x 1 root root  python2.7
lrwxrwxrwx 1 python3.8-config -> x86_64-linux-gnu-python3.8-config
-rwxr-xr-x 1 root root  python3.8

lrwxrwxrwx 1 root python3 -> python3.8
lrwxrwxrwx 1 root root  python -> /usr/bin/python3.8
tom@hp:/usr/bin/$ 
tom@hp:/usr/bin/$ 
  

Step 3: Unlink Python that is pointing to the Python3.8 version:

tom@hp: /usr/bin/$    sudo unlink python
tom@hp:/usr/bin/$ 
tom@hp:/usr/bin/$  ls -lrth python*
lrwxrwxrwx 1 root python2 -> python2.7
lrwxrwxrwx 1 root python-config -> python2-config
lrwxrwxrwx 1 python2.7-config ->  x86_64-linux-gnu-python2.7-config
-rwxr-xr-x 1 root root  python2.7
lrwxrwxrwx 1 python3.8-config -> x86_64-linux-gnu-python3.8-config
-rwxr-xr-x 1 root root  python3.8
tom@hp:/usr/bin/$ 
tom@hp:/usr/bin/$ 
  

Step 4:Now create a new python interpreter file that will Link to the recently downloaded python Compiler:

tom@hp:/usr/bin/$ cd /usr/local/bin
tom@hp:/usr/local/bin/$  sudo ln -s /usr/local/bin/python3.6 python
  

Step 5: Now python will open Python3.6 as the default downloaded version. Open a new terminal and just type python:

tom@hp:~$   python
Python 3.6.15 (default, Dec  7 2021, 13:04:41) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>  15+5
20
>>>
  

NoteIf you need to use an earlier Python version, repeat the process in reverse order. In other words, you must first unlink the python file that is now pointing to the Python3.6 version in this article. After unlinking the python file from the " usr/local/bin " directory, create a new python file that points to the previous python3.8 version. Refer to Steps 3–5 in detail.
Learn how to set up Github to clone the Django project Repo.

Dear, if you encounter any difficulties in the preceding steps, Kindly leave a comment and our team will assist you as soon as possible.

FAQ:

How to Downgrade Python version Using Conda Command in Anaconda.

How to Downgrade Python version Using Conda Command in Anaconda.

 conda install python=3.5.0

How to Downgrade Python version in
Windows 10,8, and 7.
How to Create Virtual Environment For Python Project.

How to Create Virtual Environment For Python Project.

Step1. Download Virtual Environment using the python package manager.

Option 1
$ sudo apt install python3-venv
Option 2
$ pip --version

$ pip install virtualenv   # use this command if pip points already Python3
           or
$ pip3 install virtualenv  # use this if pip points Python2


Step2. Create Virtual Environment.

$ python -m venv my_env
       or
$ python3 -m venv my_env


Step3. Activate Virtual Environment

tom@hp~$ source Env_Name/bin/activate # Note: In my case, I have install Python on my Home directory. But if you have created virtual environnment in other director, so you have to go in that path where your virtual environment created.

How to install Django in a virtual environment in Ubuntu 18.04/ Ubuntu 20.04.

How to install Django in a virtual environment in Ubuntu 18.04/ Ubuntu 20.04.

Step 1. Install pip,  pip is a Python Package manager. 

# install pip3, if it is not pre installed.
sudo apt-get -y install python3-pip

Step2. Install Django.

pip3 install django   # For Download Latest version of Django.
     or
pip3 install Django==version   # Ex: Django==2.2.24  /for Download specific Version
     or
python - m pip install Django
    or
pip install django



How to install Django Using Conda command in Anaconda.

How to install Django Using Conda command in Anaconda.

(env) tom@hp~$ conda install -c anaconda django
# Installing specific versions of conda packages by using
(env) tom@hp~$ conda install package-name=2.3.4


Optional

update - alternatives--install / usr / bin / python python / usr / bin / python3 1

Once all installation is completed, make the 'pip3' command as the default 'pip' version.

update - alternatives--install / usr / bin / pip pip / usr / bin / pip3 1

About the author

D Shwari
I'm a professor at National University's Department of Computer Science. My main streams are data science and data analysis. Project management for many computer science-related sectors. Next working project on Al with deep Learning.....

6 comments

  1. Patreck Gilbert
    Patreck Gilbert
    Hi, I'm facing some issues. After python was successfully Downgraded, python showing at ("usr/local/bin" ) repository. But I wanna point my Python to ( "usr/bin" ) repository but I have faced some problems while pointing my default Python to ( "usr/bin" ) repository. and When I'm tried to do it then it runs again previous install Python higher version, so how could I solve this problem.
    1. D Shwari
      D Shwari
      Hello Patrick, if you have successfully downgrade your Python version then it will absolutely configured all configuration by default at "usr/local/bin" directory. but yes, you have an option to change this.
      follow this steps:
      1. Copy all the downloaded file at "usr/bin" directory, and examine carefully not the same name file are already exist at "usr/bin".
      2. After Copied all the file at from "usr/local/bin" to "usr/bin" then run this command,
      "tom@hp:/usr/bin/$ sudo ln -s /usr/local/bin/python3.6 python".
      3. Now check your python it will point your "usr/bin" directory.
  2. Ali Khatoon
    How do I completely replace Python2.7 with Python 3.8 on Ubuntu 21.04. Is there any solution for this?
    1. D Shwari
      D Shwari
      Hi Ali, The answer is "NO".
      Because Linux's Ubuntu Comes by default with Python3.x and Python2.x. Many of Linux's OS software and application are depending on both Python2 and Python3 so if you remove the python2 dependency from your system it may arise abnormal errors and might be possible your system will crash. So the right solution is if your Python version is default set on " < =2.7 " then change the default version with 3.x that is mentioned above in this article.
      Hope it will helpful.
  3. Teresa Hamilton
    Hello,  I'm trying to downgrade the Python 3.11 version on Mac OS. I had followed all the steps that were described above, but I got stuck when I tried to export the files to a location called "/usr/local" that wasn't on my system. Will it still work if I import it into the main "/usr/bin" directory, or will that cause some issues?
    1. Jorge Stephen
      Good day, Teresa. The installation can be run in any directory that does not have root level restrictions enabled. There are some predefined directories where the root user can perform installation and removal operations. As a result, you can select any directory except the root level restricted directory. Hope it will helpful.