我正在使用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中,所以它没有被覆盖。
安装libffi-dev
并重新安装python3.7为我解决了这个问题。
要干净地建立py 3.7 libffi-dev
是必需的,否则以后的东西会失败
如果使用RHEL / Fedora:
yum install libffi-devel
要么
sudo dnf install libffi-devel
如果使用Debian / Ubuntu:
sudo apt-get install libffi-dev
在一个新的Debian图像上,克隆https://github.com/python/cpython并运行:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
sudo apt-get install libncursesw5-dev libgdbm-dev libc6-dev
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
sudo apt-get install libssl-dev openssl
sudo apt-get install libffi-dev
现在执行上面克隆的configure
文件:
./configure
make # alternatively `make -j 4` will utilize 4 threads
sudo make altinstall
已安装3.7并为我工作。
看起来我说我会用更多的解释更新这个答案,两年后我没有太多补充。
python-dev
这样的某些图书馆可能是必要的。altinstall
而不是install
命令中的make参数。除此之外,我想选择是通过cpython代码库来查找需要满足的#include
指令,但我通常做的是继续尝试安装包并继续阅读输出安装所需的包直到它成功了。
让我想起Engineer, the Manager and the Programmer whose car rolls down a hill的故事。
在CentOS或任何redhat linux机器上安装Python 3.7的详细步骤:
sudo yum -y install gcc gcc-c++ sudo yum -y install zlib zlib-devel sudo yum -y install libffi-devel ./configure make make install
以为我会添加Centos安装:
sudo yum -y install gcc gcc-c++
sudo yum -y install zlib zlib-devel
sudo yum -y install libffi-devel
检查python版本:
python3 -V
创建virtualenv:
virtualenv -p python3 venv
请参阅this thread,对于libffi的自定义安装,Python3.7很难找到libffi的库位置。另一种方法是在Makefile中设置CONFIGURE_LDFLAGS
变量,例如CONFIGURE_LDFLAGS="-L/path/to/libffi-3.2.1/lib64"
。