2

自从我升级到 ubuntu 12.04 后,我觉得这是一个新问题。

现在,如果我进入交互式 shell 并导入一个标准模块,如urllib2,我会收到以下错误:

$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/urllib2.py", line 94, in <module>
   import httplib
  File "/usr/lib/python2.7/httplib.py", line 79, in <module>
   import mimetools
  File "/usr/lib/python2.7/mimetools.py", line 6, in <module>
   import tempfile
  File "/usr/lib/python2.7/tempfile.py", line 34, in <module>
   from random import Random as _Random
  File "/usr/lib/python2.7/random.py", line 47, in <module>
   from os import urandom as _urandom
  ImportError: cannot import name urandom
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 66, in     apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 1, in <module>
    from apport.report import Report
  File "/usr/lib/python2.7/dist-packages/apport/report.py", line 12, in <module>
    import subprocess, tempfile, os.path, urllib, re, pwd, grp, os
  File "/usr/lib/python2.7/tempfile.py", line 34, in <module>
    from random import Random as _Random
  File "/usr/lib/python2.7/random.py", line 47, in <module>
    from os import urandom as _urandom
    ImportError: cannot import name urandom

Original exception was:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/urllib2.py", line 94, in <module>
    import httplib
  File "/usr/lib/python2.7/httplib.py", line 79, in <module>
    import mimetools
  File "/usr/lib/python2.7/mimetools.py", line 6, in <module>
    import tempfile
  File "/usr/lib/python2.7/tempfile.py", line 34, in <module>
    from random import Random as _Random
   File "/usr/lib/python2.7/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
>>>

如果我在进入交互式 shell 之前运行 sudo ,一切都很好,它导入时不会出错。

我不想只 chmod 755 我的整个 /usr/lib/python2.7 目录,那么我该怎么做才能让事情以更明智的方式更顺利地运行呢?

4

1 回答 1

0

使用虚拟机。这将为您提供一个不受过去安装影响的干净环境。

于 2013-01-25T17:21:50.900 回答