升级到 14.04 后 Python 无法正确导入

升级到 14.04 后 Python 无法正确导入

问题描述:

我无法从带有 c 扩展名的标准库中导入导入模块.这是在我从 12.04 升级到 Ubuntu 14.04 之后发生的.我试过重新安装 python、python-dev,但它没有帮助.我注意到其他人也有类似的帖子,但他们都使用 virtualenv,而我并没有全部使用.

I can't import import modules from the standard library with c extensions. This happened after I upgraded to Ubuntu 14.04 from 12.04. I've tried reinstall python, python-dev, but its not helping. I've noticed other people with similar posts, but they all use virtualenv, whereas I am not using it all.

Python 2.7.3 (default, Aug  1 2012, 05:16:07) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle, email, json, readline, socket, turtle
>>> import ctypes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/ctypes/__init__.py", line 10, in <module>
    from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes
>>> import io
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: No module named _io
>>> import datetime
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named datetime

which -a python 我们看到在 /usr/local/lib/python 中有两个 python 2 的安装/usr/bin/python/ 因此删除 /usr/local/lib/python 将对问题进行排序.

from which -a python we see there are two installs of python 2 in /usr/local/lib/python and /usr/bin/python/ so removing /usr/local/lib/python will sort the issue.