Problem in installing Python 3.3 in Ubuntu 12.04

Initially I installed Python 3.3 from source, but then I removed and deleted the directory /usr/lib/python3.3.

When I am installing it using aptitude, I am getting this error.

Unpacking python3.3 (from .../python3.3_3.3.1-1ubuntu5_i386.deb) ...
Processing triggers for man-db ...
Processing triggers for bamfdaemon ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for desktop-file-utils ...
Setting up python3.3 (3.3.1-1ubuntu5) ...
python3.3: can't open file '/usr/lib/python3.3/py_compile.py': [Errno 2] No such file or directory
dpkg: error processing python3.3 (--configure):
 subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
 python3.3
E: Sub-process /usr/bin/dpkg returned an error code (1)
A package failed to install.  Trying to recover:
Setting up python3.3 (3.3.1-1ubuntu5) ...
python3.3: can't open file '/usr/lib/python3.3/py_compile.py': [Errno 2] No such file or directory
dpkg: error processing python3.3 (--configure):
 subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:

Any idea how to rectify the error?


Solution 1:

You've destroyed the libpython3.3-minimal package in that removal. Reinstall it, than try installing python3.3 again. If you have other packages installed that depend on libpython3.3-minimal, they may need to be reinstalled too.

Note: For next time, manually installed software should go in /usr/local or /opt, never to /usr directly. That avoids conflict between manually installed files and packages, because all packages are installed to /usr.

Solution 2:

To install python version 3.3.2 here are the steps I followed and it worked

wget http://python.org/ftp/python/3.3.2/Python-3.3.2.tar.bz2

tar -xvjf ./Python-3.3.2.tar.bz2

cd ./Python-3.3.2

./configure --prefix=/opt/python3.3

make && make install

mkdir ~/bin

ln -s /opt/python3.3/bin/python ~/bin/py

echo 'alias py="/opt/python3.3/bin/python3"' >> .bashrc