[英]Can't import modules in python without sudo - ubuntu 12.04
I feel like this is a new issue since I upgraded to ubuntu 12.04. 自从我升级到ubuntu 12.04以来,我觉得这是一个新问题。
Now, if I enter the interactive shell and import a standard module like urllib2
, I get the following error: 现在,如果我进入交互式外壳程序并导入
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
>>>
If I run sudo before entering the interactive shell, everything is fine, it imports without throwing a fit. 如果我在进入交互式shell之前运行sudo,那么一切都很好,它会导入而不会抛出异常。
I don't want to just chmod 755 my entire /usr/lib/python2.7 directory, so what can I do to make things run more smoothly in a more sensible way? 我不想只对整个/usr/lib/python2.7目录进行chmod 755修改,那么我该怎么做才能使事情以更明智的方式更平稳地运行呢?
Use a Virtual Machine. 使用虚拟机。 That will give you a clean environment unhampered by past installs.
这将为您提供一个干净的环境,不受以前的安装的影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.