简体   繁体   English

Eclipse使用多个Python解释器和execnet

[英]Eclipse using multiple Python interpreters with execnet

I'm using the execnet package to allow communication between Python scripts interpreted by different Python interpreters. 我正在使用execnet包来允许不同Python解释器解释的Python脚本之间的通信。

The following code (test_execnet.py): 以下代码(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)

Runs perfectly in the command-line Terminal, showing the following output: 在命令行终端中完美运行,显示以下输出:

$ python3 test_execnet.py 
python: 0
python3: 0.333333333333

However, if I try to run the same code from within the Eclipse IDE, I get the following error: 但是,如果我尝试从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

NOTE: 注意:

  • Eclipse Version: 3.6.0 Eclipse版本:3.6.0
  • PyDev Interpreter configured for the project: python3 为项目配置的PyDev Interpreter:python3
  • "Preferences/Interpreter - Python"'s Python Interpreters: “偏好/解释器 - Python”的Python解释器:
    • python (/usr/bin/python) python(/ usr / bin / python)
    • python3 (/Library/Frameworks/Python.Framework/Versions/3.1/Resources/Python.app/Contents/MacOS/Python python3(/Library/Frameworks/Python.Framework/Versions/3.1/Resources/Python.app/Contents/MacOS/Python

EDIT: 编辑:

I write a code to show the os.environ like this: 我写了一个代码来显示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)

I got the following outputs: 我得到以下输出:

A FileMerge comparison of the files can be found at eclipse_output.txt vs. terminal_output.pdf . 可以在eclipse_output.txt与terminal_output.pdf中找到文件的FileMerge比较。

Any hints? 任何提示? Thanks 谢谢

seems like pydev does site-customizations and particularly modifies things for interactive/console usage (judging from a very quick skim of http://github.com/aptana/Pydev/blob/master/plugins/org.python.pydev/pysrc/pydev_sitecustomize/sitecustomize.py ). 似乎pydev做了网站自定义,特别修改了交互/控制台使用的东西(从http://github.com/aptana/Pydev/blob/master/plugins/org.python.pydev/pysrc/的快速浏览中判断pydev_sitecustomize / sitecustomize.py )。 This is not useful or fitting for execnet-mediated processes. 这对execnet介导的过程没有用或不合适。

You could try to "del os.environ['PYTHONPATH']" before you invoke execnet.makegateway, or, to be more careful, just delete the sitecustomize part of it. 您可以在调用execnet.makegateway之前尝试“del os.environ ['PYTHONPATH']”,或者,为了更加小心,只需删除sitecustomize部分。

hth, holger 霍尔格

'import site' failed; use -v for traceback

I have seen that when python was unable to find its landmark. 我已经看到当python无法找到它的里程碑时。 Which that indicates there is a PYTHONHOME problem. 这表明存在PYTHONHOME问题。

Check out http://docs.python.org/using/cmdline.html#envvar-PYTHONHOME maybe eclipse is screwing your environment up. 查看http://docs.python.org/using/cmdline.html#envvar-PYTHONHOME也许eclipse正在搞砸你的环境。

Edit: 编辑:

Looked at your env dumps, looks like eclipse is definitely messing with PYTHONPATH, which will cause your child python processes to not work correctly. 看看你的env转储,看起来eclipse肯定会搞乱PYTHONPATH,这会导致你的孩子python进程无法正常工作。 Basically what you have going on here is eclipse starts a python v2 instance with a PYTHONPATH pointing to the python v2 directories. 基本上你在这里发生的是eclipse启动一个python v2实例,其中PYTHONPATH指向python v2目录。 Then you spawn a python v3 process which tries to load its landmark from the python v2 directories... 然后你产生一个python v3进程,试图从python v2目录加载它的地标...
You need to find a way to have eclipse not mess with the PYTHONPATH. 你需要找到一种让日食不会与PYTHONPATH混淆的方法。 I am not sure what eclipse is trying to do by doing that, but it is certainly no friend when you want to spawn new python processes. 我不确定eclipse正在尝试做什么,但是当你想要生成新的python进程时它肯定不是朋友。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM