OSX + Eclipse + PyDev-路径不正确 [英] OSX + Eclipse + PyDev - PATH isn't correct
问题描述
尝试使用Eclipse和PyDev(调试)在OSX上运行以下脚本:
Trying to get the following script working on OSX using Eclipse and PyDev (Debug):
#------------------------------------------------------
import os, subprocess
from os.path import join as join_path
def cmd(command):
print('$ ' + command)
process = subprocess.Popen(command, shell=True, executable="/bin/bash", stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return process.communicate() + (process.returncode,)
stdout, stderr, error_code = cmd('echo $PATH')
print(stdout, stderr, error_code)
stdout, stderr, error_code = cmd('echo $PYTHONPATH')
print(stdout, stderr, error_code)
stdout, stderr, error_code = cmd('which python')
print(stdout, stderr, error_code)
stdout, stderr, error_code = cmd('which apt-get')
print(stdout, stderr, error_code)
#------------------------------------------------------
但是$ PATH不是我在.bashrc或.profile中设置的,而且我无法运行apt-get,它位于sw/bin中.看来我的$ PATH在运行subprocess.Popen时被覆盖或设置不正确.
but $PATH is not what I have set in .bashrc or .profile, and I cannot run apt-get, which is in sw/bin. It seems that my $PATH is getting overwritten or not set correctly when running subprocess.Popen.
这是上面脚本的输出:
$ echo $PATH
('/usr/bin:/bin:/usr/sbin:/sbin\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\n', '', 0)
$ which python
('/usr/bin/python\n', '', 0)
$ which apt-get
> ('', '', 1)
推荐答案
PyDev可能独立于bash配置文件中的设置来设置$ PATH.
PyDev probably sets up $PATH independent of the settings in your bash configuration files.
我建议您之一:
从具有正确PATH设置的bash外壳启动PyDev(我假设Eclipse将从该外壳继承环境).
Start PyDev from a bash shell that has the correct PATH settings (I assume Eclipse will the inherit the environment from the shell).
或
在Eclipse中明确配置PATH(我不知道如何执行此操作的详细信息,请在文档中搜索环境变量").
Explicitly configure PATH within Eclipse (I don't know the details on how to do that, search the docs for "environment variables").
这篇关于OSX + Eclipse + PyDev-路径不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!