我使用Ubuntu,并安装了Python 2.7.5和3.4.0。在Python 2.7.5中,我能够成功地分配一个变量x = Value(' I ', 2),但在3.4.0中不能。我得到:

Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/usr/local/lib/python3.4/multiprocessing/context.py", line 132, in Value
      from .sharedctypes import Value
   File "/usr/local/lib/python3.4/multiprocessing/sharedctypes.py", line 10, in <
module>
   import ctypes
   File "/usr/local/lib/python3.4/ctypes/__init__.py", line 7, in <module>
      from _ctypes import Union, Structure, Array
ImportError: No module named '_ctypes'

我刚刚通过安装3.4.0的源代码更新到了3.3.2。它安装在/usr/local/lib/python3.4.

我是否正确地更新到Python 3.4 ?

我注意到一件事,Python 3.4安装在usr/local/lib中,而Python 3.3.2仍然安装在usr/lib中,所以它没有被覆盖。


当前回答

我正在使用MAC M1,我有这个错误:

... __boot__.py", line 30, in <module> import ctypes
and something was said about the file libffi.8.dylib

我在Anaconda上下载了这个东西,现在一切都正常了:

https://anaconda.org/wakari/libffi

我告诉你,因为上面的大部分内容不是针对MAC的,就是过时了,我的Python版本是Anaconda 3.10.4

使用py2app创建的应用程序文件现在可以工作了!!

其他回答

当我试图在Ubuntu 18.04中使用next命令安装Python 3.7.3时,遇到了这个错误:$ pyenv install 3.7.3。 运行$ sudo apt-get update && sudo apt-get install libffi-dev(此处建议)后,安装成功。 问题在那里得到了解决。

这解决了我在Debian上同样的错误:

sudo apt-get install libffi-dev

然后再次编译

参考:issue31652

没有根的CentOS

安装libffi-3.2(不使用libffi-3.3) wget ftp://sourceware.org/pub/libffi/libffi-3.2.tar.gz libffi-3.2.tar.gz cd libffi - 3.2 / . / configure——prefix = $ YOUR_LIBFFI_DIR Make && Make安装 安装Python3 ./configure——prefix=$YOUR_PATH/python/3.7.10 LDFLAGS=-L${YOUR_LIBFFI_DIR}/lib64 PKG_CONFIG_PATH=${YOUR_LIBFFI_DIR}/lib/pkgconfig——enable-shared Make && Make安装

谢谢JohnWSteill

这些解决方案都不奏效。你必须重新编译你的python;一旦所有所需的包完全安装。

遵循这个:

安装所需软件包 执行./configure——enable-optimizations

https://gist.github.com/jerblack/798718c1910ccdd4ede92481229043be

如果您不介意使用Miniconda,默认情况下会安装必要的外部库和_ctypes。它会占用更多的空间,并且可能需要使用较旧的Python版本(例如,在撰写本文时,使用3.7.6而不是3.8.2)。