尝试使用Eclipse和PyDev让以下脚本在OSX上运行(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在运行时被覆盖或设置不正确子流程.Popen. 在
以下是我从上述脚本中得到的输出:
^{pr2}$
PyDev可能独立于bash配置文件中的设置来设置$PATH。在
我建议你:
从具有正确路径设置的bashshell启动PyDev(我假设Eclipse将从shell继承环境)。在
或者
在Eclipse中显式地配置PATH(我不知道如何做的细节,请在文档中搜索“environment variables”)。在
好吧,找到了一个简单的问题解决方案。在这里找到了一些好的注释:Environment variables in Mac OS X
从一个终端启动Eclipse—尽管很烦人—工作很好。从我的终端类型/Applications/eclipse/eclipse和我的环境变量中获取:
您可以在以下位置找到内部PyDev首选项:
在窗口:首选项:PyDev:解释器-Python
这包括系统PYTHONPATH。在
相关问题 更多 >
编程相关推荐