Python virtualenv 中的 ctypes 导入错误

Python ctypes import error in virtualenv

我在导入 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

virtualenv 的 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 解释器...

作为, the issue seems to be related to a known bug in the 3.4.* versions of Python. I managed to solve it in Ubuntu 14.04 by upgrading to Python 3.5 following 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 的正确解决方案是升级到 OS 版本和较新的 Python 版本 :)

尝试破坏并重建您的虚拟环境。就我而言,我在安装 dependancies/minor 升级之前创建了虚拟环境,即使虚拟环境具有指向较新文件的符号链接,也使用了较旧的次要版本解释器的副本。