在 python 虚拟环境中使用 pip 安装 Pandas 时出现“bz2 模块不可用”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/22346269/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'bz2 is module not available' when installing Pandas with pip in python virtual environment
提问by qAp
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:
我正在阅读这篇文章Numpy、Scipy 和 Pandas - 哦,天哪!, 安装了一些 python 包,但卡在安装 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.
对于最新版本,我将“wesm”更改为“pydata”,与该帖子的唯一其他区别是我使用的是 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?
我发现这篇文章与错误有关,但是答案中提到的 bz2 的 Makefile 在哪里?有没有其他方法可以解决这个问题?
Any help would be much appreciated. Thanks.
任何帮助将非常感激。谢谢。
回答by Freek Wiekmeijer
You need to build python with BZIP2 support.
您需要使用 BZIP2 支持构建 python。
Install the following package before building python:
在构建python之前安装以下包:
- Red Hat/Fedora/CentOS: yum install bzip2-devel
- Debian/Ubuntu: sudo apt-get install libbz2-dev
- 红帽/Fedora/CentOS: yum install bzip2-devel
- Debian/Ubuntu: sudo apt-get install libbz2-dev
Extract python tarball. Then
提取python tarball。然后
configure;
make;
make install
Install pipusing the new python.
pip使用新的 python安装。
Alternative:
选择:
Install a binary python distribution using yum or apt, that was build with BZIP2 support.
使用 yum 或 apt 安装二进制 python 发行版,该发行版是使用 BZIP2 支持构建的。
回答by bikram
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.
我在互联网上花了很多时间,到处都得到了部分答案。这是您需要做的事情才能使其发挥作用。遵循每一步。
- sudo apt-get install libbz2-devThanks to Freek Wiekmeijerfor this.
- sudo apt-get install libbz2-dev感谢Freek Wiekmeijer。
Now you also need to build python with bz2. Previously installed python won't work. For the do following:-
现在你还需要用 bz2 构建 python。以前安装的python 不起作用。对于执行以下操作:-
- Download stable python version from https://www.python.org/downloads/source/then extract that Gzipped source tarballfile. You can use - wget https://python-tar-file-link.tgzto download and- tar -xvzf python-tar-file.tgz to exact it in current directory
- Go inside exacted folder then run following command on at a time - ./configure
- make
- make install
 
- This will build a python file with bz2 that you previously installed
- 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
- You will see pythonfile 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)
 
- That's it. Now with this environment, you should be able to use pandas without error.
- 从https://www.python.org/downloads/source/下载稳定的 python 版本,然后解压缩该Gzip 源 tarball文件。您可以使用 - wget https://python-tar-file-link.tgz下载和- tar -xvzf python-tar-file.tgz to exact it in current directory
- 进入精确文件夹,然后一次运行以下命令 - ./configure
- make
- make install
 
- 这将使用您之前安装的 bz2 构建一个 python 文件
- 由于这个python没有安装pip,想法是用上面构建的python创建一个虚拟环境,然后使用以前安装的pip安装pandas
- 您将python在同一目录中看到文件。只需创建一个虚拟环境。- ./python -m env myenv(在同一目录或外部创建 myenv 由您选择)
- source myenv/bin/activate(激活虚拟环境)
- pip install pandas(在当前环境下安装pandas)
 
- 就是这样。现在有了这个环境,你应该可以毫无错误地使用 Pandas。

