Eclipse using multiple Python interpreters with execnet

I use the execnet package to allow communication between Python scripts interpreted by different Python interpreters.

The following code (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)

works fine in the command line terminal, displaying the following output:

$ python3 test_execnet.py 
python: 0
python3: 0.333333333333

However, if I try to run the same code from the Eclipse IDE, I get the following error:

'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
  • PyDev Interpreter is configured for the project: python3
  • "Preferences / Translator - Python" Python Translators:
    • python (/ usr / bin / python)
    • python3 (/Library/Frameworks/Python.Framework/Versions/3.1/Resources/Python.app/Contents/MacOS/Python

EDIT:

I am writing code to show os.environas follows:

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 results:

FileMerge eclipse_output.txt vs. terminal_output.pdf.

?

+3
2

, pydev , , / ( http://github.com/aptana/Pydev/blob/master/plugins/org.python.pydev/pysrc/pydev_sitecustomize/sitecustomize.py). , execnet.

"del os.environ ['PYTHONPATH" ] , execnet.makegateway, , , .

,

+4
'import site' failed; use -v for traceback

, python . PYTHONHOME.

http://docs.python.org/using/cmdline.html#envvar-PYTHONHOME, , .

Edit:

env , , eclipse PYTHONPATH, python. , , eclipse python v2 PYTHONPATH, python v2. python v3, python v2...
Eclipse PYTHONPATH. , , , , , python.

+1

Source: https://habr.com/ru/post/1754649/


All Articles