missing python bz2 module
Probably as you built python from source, you don't have bz2 headers.
Install them on Ubuntu/Debian:
sudo apt-get install libbz2-dev
Fedora:
sudo yum install bzip2-devel
And build python again.
You may notice that python checks for lots of libraries when configuring/building, if you miss some of them you probably will get no support for libs like bz2 on your case.
You should get prebuild binaries to avoid this kind of stuff. Ubuntu 12.04 packs python 2.7.3, the version your script needs.
Missing BZ2 module in python
bz2
is an optional dependency of python, but sklearn
assumes your python installation has this module.
There are at least two possible ways to fix this:
- update your version of joblib to make its dependence on
bz2
optional. (Thanks to sascha for pointing this out.) - or, install
libbz2
and then re-build python3.6.
ImportError: No module named bz2 for Python 2.7.2
Okay, this is much easier to understand in answer form, so I'll move what I would write in my comment to this answer.
Luckily for you, you didn't overwrite the system version of python, as Ubuntu 11.10 comes with 2.7.2 preinstalled.
Your python binaries (python
and python2.7
) are located in /usr/local/bin
, which is a directory where user-specific stuff is usually installed. This is fine, it means your system python is still there.
First, just try to run the system python. Type this from the command line:
/usr/bin/python -c "import bz2; print bz2.__doc__"
This should print out something like this:
λ > /usr/bin/python -c "import bz2; print bz2.__doc__"
The python bz2 module provides a comprehensive interface for
the bz2 compression library. It implements a complete file
interface, one shot (de)compression functions, and types for
sequential (de)compression.
If so, means you're fine.
So you just have to fix your PATH
, which tells the shell where to find commands. /usr/local/bin
is going to have priority over /usr/local
, so there are some ways to fix this, in order of difficulty/annoyance/altering your system:
Remove the symlink python
from /usr/local/bin
This will make it so that when you type python
, it should go back to executing /usr/bin/python
, which is an alias for the system's python 2.7.2.
sudo rm /usr/local/bin/python
Move /usr/bin
to have higher precedence in the PATH
Might not be desirable if you already have stuff in /usr/local/bin
that should have precedence over /usr/bin
, but I'm adding this for completeness.
In your shell profile (not sure what Ubuntu's default is, but I'm using ~/.bash_profile
, you can do this:
export PATH=/usr/bin:$PATH
Remove your python install
This is extreme and the first option I presented should be your first option.
Do you really need your own version of Python? If you want isolated python environments you probably really want virtualenv
. You can probably remove yours unless there's a reason not to.
It's going to be a little annoying though, but basically:
- Remove the
python
andpython2.7
andpythonw
andpythonw2.7
commands from/usr/local/bin
. - Remove
/usr/local/lib/python/2.7.2
This part is not complete because I forget what else there is.
'bz2 is module not available' when installing Pandas with pip in python virtual environment
You need to build python with BZIP2 support.
Install the following package before building python:
- Red Hat/Fedora/CentOS:
yum install bzip2-devel
- Debian/Ubuntu:
sudo apt-get install libbz2-dev
Extract python tarball. Then
configure;
make;
make install
Install pip
using the new python.
Alternative:
Install a binary python distribution using yum or apt, that was build with BZIP2 support.
See also: ImportError: No module named bz2 for Python 2.7.2
Python's bz2 module not compiled by default
You need libbz2.so (the general purpose libbz2 library) properly installed first, for Python to be able to build its own interface to it. That would typically be from a package in your Linux distro likely to have "libbz2" and "dev" in the package name.
Related Topics
Permission Check Discord.Py Bot
Looping in Python: Modify One Column Based on Values in Other Columns
How to Sort a List of Lists by a Specific Index of the Inner List
How to Properly Setup Pipenv in Pycharm
Python - Get Last Element After Str.Split()
Importerror: No Module Named Sklearn (Python)
Using Buttons in Tkinter to Navigate to Different Pages of the Application
Python - How to Check If Table Exists
Pickle - Cpickle.Unpicklingerror: Invalid Load Key, '?'
How to Add Pandas Data to an Existing CSV File
Typeerror: Unsupported Operand Type(S) for ** or Pow(): 'List' and 'Int'
Install Utils Package in Python Facing With Error Package Not Found
Get Business Days Between Start and End Date Using Pandas
How to Execute Multiple Commands in a Single Session in Paramiko - Python