'_ctypes' 通过 pyenv 安装 python 时缺少模块



我正试图在Ubuntu 20.04上使用pyenv和自制软件来设置一个环境。我的python系统安装没有问题。然而,当我使用pyenv安装特定版本的python时,我在运行Jupyter时遇到了以下问题:

> jupyter notebook
Traceback (most recent call last):
File "/home/parzydlo/.pyenv/versions/3.10.3/bin/jupyter-notebook", line 5, in <module>
from notebook.notebookapp import main
File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/site-packages/notebook/notebookapp.py", line 76, in <module>
from .base.handlers import Template404, RedirectWithParams
File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/site-packages/notebook/base/handlers.py", line 35, in <module>
from notebook.utils import is_hidden, url_path_join, url_is_absolute, url_escape, urldecode_unix_socket_path
File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/site-packages/notebook/utils.py", line 8, in <module>
import ctypes
File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

验证包裹是否丢失:

> python3
Python 3.10.3 (main, Apr  7 2022, 19:51:28) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

当我切换回系统python时:

> pyenv local system
> python3
Python 3.9.12 (main, Mar 23 2022, 21:36:19)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>>

在SO上的许多线程之后,我安装了libffi-dev,并尝试重新安装pyenv-python,但问题仍然存在。也许值得一提的是,我使用自制软件作为包管理器,但必须使用apt.安装libffi-dev

最后,我阅读了[这篇关于dev.to][1]的文章,其中建议了以下修复:

CC="$(brew --prefix gcc)/bin/gcc-11" 
pyenv install --verbose 3.10.0

不幸的是,这也没有解决问题。[1] :https://dev.to/ajkerrigan/homebrew-pyenv-ctypes-oh-my-3d9#isolating-有用的改变

我也有类似的问题,诀窍是需要在所有apt install lib**-dev之后重新安装相同的python版本,例如pyenv install -f

相关内容

  • 没有找到相关文章

最新更新