问题
I use Windows. I wrote a Python 3.1 script that my Mac-using friend would like to run, but we can't get Python 3.1 to work right on his Mac. I think the problem is that the Python 3.1 framework is not being installed. Here's exactly what what I did and why I think this is the problem.
I downloaded Python 3.1.2 from the Python download page (this file). I opened the file, then opened "Python.mpkg". I proceeded with the install wizard, and I made sure to check the box to install "Shell profile updater" during the wizard. I went to "/Applications/Python 3.1" and double-clicked "Update Shell Profile.command".
Next I selected the python script I wrote and selected "File", "Get Info" in the menu bar. Under "Open With" I selected "PythonLauncher" from "/Applications/Python 3.1". I then clicked the "Change All" button. Now I double-clicked my program to run it, but it was run by Python 2.5.1 instead of Python 3.1. (I'm sure of this, I wrote a program to "print(sys.version)".)
So now I tried to figure out why the "PythonLauncher" from "/Applications/Python 3.1" is using Python 2.5.1. I opened "PythonLauncher" and found that the interpreter for "Python Script" is "/usr/bin/pythonw". So I went to "/usr/bin/" and discovered that "pythonw" was an alias pointing to "/System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5". Obviously this should be version 3.1 instead. So I went to "/System/Library/Frameworks/Python.framework/Versions/" and discovered that the only sub-folders are "2.3" and "2.5". Where's 3.1?
回答1:
Take a look at PythonBrew. It made installing Python on my Mac a lot easier.
Also this might help:
Is there a Python Equivalent of Ruby's RVM?
回答2:
Python Launcher.app
is a somewhat neglected app; there have been some discussion about removing it all together because it could be somewhat of a security risk if someone downloads arbitrary Python scripts from the web. It can also be kind of hit or miss if you have multiple Python versions installed. And many people just run Python from a terminal window command line so they don't need Python Launcher.app
and that's probably the safest thing to do. To do so, you should first run the Update Shell Profile
command in /Applications/Python 3.1
which will ensure that the proper Python framework bin
directory is added to your shell path. Then you can just type:
$ python3 /path/to/script.py
That said, you can make Python Launcher
work by changing the interpreter path to:
/Library/Frameworks/Python.framework/Versions/3.1/bin/python3
but I discourage you from doing so.
Another better GUI option is to launch IDLE.app
and drag-and-drop files onto it in the dock or open them in its File menu.
回答3:
The versions in /System/Library/Frameworks/Python.framework/...
were put there as part of OS X. They should be left alone. (See this question.)
.dmg files downloaded from python.org install to /Library/Frameworks/Python.framework/...
. These are user-installed, so you can install/uninstall/move however you like. These installers also created symlinks in /usr/local/bin
.
You can add either /Library/.../3.1/bin
or /usr/local/bin
to your path in your shell if you want python3
to be on your path.
来源:https://stackoverflow.com/questions/4261429/install-python-3-1-on-mac-os-x-version-10-5-8