當我試圖在Eclipse(的PyDev)運行該腳本如下:返回導入錯誤:無法導入名稱urandom的在Eclipse/PyDev的
import subprocess
subprocess.call("/usr/local/bin/mitmdump")
錯誤:
Traceback (most recent call last):
File "/usr/local/bin/mitmdump", line 19, in <module>
from libmproxy import proxy, dump, cmdline
File "/Library/Python/2.7/site-packages/libmproxy/proxy.py", line 22, in <module>
import shutil, tempfile, threading
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 34, in <module>
from random import Random as _Random
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
如果我運行相同的腳本從bash,它工作正常。是什麼賦予了?
$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call("/usr/local/bin/mitmdump")
127.0.0.1 GET http://google.com/
似乎有一個與Ubuntu Python ImportError cannot import urandom Since Ubuntu 12.04 upgrade相關的問題,但我的環境是OSX。
檢查您的PYTHONPATH。 – Daenyth
您是否在'virtualenv'下運行該項目? – drudru