简体   繁体   English

Python ctypes在virtualenv中导入错误

[英]Python ctypes import error in virtualenv

I get the following error when importing ctypes , but only inside my virtual environment (Python 3.4). 导入ctypes时出现以下错误,但仅在我的虚拟环境中(Python 3.4)。

>>> 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 freeze of the virtualenv: pip冻结了virtualenv:

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

How do I fix this? 我该如何解决? It works on the main python 3.4 interpreter... 它适用于主要的python 3.4解释器......

As eryksun described , the issue seems to be related to a known bug in the 3.4.* versions of Python. 正如eryksun所描述的 ,这个问题似乎与3.4。*版本的Python中的已知错误有关。 I managed to solve it in Ubuntu 14.04 by upgrading to Python 3.5 following this answer : 我设法在Ubuntu 14.04中通过升级到Python 3.5来解决这个问题

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

The proper solution where you don't depend on 3rd party PPAs would be to upgrade to an OS version with a newer Python version :) 您不依赖第三方PPA的正确解决方案是升级到具有较新Python版本的操作系统版本:)

Try destroying and recreating your virtual environment. 尝试销毁并重新创建虚拟环境。 In my case, I had created the virtual environment before installing dependancies/minor upgrade and even though the virtual env had symlinks to the newer files, a copy of the older minor version interpreter was used. 在我的情况下,我在安装dependancies / minor升级之前创建了虚拟环境,即使虚拟环境对新文件有符号链接,也使用了旧版次要版本解释器的副本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM