'bz2 is module not available' when installing Pandas with pip in python virtual environment

喜夏-厌秋 提交于 2020-01-25 08:41:05

问题


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:


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




回答2:


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 the do following:-

  1. 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 exact it in current directory

  2. Go inside exacted folder then run following command on at a time

    • ./configure
    • make
    • make install
  3. This will build a python file with bz2 that you previously installed
  4. 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
  5. 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)
  6. That's it. Now with this environment, you should be able to use pandas without error.


来源:https://stackoverflow.com/questions/22346269/bz2-is-module-not-available-when-installing-pandas-with-pip-in-python-virtual

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!