2015-10-19 118 views
10

导入​​时出现以下错误,但仅在我的虚拟环境(Python 3.4)中导入。在virtualenv中的在virtualenv中导入Python的ctypes错误

>>> import ctypes 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/lib/python3.4/ctypes/__init__.py", line 7, in <module> 
    from _ctypes import Union, Structure, Array 
    ImportError: /home/user/Code/Python/venvs/main/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so: undefined symbol: _PyTraceback_Add 

PIP冻结:

beautifulsoup4==4.4.0 
blessings==1.6 
Django==1.8.4 
image==1.4.1 
Pillow==2.9.0 
wheel==0.24.0 

我该如何解决这个问题?它适用于主要的python 3.4解释器...

+4

在3.4.3中,旧的'_ctypes_add_traceback'被移动到内部API,_PyTraceback_Add(参见[issue 22462](http://bugs.python.org/issue22462))。看起来,您在某种程度上使用了带有较旧版本Python 3.4的'_ctypes'扩展模块的3.4.3 +版本。 – eryksun

+0

非常感谢@eryksun!它现在工作:) – David

回答

9

由于eryksun described,这个问题似乎与3.4。*版本的Python中的known bug有关。我设法解决它在Ubuntu 14.04升级到Python的3.5以下this answer

sudo apt-get install software-properties-common 
sudo add-apt-repository ppa:fkrull/deadsnakes 
sudo apt-get update 
sudo apt-get install python3.5 python3.5-dev python3.5-venv 
# create a python3.5 virtualenv 
python3.5 -m venv venv 
. ./venv/bin/activate 
python -c 'import ctypes' # throws no errors as opposed to before 

正确的解决方案,你不依赖于第三方的PPA将升级用较新的Python版本的操作系统版本: )

4

尝试销毁并重新创建虚拟环境。就我而言,我在安装依赖关系/次要升级之前创建了虚拟环境,即使虚拟环境对新文件具有符号链接,也使用了较旧的次要版本解释程序的副本。