Installing new version of python on Debian Linux server
I think you'd better to install with compiling python 2.7.8 in your home directory. That's definitely clear for the others. 'update-alternatives' command makes system default python version change.
In my case, I made hidden directory '.opt' on my account. Then downloaded and extracted source code from python.org (https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz) with below command.
$ cd $HOME
$ mkdir -p .opt
$ wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
$ tar zxvf Python-2.7.8.tgz
It'll make Python-2.7.8 directory on your account home. So change directory Python-2.7.8.
$ cd Python-2.7.8
Please configure with 'prefix' option. In my case '--prefix=$HOME/.opt'.
$ ./configure --prefix=$HOME/.opt
It'll be configured with setting at your home directory. After than you can 'make' and 'make install'.
$ make && make install
If there are no errors, you can find directories for python binaries in .opt directory. $HOME/.opt/bin/python is new one. Please set path environment variable in your profile in .bashrc or .profile.
$ echo "export PATH=$HOME/.opt/bin:$PATH" >> $HOME/.bashrc
It'll be works only for your account.
How can I upgrade python on a Debian server?
You could also compile the latest source and install Python to an alternative path from the default (so that applications don't get messed up). Basically you would download the latest Python, configure it, compile, then install.
$> wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
$> tar xvhf Python-2.7.11.tgz
$> cd Python-2.7.11
$> ./configure
$> make
$> sudo make altinstall
Update
To see all the available options for Python configuration execute ./config --help
. This is important to know because, by default, many options are left out (especially in Python 2.x) such as unicode or IPv6 support. Features can also be disabled if required.
Reference
- Installing new version of python on Debian Linux server
- Building Python from source on Debian or Ubuntu
How to install python 3.4.3 from source and pip on Debian
Add the line in which you export the PATH
variable to the .profile and it will work after logging back in.
You can do this by executing
echo 'export PATH="$PATH:/opt/python3.4.3/bin"' >> ~/.profile
Instead of changing the PATH
variable, you could simply install python into the system directories (where it is better placed), by going to the root of the source directory and running
./configure
make
sudo make install
If pip is distributed within the python source, then it will be installed, too. Check if pip has been installed by executing
pip --version
If it is not, you have to manually install pip, too.
https://pip.pypa.io/en/latest/installing.html explains how this is done.
Simply download the script get-pip.py
and run it like this
sudo python get-pip.py
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
Multiple Python versions on the same machine?
I think it is totally independent. Just install them, then you have the commands e.g. /usr/bin/python2.5
and /usr/bin/python2.6
. Link /usr/bin/python
to the one you want to use as default.
All the libraries are in separate folders (named after the version) anyway.
If you want to compile the versions manually, this is from the readme file of the Python source code:
Installing multiple versions
On Unix and Mac systems if you intend to install multiple versions of Python
using the same installation prefix (--prefix argument to the configure
script) you must take care that your primary python executable is not
overwritten by the installation of a different version. All files and
directories installed using "make altinstall" contain the major and minor
version and can thus live side-by-side. "make install" also creates
${prefix}/bin/python3 which refers to ${prefix}/bin/pythonX.Y. If you intend
to install multiple versions using the same prefix you must decide which
version (if any) is your "primary" version. Install that version using
"make install". Install all other versions using "make altinstall".For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being
the primary version, you would execute "make install" in your 2.6 build
directory and "make altinstall" in the others.
How do I update a Python package?
You might want to look into a Python package manager like pip. If you don't want to use a Python package manager, you should be able to download M2Crypto and build/compile/install over the old installation.
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.
Related Topics
Mpc/Mpd on Linux: How to Play Local Wav File
Pte Structure in The Linux Kernel
How to Use Sysfs Inside Kernel Module
How to Execute a Command in a Bash Script and Then Focus The Appearing Window
Starting Multiple Firefox Profiles with Batch File in Linux
How to Set Errno in Linux Device Driver
Cmake: Don't Set Rpath for a Single Library Used in Link
Tmux .Tmux.Conf Doesn't Load Properly
Do I Have to Pthread_Join Each Thread I Create
How to Remove File with Special Characters
Svn Setup of Existing Directory
How to Lock The Cursor to The Inside of a Window on Linux
Problem of Understanding Clock_Gettime
Git Clone Using Ssh Failed in Windows Due to Permission Issue