我使用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中,所以它没有被覆盖。


当前回答

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

遵循这个:

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

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

其他回答

在CentOS或任何redhat linux机器上安装Python 3.7的详细步骤:

从https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz下载Python 解压新文件夹中的内容 在同一目录下打开终端 一步一步运行下面的代码:

Sudo yum -y安装GCC GCC -c++ Sudo yum -y install zlib-devel Sudo yum -y安装libffi-devel . / configure 使 制作安装

安装libffi-dev和重新安装python3.7为我解决了这个问题。

为了干净地构建py 3.7,需要libffi-dev,否则后面的东西会失败

如果使用RHEL/Fedora:

yum install libffi-devel

or

sudo dnf install libffi-devel

如果使用Debian/Ubuntu:

sudo apt-get install libffi-dev

如何从源代码安装Python没有libffi在/usr/local?

从github下载libffi,安装到/path/to/local 下载python源代码并按以下配置进行编译:

export PKG_CONFIG_PATH=/path/to/local/lib/pkgconfig
./configure --prefix=/path/to/python \
    LDFLAGS='-L/path/to/local/lib -Wl,-R/path/to/local/lib' \
    --enable-optimizations
make
make install

在我的Ubuntu 18.04机器上,我有一个常见的问题,python找不到_ctypes与pyenv安装的python。

在我的例子中,libffi-dev已经安装了。按照@MikeiLL的建议,从源代码安装cpython也没有帮助。

结果发现是自制的问题。

Ajkerrigans建议解决方案的pyenvs github问题为我解决了这个问题。

解决方案总结:告诉pyenv使用homebrew管理的GCC构建Python,使用如下命令:

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

这假设任何构建依赖项都已通过pyenv wiki中指定的Homebrew安装。在写这篇文章时,Linux上的Homebrew看起来是这样的:

brew install bzip2 libffi libxml2 libxmlsec1 openssl readline sqlite xz zlib

我正在使用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创建的应用程序文件现在可以工作了!!