简体   繁体   English

在Mac OS X版本10.5.8上安装Python 3.1

[英]Install Python 3.1 on Mac OS X version 10.5.8

I use Windows. 我使用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. 我编写了一个Python 3.1脚本,使用Mac的朋友想运行它,但是我们无法让Python 3.1在他的Mac上正常工作。 I think the problem is that the Python 3.1 framework is not being installed. 我认为问题在于未安装Python 3.1框架。 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 ). 我从Python下载页面( 此文件 )下载了Python 3.1.2。 I opened the file, then opened "Python.mpkg". 我打开文件,然后打开“ Python.mpkg”。 I proceeded with the install wizard, and I made sure to check the box to install "Shell profile updater" during the wizard. 我继续进行安装向导,并确保在向导期间选中用于安装“ Shell配置文件更新程序”的框。 I went to "/Applications/Python 3.1" and double-clicked "Update Shell Profile.command". 我转到“ / Applications / Python 3.1”并双击“ Update Shell Profile.command”。

Next I selected the python script I wrote and selected "File", "Get Info" in the menu bar. 接下来,我选择了编写的python脚本,并在菜单栏中选择了“文件”,“获取信息”。 Under "Open With" I selected "PythonLauncher" from "/Applications/Python 3.1". 在“打开方式”下,我从“ / Applications / Python 3.1”中选择了“ PythonLauncher”。 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. 现在,我双击我的程序来运行它,但是它是由Python 2.5.1而不是Python 3.1运行的。 (I'm sure of this, I wrote a program to "print(sys.version)".) (对此,我很确定,我编写了一个程序“ print(sys.version)”。)

So now I tried to figure out why the "PythonLauncher" from "/Applications/Python 3.1" is using Python 2.5.1. 所以现在我试图弄清楚为什么“ / Applications / Python 3.1”中的“ PythonLauncher”使用的是Python 2.5.1。 I opened "PythonLauncher" and found that the interpreter for "Python Script" is "/usr/bin/pythonw". 我打开“ PythonLauncher”,发现“ Python脚本”的解释器是“ / 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". 因此,我转到“ / usr / bin /”,发现“ pythonw”是指向“ /System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5”的别名。 Obviously this should be version 3.1 instead. 显然,这应该是3.1版。 So I went to "/System/Library/Frameworks/Python.framework/Versions/" and discovered that the only sub-folders are "2.3" and "2.5". 因此,我转到“ /System/Library/Frameworks/Python.framework/Versions/”,发现仅有的子文件夹为“ 2.3”和“ 2.5”。 Where's 3.1? 3.1在哪里?

Take a look at PythonBrew . 看一下PythonBrew It made installing Python on my Mac a lot easier. 它使在Mac上安装Python变得容易得多。

Also this might help: 另外,这可能会有所帮助:

Is there a Python Equivalent of Ruby's RVM? 有与Ruby的RVM等效的Python吗?

Python Launcher.app is a somewhat neglected app; Python Launcher.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. 关于将其全部删除有一些讨论,因为如果有人从网络上下载任意Python脚本,可能会带来一定的安全风险。 It can also be kind of hit or miss if you have multiple Python versions installed. 如果您安装了多个Python版本,它也可能会大打出手。 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. 而且许多人只是从终端窗口命令行运行Python,因此他们不需要Python Launcher.app ,这可能是最安全的做法。 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. 为此,您首先应该在/Applications/Python 3.1运行Update Shell Profile命令,这将确保将正确的Python框架bin目录添加到您的Shell路径中。 Then you can just type: 然后,您可以输入:

$ python3 /path/to/script.py

That said, you can make Python Launcher work by changing the interpreter path to: 也就是说,您可以通过将解释器路径更改为以下方式使Python Launcher正常工作:

/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. 另一个更好的GUI选项是启动IDLE.app并将文件拖放到扩展坞中,或在其“文件”菜单中打开它们。

The versions in /System/Library/Frameworks/Python.framework/... were put there as part of OS X. They should be left alone. /System/Library/Frameworks/Python.framework/...中的版本作为OS X的一部分放置在/System/Library/Frameworks/Python.framework/... 。应单独放置。 (See this question .) (请参阅此问题 。)

.dmg files downloaded from python.org install to /Library/Frameworks/Python.framework/... . python.org下载的.dmg文件安装到/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 . 这些安装程序还在/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. 如果希望python3在路径中,则可以将/Library/.../3.1/bin/usr/local/bin到外壳中的路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM