Linux 缺少 python bz2 模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12806122/
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
missing python bz2 module
提问by Satish
I have installed at my home directory.
我已经安装在我的主目录中。
[spatel@~ dev1]$ /home/spatel/python-2.7.3/bin/python -V
Python 2.7.3
I am trying to run one script which required python 2.7.x version, and i am getting missing bz2 error
我正在尝试运行一个需要 python 2.7.x 版本的脚本,但我遇到了 bz2 错误
[spatel@~ dev1]$ ./import_logs.py
Traceback (most recent call last):
File "./import_logs.py", line 13, in <module>
import bz2
ImportError: No module named bz2
I have tried to install bz2 module but i got lots of error
我尝试安装 bz2 模块,但出现很多错误
[spatel@dev1 python-bz2-1.1]$ /home/spatel/python-2.7.3/bin/python setup.py install
...
...
...
bz2.c:1765: error: aBZ_FINISH_OKa undeclared (first use in this function)
bz2.c:1765: warning: comparison between pointer and integer
bz2.c:1771: error: aPyMemberDefa has no member named aavail_outa
bz2.c:1778: error: aPyMemberDefa has no member named anext_outa
bz2.c:1778: error: aPyMemberDefa has no member named atotal_out_hi32a
bz2.c:1778: error: aPyMemberDefa has no member named atotal_out_lo32a
bz2.c:1778: error: invalid operands to binary +
bz2.c:1778: warning: statement with no effect
bz2.c:1779: error: aPyMemberDefa has no member named aavail_outa
bz2.c:1779: error: aPyMemberDefa has no member named anext_outa
bz2.c:1779: error: invalid operands to binary -
bz2.c:1779: error: invalid operands to binary -
bz2.c:1779: warning: statement with no effect
bz2.c:1783: error: aPyMemberDefa has no member named aavail_outa
bz2.c:1784: error: aPyMemberDefa has no member named atotal_out_hi32a
bz2.c:1784: error: aPyMemberDefa has no member named atotal_out_lo32a
bz2.c:1784: warning: passing argument 2 of a_PyString_Resizea makes integer from pointer without a cast
error: command 'gcc' failed with exit status 1
采纳答案by jviotti
Probably as you built python from source, you don't have bz2 headers.
可能当您从源代码构建 python 时,您没有 bz2 标头。
Install them on Ubuntu/Debian:
在 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.
并再次构建python。您可能会注意到,python 在配置/构建时会检查大量库,如果您错过了其中的一些库,您可能不会在您的案例中获得对 bz2 之类的库的支持。
You should get prebuild binaries to avoid this kind of stuff. Ubuntu 12.04 packs python 2.7.3, the version your script needs.
你应该得到预构建的二进制文件来避免这种事情。Ubuntu 12.04 包含python 2.7.3,您的脚本需要的版本。
回答by AFoglia
You need to have the development version of the bz2 c library installed. You probably don't and that's why it wasn't installed when you built your user copy of python. On Ubuntu it's the libbz2-dev package. It's probably named the same or similar on Fedora. Or you can download it from www.bzip.org.
您需要安装 bz2 c 库的开发版本。您可能没有,这就是为什么在您构建 Python 用户副本时未安装它的原因。在 Ubuntu 上,它是 libbz2-dev 包。它在 Fedora 上的名称可能相同或相似。或者您可以从 www.bzip.org 下载它。
回答by James Tang
On CentOS 7, install bzip2-devel:
在 CentOS 7 上,安装 bzip2-devel:
sudo yum install bzip2-devel
Then re-compile python.
然后重新编译python。
回答by lvxiaobo616
You must reinstall bzip2
by source code:
您必须bzip2
通过源代码重新安装:
yum install bzip2-devel
wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
tar -zxvf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make && make install
configure and re compile python
yum install bzip2-devel
wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
tar -zxvf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make && make install
配置并重新编译python
those steps working sometimes.
这些步骤有时会起作用。
Finally, I have figured out the problem, it needs the /usr/local/Python-3.5.2/lib/python3.5/lib-dynload/_bz2.cpython-35m-x86_64-linux-gnu.so, it must have a problem when I compile bzip2 by source code. I copy this file from another VM to solve the problem.
最后,我找到了问题所在,它需要 /usr/local/Python-3.5.2/ lib/python3.5/lib-dynload/_bz2.cpython-35m-x86_64-linux-gnu.so,它必须有当我通过源代码编译 bzip2 时出现问题。我从另一个虚拟机复制这个文件来解决这个问题。
回答by Mithril
If you python install on a specific location, just install libbz2-dev
would not work.
如果您将 python 安装在特定位置,则仅安装libbz2-dev
将不起作用。
There is a workaround for centos:
centos 有一个解决方法:
Centos 6
sudo cp /usr/lib64/python2.6/lib-dynload/bz2.so /python_install_path/lib/python2.7
Centos 7
sudo cp /usr/lib64/python2.7/lib-dynload/bz2.so /python_install_path/lib/python2.7
Centos 6
sudo cp /usr/lib64/python2.6/lib-dynload/bz2.so /python_install_path/lib/python2.7
Centos 7
sudo cp /usr/lib64/python2.7/lib-dynload/bz2.so /python_install_path/lib/python2.7
python_install_path
usually is /usr/local/lib/python2.7/
, you would need replace that if you have custom python path.
python_install_path
通常是/usr/local/lib/python2.7/
,如果您有自定义 python 路径,则需要替换它。
回答by trinth
I should also add that on CentOS 6, make sure you have bzip2-devel
, not bzip2-libs
installed.
我还应该在 CentOS 6 上补充一点,确保你有bzip2-devel
,没有bzip2-libs
安装。
回答by Jingjia Luo
the solution above can solve bz2 problems with python2.7. but not python 3.x yeah, you need _bz2.cpython-3xm-x86_64-linux-gnu.so, however you should build it in your own env.
上面的解决方案可以用python2.7解决bz2问题。但不是 python 3.x 是的,你需要 _bz2.cpython-3xm-x86_64-linux-gnu.so,但是你应该在你自己的环境中构建它。
here's my solution:
这是我的解决方案:
- yum install bzip2-devel. (or apt-get)
- download bzip2-1.0.6. make && make install ()
- build Python3's _bz2.cpython like this:
- yum 安装 bzip2-devel。(或 apt-get)
- 下载 bzip2-1.0.6。make && make install ()
- 像这样构建 Python3 的 _bz2.cpython:
vim run.sh under python3's source code folder:Python-3.x.x
python3的源代码文件夹下的vim run.sh:Python-3.xx
export CFLAGS="-I/usr/include"
export LDFLAGS="-L/usr/lib64"
export LD_LIBRARY_PATH=/usr/lib64
make distclean
./configure --prefix=/home/xxx/Python3 && make && make install
you can set prefix the same of your pre version, that will not uninstrall any package you installed. And before that, make a backup folder.
您可以设置与您的预版本相同的前缀,这不会取消安装您安装的任何软件包。在此之前,制作一个备份文件夹。
回答by chi doujiao
Here is my solution on CentOS: (step 2-6 may skip)
这是我在 CentOS 上的解决方案:(步骤 2-6 可以跳过)
sudo yum install bzip2-devel
download
bzip2-1.0.6.tar.gz
from https://github.com/nemequ/bzip2/releasestar -zxvf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make && make install
- download file from https://github.com/Imaginashion/ccdev-vision/blob/master/.fr-d0BNfn/django-jquery-file-upload/venv/lib/python3.5/lib-dynload/_bz2.cpython-35m-x86_64-linux-gnu.soand move it to
/[your python path]/lib-dynload/_bz2.cpython-35m-x86_64-linux-gnu.so
sudo ln -s `find /usr/lib64/ -type f -name "libbz2.so.1*"` /usr/lib64/libbz2.so.1.0
credit to https://michaelheap.com/error-while-loading-shared-libraries-libbz2-so-1-0-cannot-open-shared-object-file-on-centos-7
sudo yum install bzip2-devel
bzip2-1.0.6.tar.gz
从https://github.com/nemequ/bzip2/releases下载tar -zxvf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make && make install
- 从https://github.com/Imaginashion/ccdev-vision/blob/master/.fr-d0BNfn/django-jquery-file-upload/venv/lib/python3.5/lib-dynload/_bz2.cpython-下载文件35m-x86_64-linux-gnu.so并将其移动到
/[your python path]/lib-dynload/_bz2.cpython-35m-x86_64-linux-gnu.so
sudo ln -s `find /usr/lib64/ -type f -name "libbz2.so.1*"` /usr/lib64/libbz2.so.1.0
归功于https://michaelheap.com/error-while-loading-shared-libraries-libbz2-so-1-0-cannot-open-shared-object-file-on-centos-7
回答by duybinh0208
I also have this problem when installing Python
from a different location (I use Python 3.7.5
on Centos 7
).
Python
从其他位置安装时我也有这个问题(我使用Python 3.7.5
on Centos 7
)。
Here are steps that I make it be able to work:
以下是我使其能够工作的步骤:
- Export environment variables
- 导出环境变量
export PATH=<YOUR_PYTHON_PATH>/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
export PYTHONPATH=<YOUR_PYTHON_PATH>/lib/python3.7/site-packages
export LD_RUN_PATH=/usr/local/lib:/usr/lib64
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib64
export CFLAGS="-I/usr/include"
export LDFLAGS="-L/usr/lib64"
- Install bzip2-devel
- 安装 bzip2-devel
yum install -y bzip2-devel
- Download & compile bzip2
- 下载并编译 bzip2
wget/curl <bzip2_url>
make
make install
By doing this, you don't need to download the _bz2.cpython-35m-x86_64-linux-gnu.so
file.
通过这样做,您无需下载_bz2.cpython-35m-x86_64-linux-gnu.so
文件。
回答by BryanMinorPhD
I had this happen for python 3.8.2 when importing pandas: import pandas as pd
导入熊猫时,python 3.8.2 发生了这种情况: import pandas as pd
resulted in a long error message ending with: "error: ModuleNotFoundError: No module named '_bz2'"
导致了一条以“错误:ModuleNotFoundError:没有名为‘_bz2’的模块”结尾的长错误消息
This was resolved by doing the following 2 bash commands:
这是通过执行以下 2 个 bash 命令解决的:
sudo apt-get install libbz2-dev
sudo cp /usr/lib/python3.8/lib-dynload/_bz2.cpython-38-x86_64-linux-gnu.so /usr/local/lib/python3.8/
Then it worked fine.
然后它工作得很好。