安装Python 3.7的libffi-dev时遇到问题

时间:2019-06-28 17:12:34

标签: python-3.x ubuntu ctypes libffi

当尝试在Ubuntu系统上以桌面模式安装pgadmin4时,我收到了针对_ctypes的ModuleNotFoundError。

我做了一些研究,发现_ctypes需要安装libffi-dev软件包。但是,似乎为Python 2.7安装了libffi-dev和_ctypes,当我运行import ctypes时似乎可以正常工作:

$ python2
Python 2.7.15+ (default, Nov 27 2018, 23:36:35) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> 

当我尝试对Python 3.7进行相同操作时,它不起作用:

$ python
Python 3.7.3 (default, Jun 21 2019, 12:46:58) 
[GCC 7.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 "/usr/local/lib/python3.7/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

如何将_ctypes模块添加到我的Python 3.7配置中?

1 个答案:

答案 0 :(得分:1)

如果从源文件安装python,则必须按照https://superuser.com/questions/1412975/how-to-build-and-install-python-3-7-x-from-source-on-debian-9-8中所述手动安装一些必需的软件包。

实际上,您应该在make之后看到一些错误,原因是未找到libffi,如下面的屏幕快照所示。但是,尽管出现错误,您仍然可以运行make install。在安装后打开python并导入模块时,它会给您这样的错误。

要解决此问题,您可以在提到的libffilibffi-devel./configure之前安装相关软件包,即makemake install(redhat)在: Package libffi was not found in the pkg-config search path REDHAT6.5https://bugs.python.org/issue31652

enter image description here