1
votes

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!

3

3 Answers

0
votes

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).

0
votes

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

0
votes

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.