OSX + Eclipse + PyDev - PATH isn't correct

你离开我真会死。 提交于 2019-12-07 07:57:26

PyDev probably sets up $PATH independent of the settings in your bash configuration files.

I suggest you either:

Start PyDev from a bash shell that has the correct PATH settings (I assume Eclipse will the inherit the environment from the shell).

or

Explicitly configure PATH within Eclipse (I don't know the details on how to do that, search the docs for "environment variables").

dixkin

OK, figured out a simple solution to the problem. Found a number of good notes here: Environment variables in Mac OS X

Starting Eclipse from a terminal - though annoying - works fine. From my terminal type /Applications/eclipse/eclipse and my environment variables get picked up:

$ echo $PATH ('/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/mysql/bin:sw/bin:/usr/local/mysql/bin:sw/bin:/usr/X11R6/bin\n', '', 0) $ echo $PYTHONPATH ('/Applications/eclipse/plugins/org.python.pydev_2.6.0.2012062515/pysrc/pydev_sitecustomize:/Users/bryancdickson/Development/Lootsie/_repos/ap/ap:/Users/bryancdickson/Development/Lootsie/_repos/ap/ap/ap:/sw/bin:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages:/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload:/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC:/Library/Python/2.7/site-packages:/sw/bin\n', '', 0) $ which python ('/usr/bin/python\n', '', 0) $ which apt-get ('/sw/bin/apt-get\n', '', 0)

You can find the internal PyDev preferences under:

Window:Preferences:PyDev:Interpreter - Python

This includes the system PYTHONPATH.

Launch Eclipse from the Terminal worked for me with Eclipse 4.3, but it doesn't work anymore with Eclise 4.5 (Mars)

The problem is that the PATH variable is not correctly set when calling subprocess.Popen

A workaround is to add the real PATH into the environment using os.environ

import os
os.environ['PATH'] = os.environ['PATH']+':'+os.getenv('PATH')

This works for me (I just had to add the variable PATH and its value in the Environment of the Python Interpreter, see the Preferences (Preferences -> PyDev -> Interpreters -> Python Interpreter -> Environment)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!