I'm using Python 2.7.2 on Ubuntu 11.10. I got this error when importing the bz2 module:
ImportError: No module named bz2
I thought the bz2 module is supposed to come with Python 2.7. How can I fix this problem?
EDIT: I think I previously installed Python 2.7.2 by compiling from source. Probably at that point I didn't have libbz2-dev and so the bz2 module is not installed. Now, I'm hoping to install Python2.7 through
sudo apt-get install python2.7
But it will say it's already installed. Is there a way to uninstall the previous Python2.7 installation and reinstall?
I used a symlink between
/usr/lib64/python2.6/lib-dynload/bz2.so /usr/local/lib/python2.7/lib-dynload/
Worked fine for me...
I meet the same problem, here's my solution.
The reason of import error is while you are building python, system couldn't find the bz2 headers and skipped building bz2 module.
Install them on Ubuntu/Debian:
Fedora:
and then rebuild python
comes from another answer
@birryree's answer helps to back to the system's original python.
For Ubuntu/Debian:
For Fedora:
And then recompile the python and install it.
I had the same problem with Python 2.17.15 and pyenv on Ubuntu. System python from /usr/bin/python worked fine. In my case it helped to install libbz2-dev and then to reinstall python 2.7.15:
In case, you must be used python2.7, you should run: (Centos 6.4)
matocnhoi's answer works for me in centOS
and I used virtualenv, so the command is