Python3: ImportError: No module named '_ctypes' when using Value from module multiprocessing

匿名 (未验证) 提交于 2019-12-03 03:08:02

问题:

I am using ubuntu and have installed python 2.7.5 and 3.4.0. For python 2.7.5, I am able to successfully assign a variable x = Value('i', 2) in python 2.7.5, but not 3.4.0. I am getting:

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' 

I just updated to 3.3.2 through installing the source of 3.4.0. It installed in /usr/local/lib/python3.4

Did I update to python3.4 correctly?

One thing I noticed that python3.4 is installed in usr/local/lib, while python3.3.2 is still installed in usr/lib, so it was not overwritten.

回答1:

On a fresh Debian image, cloning https://github.com/python/cpython and running:

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 build-essential 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 

And then

./configure make sudo make altinstall 

Got 3.7 installed and working for me.



回答2:

Thought I'd add the Centos installs:

sudo yum -y install gcc gcc-c++  sudo yum -y install zlib zlib-devel sudo yum -y install libffi-devel  

Check python version:

python3 -V

Create virtualenv:

virtualenv -p python3 venv



回答3:

Installing libffi-dev and re-installing python3.7 fixed the problem for me.

to cleanly build py 3.7 libffi-dev is required or else later stuff will fail



回答4:

pyenv wiki has the suggestions for various systems to build Python:

https://github.com/pyenv/pyenv/wiki



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!