Pyenv 的 python 缺少 bzip2 模块

2024-03-26

我使用 pyenv 安装 python 3.8.2 并创建一个 virtualenv。 在virtualenv中,我使用pipenv来安装pandas.

但是,当导入 pandas 时,我得到以下信息:

  [...]
  File "/home/luislhl/.pyenv/versions/poc-prefect/lib/python3.8/site-packages/pandas/io/common.py", line 3, in <module>
    import bz2
  File "/home/luislhl/.pyenv/versions/3.8.2/lib/python3.8/bz2.py", line 19, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'

经过一番谷歌搜索后,我发现有人建议我在系统中安装 bzip2 库后从源代码重建 Python。

但是,尝试安装后sudo dnf install bzip2-devel我看到我已经安装了它。

据我所知,pyenv 在安装某些版本时从源代码构建 python。 那么,为什么它在构建时不能包含 bzip2 模块呢?

如何使用 pyenv 重建 Python 以使 bzip2 可用? 我在 Fedora 30

提前致谢

UPDATE我尝试在详细模式下使用 pyenv 安装另一个版本的 python,以查看编译输出。

编译最后有这样一条信息:

WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?

但正如我之前所说,我检查过我的系统中已经安装了 bzip2。所以我不知道该怎么办。


在 Ubuntu 22 LTS 上

使用 Pyenv 安装 Python 时缺少库问题

修复前:

$> pyenv install 3.11.0

命令结果:

pyenv: /home/user/.pyenv/versions/3.11.0 already exists
continue with installation? (y/N) y
Downloading Python-3.11.0.tar.xz...
-> https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tar.xz


Installing Python-3.11.0...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
WARNING: The Python lzma extension was not compiled. Missing the lzma lib?

TLDR;

解决方法:

sudo apt-get install build-essential zlib1g-dev libffi-dev libssl-dev libbz2-dev libreadline-dev libsqlite3-dev liblzma-dev

Result

修复后:

$> pyenv install 3.11.0

命令结果:

pyenv: /home/user/.pyenv/versions/3.11.0 already exists
continue with installation? (y/N) y
Downloading Python-3.11.0.tar.xz...
-> https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tar.xz
Installing Python-3.11.0...
Installed Python-3.11.0 to /home/user/.pyenv/versions/3.11.0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Pyenv 的 python 缺少 bzip2 模块 的相关文章

随机推荐