没有sudo,无法在python中导入模块 - ubuntu 12.04

时间:2012-09-16 18:53:07

标签: python permissions ubuntu-12.04

自从我升级到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目录,那么我能做些什么来让事情以更合理的方式运行得更顺畅呢?

1 个答案:

答案 0 :(得分:0)

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