Install python 3.3 in linux (python 3.5 is the newest)

Install python 3.3 in linux (python 3.5 is the newest)

I have installed python3.5 at my linux computer. To use the package django-polymorphic, which only supporty python 2.7, python 3.2 and 3.3 I am forced to use an older version of python.

  1. (Why) would that be (not) good?
  2. How do I force my computer to use an older version? (I don't worry about removing the older one.) Anybody knows? Thanx for reading this. (Sorry if this is a trivial question. I'm a noob with linux shell commands (I know how to install and upgrade, but that's all), and I haven't found anything)

答案1

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

相关内容