You can install a new version of Python 3.3 alongside the existing versions of Python without making any changes to the default Python versions and without making any changes to the versions of Python that are already installed. That way your system will continue to use the default versions of Python in the same way as usual unless you specifically tell it to use Python 3.3 (for example to use django-polymorphic).
Open the terminal and type:
sudo apt-get install build-essential libsqlite3-dev sqlite3
wget http://www.python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz
tar xJf ./Python-3.3.5.tar.xz
cd ./Python-3.3.5
./configure --prefix=/opt/python3.3
make
make test
sudo make altinstall
echo 'alias py3.3="/opt/python3.3/bin/python3.3"' >> .bashrc
source ~/.bashrc
You can now run Python 3.3 using the command py3.3
.
make install
can overwrite or masquerade the python binary. make altinstall
is therefore recommended instead of make install
since it only installs in exec_prefix/bin/pythonversion
.Python 3.3 documentation
Now that you have Python 2.7, Python 3.3 and Python 3.5 installed you can change from the default Python to the alternative Python 3.3 and back using the following update-alternatives
commands.
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
sudo update-alternatives --install /usr/bin/python python /opt/python3.3/bin/python3.3 3
sudo update-alternatives --config python
After running sudo update-alternatives --config python
there will be three choices for the alternative python (providing /usr/bin/python
). Press enter to keep the current choice(*), or type a selection number (which may be 1, 2 or 3).
Other useful python commands:
python --version # show python version
update-alternatives --list python # list all python alternatives
1Can you run a
sudo apt-cache show python3.3
to see if it's in the Ubuntu repo? – DrZoo – 2017-02-10T16:13:54.997When I run this I get an answer about the package lib2to3. I tried to find version 3.3 with synaptic but it wasn't there. [Now I use python 2.7 because everything works like this, I also had a problem with django in version 3.x, so I returned to the older one, but it's not satisfying.) – Asqiir – 2017-02-10T18:12:22.770