15

I am going through this post Numpy, Scipy, and Pandas - Oh My!, installing some python packages, but got stuck at the line for installing Pandas:

pip install -e git+https://github.com/pydata/pandas#egg=pandas

I changed 'wesm' to 'pydata' for the latest version, and the only other difference to the post is that I'm using pythonbrew.

I found this post, related to the error, but where is the Makefile for bz2 mentioned in the answer? Is there another way to resolve this problem?

Any help would be much appreciated. Thanks.

1

3 Answers 3

31

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

Sign up to request clarification or add additional context in comments.

3 Comments

There is no other option? .. I have a python tarball and pip installed. I did pip install pandas and I am getting this error..
You need python with bzip2 libs linked in. That’s a build tome option. You either build your python interpreter from source, or install a binary python distribution which comes with bzip2 support.
just for further information. it seems setup.py decide whether compile bz2 # Gustavo Niemeyer's bz2 module. if (self.compiler.find_library_file(lib_dirs, 'bz2')): xxxx
21

I spent a lot of time on the internet and got a partial answer everywhere. Here is what you need to do to make it work. Follow every step.

  1. sudo apt-get install libbz2-dev Thanks to Freek Wiekmeijer for this.
    Now you also need to build python with bz2. Previously installed python won't work. For that do following:

  2. Download stable python version from https://www.python.org/downloads/source/ then extract that Gzipped source tarball file. You can use wget https://python-tar-file-link.tgz to download and tar -xvzf python-tar-file.tgz to extract it in current directory

  3. Go inside extracted folder then run following commands one at a time

    • ./configure
    • make
    • make install
  4. This will build a python file with bz2 that you previously installed

  5. Since this python doesn't have pip installed, idea was to create a virtual environment with above-built python then install pandas using previously installed pip

  6. You will see python file in the same directory. Just create a virtual environment.

    • ./python -m env myenv (create myenv in the same directory or outside it's your choice)
    • source myenv/bin/activate (activate virtual environment)
    • pip install pandas (install pandas in the current environment)
  7. That's it. Now with this environment, you should be able to use pandas without error.

4 Comments

Also I recommend use make altinstall for not to replace default python version.
Also I'd suggest to use: ./configure --enable-optimizations additionally to configure.
Thank you, I've searched many threads, this is the first "full" answer I've come across that worked for me. Thank you for the clear step by step
I had a problem where my pip was not able to recognize a tar.bz2 package. I had installed another version of python on ubuntu from source. Installing libbz2-dev fixed it. Eternally thankful to humans of stackoverflow. 😀
3

pyenv

I noticed that installing Python using source takes a long time (I am doing it on i7 :/ ); especially the make and make test...

A simpler and shorter solution was to install another version of Python (I did Python 3.7.8) using pyenv, install it using these steps.

It not only saved the problem of using multiple Python instances on the same system but also maintain my virtual environments without virtualenvwrapper (which turned buggy on my newly setup ubuntu-20.04).

1 Comment

please summaries what "these steps" are. your answer does not explain in any way how or why this answer the question

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.