无法在Sublime Text2中设置Python版本 [英] Trouble setting Python version in Sublime Text2
问题描述
我无法在Sublime Text2中设置构建环境. 我正在使用Macports进行Python和软件包安装.
I'm having trouble setting the build environment in Sublime Text2. I'm using Macports for Python and package installation.
我的python.sublime-build文件如下所示:
My python.sublime-build file looks like this:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
我认为(通过搜索)我需要修改"cmd"行以指向Macports版本.有人成功做到了吗?
I think (from searching) that I need to modify the "cmd" line to point to the Macports version. Anyone done this successfully?
在Terminal中,一切都可以正常构建/运行,只有Sublime Text2的构建仍在获取系统版本.
From Terminal, everything builds/runs fine, it's only Sublime Text2's build that's grabbing the system version still.
其他信息:
which python
/opt/local/bin/python
感谢您的帮助.
推荐答案
您的Sublime Text 2环境不同于您的Shell环境; $PATH
变量可能没有指向相同的目录,并且选择了错误的可执行文件.
Your Sublime Text 2 environment is different from your shell environment; the $PATH
variable is probably not pointing to the same directories and the wrong executable is selected.
您可以通过以下几种方法解决此问题:
You have several options to work around that:
-
设置一个
"path"
选项,其中包括/opt/local/bin
需要为您的python
可执行文件使用绝对路径,因为Sublime Text 2与您的Shell使用的环境PATH变量不同.检查echo $PATH
并将其用作模板:
Set a
"path"
option that includes/opt/local/bin
need to use an absolute path for yourpython
executable, as Sublime Text 2 doesn't share the same environment PATH variable your shell uses. Inspectecho $PATH
and use that as a template:
{
"cmd": ["python", "-u", "$file"],
"path": "/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/Current/bin:/Users/yourloginname/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
这将使用/bin/bash
来运行命令,我认为该命令与您的终端具有相同的$PATH
设置.
That'll use /bin/bash
to run the command, which I think would have the same $PATH
setting as your terminal.
通过命令行运行命令,而不要设置"shell"
选项:
Run the command through the shell instead by setting the "shell"
option:
{
"cmd": ["python", "-u", "$file"],
"shell": true,
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
使用python命令的完整路径:
Use the full path for the python command:
{
"cmd": ["/opt/local/bin/python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
这篇关于无法在Sublime Text2中设置Python版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!