我使用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中,所以它没有被覆盖。
我的解决方案:
用apt-get安装libffi-dev没有帮助。
但是这有帮助:从源代码安装libffi,然后从源代码安装Python 3.8。
我的配置:
Ubuntu 16.04 LTS
Python 3.8.2
循序渐进:
当从Visual Studio Code启动调试器时,我得到了错误消息“ModuleNotFoundError: No module named '_ctypes'”,当运行python3 -c“import sklearn;sklearn.show_versions()”。
从https://github.com/libffi/libffi/releases下载libffi v3.3
安装libtool: sudo apt-get Install libtool
文件README。libffi的Md提到autoconf和automake也是必要的。它们已经安装在我的系统上了。
配置libffi不带docs:
. / configure——disable-docs
做检查
Sudo make install
从https://www.python.org/downloads/下载python 3.8
. / configure
使
做测试
制作安装
之后,我的python安装可以找到_ctypes。
我也有同样的问题。以上的方法对我来说都没用。关键的挑战是我没有根权限。因此,我首先下载libffi的源代码。然后我用常用的命令来编译:
./configure --prefix=desired_installation_path_to_libffi
make
然后我重新编译python使用
./configure --prefix=/home/user123/Softwares/Python/installation3/ LDFLAGS='-L/home/user123/Softwares/library/libffi/installation/lib64'
make
make install
在我的例子中,'home/user123/Softwares/library/libffi/installation/lib64'是libffi安装目录的路径。所以是定位。“/home/user123/ software /Python/installation3/ is”为Python安装目录的路径。根据您的情况修改它们。
我正在使用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创建的应用程序文件现在可以工作了!!