当我尝试在 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似乎有一个相关的问题,因为Ubuntu 12.04升级但我的环境是OSX。