我正在使用execnet package來允許不同Python解釋器解釋的Python腳本之間的通信。使用execnet與多個Python解釋器的Eclipse
以下代碼(test_execnet.py):
import execnet
for python_version in ('python', 'python3'):
try:
gw = execnet.makegateway("popen//python="+python_version)
ch = gw.remote_exec('channel.send(1/3)')
res = ch.receive()
print(python_version, ': ', res, sep ="")
except:
print('problems with ', python_version)
奔跑完全在命令行終端,示出了下面的輸出:
$ python3 test_execnet.py
python: 0
python3: 0.333333333333
但是,如果我嘗試運行相同代碼從Eclipse IDE中,我得到以下錯誤:
'import site' failed; use -v for traceback
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 4, in <module>
File "<string>", line 2, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/execnet/gateway_base.py", line 8, in <module>
import sys, os, weakref
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/os.py", line 380, in <module>
from _abcoll import MutableMapping # Can't use collections (bootstrap)
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/_abcoll.py", line 54
class Hashable(metaclass=ABCMeta):
^
SyntaxError: invalid syntax
problems with python
problems with python3
注意:
- Eclipse版本:3.6.0
- PyDev的解釋爲該項目配置:python3
- 「首選項/口譯 - 蟒」 的Python解釋:
- 蟒蛇(在/ usr/bin中/蟒)
- python3(/Library/Frameworks/Python.Framework/Versions/3.1/Resources/Python.app/Contents/MacOS/Python
編輯:
我寫的代碼,以顯示os.environ
這樣的:
for python_version in ('python', 'python3'):
try:
import os
for item in os.environ:
print(item, '= ', os.environ[item])
except:
print('problems with ', python_version)
我得到了以下成果:
文件的FileMerge比較可以在eclipse_output.txt vs. terminal_output.pdf找到。
任何提示? 感謝
謝謝hpk42。這是關鍵。通過執行你所說的我可以從Eclipse IDE內部運行代碼。爲了確保在Eclipse IDE/Terminal中執行,我在'execnet.makegateway'調用之前放置了以下代碼:''import os if(os.environ.get('PYTHONPATH',None)): del os.environ ['PYTHONPATH']'' – 2010-07-15 12:24:14