I have downloaded Python 3.3 from the official site but no idea how to install it.
I'm using Ubuntu 12.04
Best Answer
Python 3.3 has been released on 29 September 2012, several months after Ubuntu 12.04 was released. It is included in Ubuntu 12.10 though as python3.3 package
If you want to install Python 3.3 on Ubuntu version which does not have it in its repositories, you have the following options:
This is very easy and allows you to have multiple Python versions without messing with system python interpreter (which is used by a lot of Ubuntu own programs). On my dev machine I have literally dozens of different Python versions from 2.4 to 3.2 living happily in /opt.
we need C compiler and other stuff to compile Python
sudo apt-get install build-essential
SQLite libs need to be installed in order for Python to have SQLite support.
sudo apt-get install libsqlite3-dev
sudo apt-get install sqlite3 # for the command-line client
sudo apt-get install bzip2 libbz2-dev
Download and compile Python:
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 && sudo make install
Some nice touches to install a py command by creating a symlink:
And this is it. Now you can have any Python version, even an alpha, or, say, to have a few copies of Python 3.3 compiled with different settings... not that many people need that though :)
Use pyenv
There's a software called pyenv which may help you to automate the procedure - what it essentially does is compile Python from source, installing it in your home directory. Its goal is to help you manage multiple Python versions.
If you "replace" the default python installation you will probably break the system. There are many system tools that use python2.X and will fail when using python3. In your case, python3 doesn't have the apt_pkg module, so you get that error.
To solve this just remove the symlink created and link it to the default python2.X (in 12.10 it is python2.7):
You can custom your python3 alias. For this, you can modify your .bashrc file by appending "alias python3='python3.3'" at the end of it. This shell script can do it for you :
#!/bin/bash
cd ~
# Create the ~/.bashrc file if it does not exist
if [ ! -f ./.bashrc ]; then
touch .bashrc
chmod 755 .bashrc
echo "#!/bin/bash" >> .bashrc
fi
# Append the customed alias
echo " " >> .bashrc
echo "alias python3='python3.3'" >> .bashrc
echo " " >> .bashrc
# Reload settings in the .bashrc script
source .bashrc
Best Answer
Python 3.3 has been released on 29 September 2012, several months after Ubuntu 12.04 was released. It is included in Ubuntu 12.10 though as
python3.3
packageIf you want to install Python 3.3 on Ubuntu version which does not have it in its repositories, you have the following options:
Use a PPA
There's a PPA containing Old and New Python versions maintained by Felix Krull. See Luper Rouch's answer for installation instructions.
Compile Python from source
This is very easy and allows you to have multiple Python versions without messing with system python interpreter (which is used by a lot of Ubuntu own programs). On my dev machine I have literally dozens of different Python versions from 2.4 to 3.2 living happily in
/opt
.we need C compiler and other stuff to compile Python
SQLite libs need to be installed in order for Python to have SQLite support.
Download and compile Python:
Some nice touches to install a
py
command by creating a symlink:Alternatively, you can install a bash alias named
py
instead:And this is it. Now you can have any Python version, even an alpha, or, say, to have a few copies of Python 3.3 compiled with different settings... not that many people need that though :)
Use pyenv
There's a software called pyenv which may help you to automate the procedure - what it essentially does is compile Python from source, installing it in your home directory. Its goal is to help you manage multiple Python versions.