How do I downgrade my version of python from 3.7.5 to 3.6.5 on ubuntu
The following talks about upgrade from 3.6.7 to 3.7.0 but you can use the same process for downgrade. You should not change the system python unless you really know what you're doing
First Install Pyenv
Installlation Instructions are here
Look at Pyenv Options
$ pyenv
pyenv 1.2.14
Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
commands List all available pyenv commands
activate Activate virtual environment
commands List all available pyenv commands
deactivate Deactivate virtual environment
doctor Verify pyenv installation and deevlopment tools to build pythons.
exec Run an executable with the selected Python version
global Set or show the global Python version
help Display help for a command
hooks List hook scripts for a given pyenv command
init Configure the shell environment for pyenv
install Install a Python version using python-build
local Set or show the local application-specific Python version
prefix Display prefix for a Python version
rehash Rehash pyenv shims (run this after installing executables)
root Display the root directory where versions and shims are kept
shell Set or show the shell-specific Python version
shims List existing pyenv shims
uninstall Uninstall a specific Python version
--version Display the version of pyenv
version Show the current Python version and its origin
version-file Detect the file that sets the current pyenv version
version-name Show the current Python version
version-origin Explain how the current Python version is set
versions List all Python versions available to pyenv
virtualenv Create a Python virtualenv using the pyenv-virtualenv plugin
virtualenv-delete Uninstall a specific Python virtualenv
virtualenv-init Configure the shell environment for pyenv-virtualenv
virtualenv-prefix Display real_prefix for a Python virtualenv version
virtualenvs List all Python virtualenvs found in `$PYENV_ROOT/versions/*'.
whence List all Python versions that contain the given executable
which Display the full path to an executable
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme
Look at Python Versions
$ pyenv versions
system
* 3.6.7 (set by /home/taarimalta/.pyenv/version)
Install a new Python
$ pyenv install 3.7.0
Installing Python-3.7.0...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
If you run into an issue with _ctypes install libffi-dev library
Now look at the versions
$ pyenv versions
system
* 3.6.7 (set by /home/taarimalta/.pyenv/version)
3.7.0
Select 3.7.0 for local environment
$ pyenv local 3.7.0
See that the version changed
$ pyenv versions
system
3.6.7
* 3.7.0 (set by /home/taarimalta/.python-version)
$ python
Python 3.7.0 (default, Jan 1 2020, 10:52:57)
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Switch to a different folder
cd ../project2
pyenv versions
system
* 3.6.7 (set by /home/taarimalta/.pyenv/version)
3.7.0
The python version may be different here depending on which python version you have set locally
Set pyenv version globally
This globally sets a python version for a user
pyenv global 3.7.0
Note that pyenv sets local version by adding a .python-version file
$ pyenv local 3.7.0
$ cat .python-version
3.7.0
Note that pyenv knows the global version by looking at the ~/.pyenv/version
file
cat ~/.pyenv/version
3.8.2
conda install downgrade python version
If you want to set specific version, use it like this:
WARNING: This command will overwrite the default python version system-wise
conda install python=3.6
To create environment with a specific version, you can do:
conda create -n $PYTHON36_ENV_NAME python=3.6 anaconda # set custom env name
The
anaconda
at the end allows the env to use all anaconda packages
For more information refere to Anaconda documentation
Change python version to 3.x
Interestingly, poetry is silently failing due to a missing package the tool itself relies on and continues to install a broken venv. Here's how you fix it.
sudo apt install python3-venv
poetry env remove python3
poetry install
I had to remove pytest, and then reinstall with poetry add pytest
.
EDIT: I ran into this issue again when upgrading a project from python3.7 to python3.8 - for this instead of installing python3-venv
, you'd want to install python3.8-venv
instead
Unable to set default python version to python3 in ubuntu
EDIT:
I wrote this when I was young and naive, update-alternatives
is the better way to do this. See @Pardhu's answer.
Outdated answer:
Open your .bashrc file
nano ~/.bashrc
. Typealias python=python3
on to a new line at the top of the file then save the file with ctrl+o
and close the file with ctrl+x. Then, back at your command line typesource ~/.bashrc
. Now your alias should be permanent.
How to downgrade python version without affecting other files
pip uninstall python 3.8.4
This command will never work. pip
is a python package manager, i.e. for an installation of python, pip is responsible to install modules to that python installation. It does not manage the installation of python itself
To your error with the tensorflow installation:
pip install tensorflow
and
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'c:\\programdata\\anaconda3\\lib\\site-packages\\wrapt-1.11.2.dist-info\\INSTALLER'
This is caused by the fact that the c:\\programdata
is write protected from non-admin users, so in order for your command to succeed, you should run your cmd as admin.
BUT:
It seems like you have installed anaconda and are trying to install tensorflow
into the base environment using pip
. Pip in turn tries to uninstall some already existing package, probably to fulfill the tensorflow requirements. But the already existing package are probably installed by conda
when you first installed anaconda, so you ware getting into dangerous waters here and you are risking to break your base environment, so two suggestions:
- Create a new environment
conda create -n tf tensorflow-gpu
- Use conda commands to install tensorflow.
conda install tensorflow-gpu
will give you tensorflow
To your other question:
How to downgrade python
The solution is also to use a conda command:
conda install python=<some version>
or, even better, simply create an environment with the version you need:
conda create -n py37 python=3.7
would for example give you an environment called py37 with python3.7 installed. It can be activated and used with
conda activate py37
Related Topics
Dropping Root Permissions in Python
Python Multiprocessing Memory Usage
How to Send a Signal from a Python Program
Decrypt Chrome Linux Blob Encrypted Cookies in Python
Gae " No Attribute 'Httpshandler' " Dev_Appserver.Py
Python Script Prints Output of Os.System Before Print
Subprocess.Popen(): Oserror: [Errno 8] Exec Format Error in Python
How to Retrieve the Process Start Time (Or Uptime) in Python
Setting Ld_Library_Path from Inside Python
Find the Oldest File (Recursively) in a Directory
Better Way to Script Usb Device Mount in Linux
Mismatch Between Sys.Executable and Sys.Version in Python
How to Set File Permissions in Python3
List All Currently Open File Handles