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

发布于 2024-10-04 05:48:56 字数 980 浏览 1 评论 0原文

我使用Windows。我编写了一个 Python 3.1 脚本,我使用 Mac 的朋友想要运行该脚本,但我们无法让 Python 3.1 在他的 Mac 上正常工作。我认为问题是没有安装Python 3.1框架。这正是我所做的以及为什么我认为这是问题所在。

我从Python下载页面下载了Python 3.1.2 (此文件)。我打开该文件,然后打开“Python.mpkg”。我继续执行安装向导,并确保在向导过程中选中安装“Shell 配置文件更新程序”的框。我转到“/Applications/Python 3.1”并双击“Update Shell Profile.command”。

接下来我选择了我编写的python脚本,并在菜单栏中选择了“文件”、“获取信息”。 在“打开方式”下,我从“/Applications/Python 3.1”中选择了“PythonLauncher”。然后我单击“更改全部”按钮。现在我双击我的程序来运行它,但它是由Python 2.5.1而不是Python 3.1运行的。 (我确信这一点,我编写了一个程序“print(sys.version)”。)

所以现在我试图弄清楚为什么“/Applications/Python 3.1”中的“PythonLauncher”使用Python 2.5.1。我打开“PythonLauncher”,发现“Python Script”的解释器是“/usr/bin/pythonw”。所以我去了“/usr/bin/”并发现“pythonw”是指向“/System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5”的别名。显然这应该是 3.1 版本。所以我去了“/System/Library/Frameworks/Python.framework/Versions/”,发现唯一的子文件夹是“2.3”和“2.5”。 3.1在哪里?

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?

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

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

发布评论

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

评论(3

叶落知秋 2024-10-11 05:48:56

看看 PythonBrew。它使得在我的 Mac 上安装 Python 变得更加容易。

这也可能有帮助:

Is there a Python Equivalent of Ruby's RVM?

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?

溺孤伤于心 2024-10-11 05:48:56

Python Launcher.app 是一个有点被忽视的应用程序;已经有一些关于将其全部删除的讨论,因为如果有人从网络下载任意 Python 脚本,可能会存在一定的安全风险。如果您安装了多个 Python 版本,它也可能会出现问题。许多人只是从终端窗口命令行运行 Python,因此他们不需要 Python Launcher.app,这可能是最安全的做法。为此,您应该首先在 /Applications/Python 3.1 中运行 Update Shell Profile 命令,这将确保正确的 Python 框架 bin 目录已添加到您的 shell 路径中。然后您只需输入:

$ python3 /path/to/script.py

也就是说,您可以通过将解释器路径更改为:

/Library/Frameworks/Python.framework/Versions/ 来使Python Launcher工作3.1/bin/python3

但我不鼓励你这样做。

另一个更好的 GUI 选项是启动 IDLE.app 并将文件拖放到 Dock 中或在其“文件”菜单中打开它们。

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.

你丑哭了我 2024-10-11 05:48:56

/System/Library/Frameworks/Python.framework/... 中的版本是作为 OS X 的一部分放置在那里的。它们应该单独保留。 (请参阅此问题。)

从<下载的.dmg文件a href="http://python.org" rel="nofollow noreferrer">python.org 安装到 /Library/Frameworks/Python.framework/...。这些是用户安装的,因此您可以根据需要安装/卸载/移动。这些安装程序还在 /usr/local/bin 中创建了符号链接。

如果您想要 python3/Library/.../3.1/bin/usr/local/bin 添加到 shell 中的路径中代码> 在您的道路上。

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.

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