让 PyDev 在 OS X Lion 下的 Eclipse 上识别正确的 Python 解释器

发布于 2025-01-02 04:42:23 字数 776 浏览 3 评论 0原文

我在运行 OSX Lion 的 mac 上安装了两个版本的 python。第一个是 OSX 附带的默认 python 版本,位于 /usr/bin/python 中。我想使用的版本是我从 python.org 下载的版本,安装在 /Library/Frameworks/Python.framework/Versions/2.7/bin/python 中。我想使用 Eclipse 和 PyDev 使用 python.org 版本作为解释器。因此,在 Eclipse 中,我进入首选项并将 /Library/Frameworks/Python.framework/Versions/2.7/bin/python 中安装的版本设置为解释器。

在终端窗口中,如果我输入: $ which python

我得到“/Library/Frameworks/Python.framework/Versions/2.7/bin/python”,因为我相应地设置了 $PATH(修改 .bash_profile 以永久这样做),

但是如果我在 Eclipse 中运行以下简单脚本:

import os
os.system("which python")

脚本的输出是“/usr/bin/python”

我按照其他类似帖子的建议尝试过:

  1. 尝试删除并重新添加解释器位置
  2. 尝试将 /Library/.../package-sites 添加到PYTHONPATH

为什么 Eclipse 不使用我明确告诉它使用的解释器?任何有关此问题的帮助将不胜感激!

I have two versions of python installed on my mac running OSX Lion. The first is the default python version that ships with OSX and is found in /usr/bin/python. The version I want to use is the version I downloaded from python.org, and that is installed in /Library/Frameworks/Python.framework/Versions/2.7/bin/python. I want to use Eclipse and PyDev using the python.org version as the interpreter. So, in Eclipse, I go to preferences and set the version installed in /Library/Frameworks/Python.framework/Versions/2.7/bin/python to be the interpreter.

in a terminal window, if I type:
$ which python

I get "/Library/Frameworks/Python.framework/Versions/2.7/bin/python" because I set my $PATH accordingly (modified .bash_profile to permanently do so)

but if I run the following simple script in Eclipse:

import os
os.system("which python")

the script's output is "/usr/bin/python"

Things I have tried as suggested by other similar posts:

  1. tried removing and re-adding the interpreter location
  2. tried adding the /Library/.../package-sites to PYTHONPATH

Why isn't eclipse using the interpreter I explicitly tell it to use? Any help with this issue will be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

双马尾 2025-01-09 04:42:23

问题是 os.system('which python') 将搜索路径中的 python,而不是您当前正在运行的 python(因此,其输出是正确的)。

您想要使用/检查的是sys.executable(此属性将指向您当前正在运行的可执行文件)。

至于wxPython问题,你遇到了什么错误? (可能是 stackoverflow 思想中的另一个问题)。

The problem is that os.system('which python') will search for the python in the path, not the one where you're currently running (so, its output is correct).

What you want to use/check instead is sys.executable (this attribute will point to your currently running executable).

As for the wxPython issue, which error are you having? (probably another question in stackoverflow thought).

任谁 2025-01-09 04:42:23

我认为 Eclipse 正在运行正确的 python。在您的代码中,当在 eclipse which python 下运行时,找不到正在运行的 python。尝试

import sys
print sys.version

这里的问题是,从 desktop/dock/folder 运行 GUI 应用程序不会加载您的 .bash_profile,因此 which python 不会加载找到您对 PATH 的更改。要更改 GUI 应用程序的路径,您需要编辑 ~/.MacOSX/environment.plist

I think Eclipse is running the correct python. In your code when running under eclipse which python does not find the python running. Try

import sys
print sys.version

The issue here is that running a GUI app from the desktop/dock/folder does not load your .bash_profile and so which python does not find your change to the PATH. To change your path for GUI apps you need to edit ~/.MacOSX/environment.plist

晨曦÷微暖 2025-01-09 04:42:23

我同意马克的观点。 sys.version 将是 eclipse 用于运行代码的版本。 os.system("which python") 将是在 Eclipse 运行代码时转发的 PATH 中找到的 python。也许如果您使用 PATH 调整,您也应该设置环境变量以便在 Eclipse 中运行代码。

I agree with Mark here. sys.version will be what eclipse uses to run your code. os.system("which python") will be python found in PATH that eclipse forwarded when running your code. Perhaps if you use PATH tweaks you should set environment variables for running code in Eclipse too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文