OS X - 多个 python 版本、PATH 和 /usr/local
如果你安装了多个版本的python(我目前有默认的2.5,安装了3.0.1,现在安装了2.6.2),它会自动将东西放入/usr/local
,并且它还会调整路径包含 /Library/Frameworks/Python/Versions/theVersion/bin
,但是当 /usr/local
已经在 PATH 上并且所有已安装时,这有什么意义版本(默认的 2.5 除外,位于 /usr/bin
中)都在那里吗?我从 .bash_profile
的 PATH 中删除了 python 框架路径,但我仍然可以输入 "python -V" =>; “Python 2.5.1”
,“python2.6 -V”=> "Python 2.6.2"
,"python3 -V" => “Python 3.0.1”。只是想知道为什么它把它放在
/usr/local
中,并且还更改了 PATH。我做的好吗?谢谢。
另外,2.6 安装使其成为“当前”版本,.../Python.framework/Versions/Current
指向 2.6。,因此 /usr/ 中的简单“python”内容local/bin
指向 2.6,但这并不重要,因为 usr/bin
排在第一位,其中同名的东西指向 2.5 的东西。无论如何,2.5 是 leopard 附带的,我安装了 3.0.1 只是为了获得最新版本(有一个 dmg 文件),现在我安装了 2.6.2 以与 pygame 一起使用。
编辑:好的,这就是我的理解。例如,当您安装 Python 2.6.2 时: 一堆符号链接被添加到 /usr/local/bin
中,因此当有 #! /usr/local/bin/python
shebang 在 python 脚本中,它将运行,并且在 /Applications/Python 2.6
中,Python Launcher 被设置为运行 .py 文件的默认应用程序,它使用 /usr/local/bin/pythonw
,并创建 /Library/Frameworks/Python.framework/Versions/2.6/bin
并将其添加到路径的前面,所以 which python
将获取其中的 python,还有 #! /usr/bin/env python
shebang 将正确运行。
If you install multiple versions of python (I currently have the default 2.5, installed 3.0.1 and now installed 2.6.2), it automatically puts stuff in /usr/local
, and it also adjusts the path to include the /Library/Frameworks/Python/Versions/theVersion/bin
, but whats the point of that when /usr/local
is already on the PATH, and all installed versions (except the default 2.5, which is in /usr/bin
) are in there? I removed the python framework paths from my PATH in .bash_profile
, and I can still type "python -V" => "Python 2.5.1"
, "python2.6 -V" => "Python 2.6.2"
,"python3 -V" => "Python 3.0.1"
. Just wondering why it puts it in /usr/local
, and also changes the PATH. And is what I did fine? Thanks.
Also, the 2.6 installation made it the 'current' one, having .../Python.framework/Versions/Current
point to 2.6., So plain 'python' things in /usr/local/bin
point to 2.6, but it doesn't matter because usr/bin
comes first and things with the same name in there point to 2.5 stuff.. Anyway, 2.5 comes with leopard, I installed 3.0.1 just to have the latest version (that has a dmg file), and now I installed 2.6.2 for use with pygame.
EDIT: OK, here's how I understand it. When you install, say, Python 2.6.2:
A bunch of symlinks are added to /usr/local/bin
, so when there's a #! /usr/local/bin/python
shebang in a python script, it will run, and in /Applications/Python 2.6
, the Python Launcher is made default application to run .py files, which uses /usr/local/bin/pythonw
, and /Library/Frameworks/Python.framework/Versions/2.6/bin
is created and added to the front of the path, so which python
will get the python in there, and also #! /usr/bin/env python
shebang's will run correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有先验保证 /usr/local/bin 将保留在 PATH 上(特别是它不一定保留在 /usr/bin 的“前面”!-),因此安装程序确保特别需要的 / 是完全合理的Library/.../bin 目录确实进入了 PATH。另外, /Library/.../bin 可能有一些补充内容没有被符号链接到 /usr/local/bin 中,尽管我相信当前 Python 的 Mac 标准发行版并非如此。
如果您知道 /usr/local/bin 完全满足您安排路径的方式以及您将使用的可执行文件的确切集合,那么您可以删除 /Library/etc 目录当然,从你自己的道路开始。
There's no a priori guarantee that /usr/local/bin will stay on the PATH (especially it will not necessarily stay "in front of" /usr/bin!-), so it's perfectly reasonable for an installer to ensure the specifically needed /Library/.../bin directory does get on the PATH. Plus, it may be the case that the /Library/.../bin has supplementary stuff that doesn't get symlinked into /usr/local/bin, although I believe that's not currently the case with recent Mac standard distributions of Python.
If you know that the way you'll arrange your path, and the exact set of executables you'll be using, are entirely satisfied from /usr/local/bin, then it's quite OK for you to remove the /Library/etc directories from your own path, of course.
我刚刚在我的 Mac 上注意到/遇到了这个问题。我的机器上有 Python 2.5.4、2.6.2 和 3.1.1,并且正在寻找一种可以轻松地在它们之间随意更改的方法。就在那时,我注意到可执行文件的所有符号链接,我在“/usr/bin”和“/usr/local/bin”中找到了这些符号链接。我删除了所有非版本特定的符号链接,留下 python2.5、python2.6 等,并编写了一个 bash shell 脚本,我可以以 root 身份运行该脚本来更改我用来将路径定向到我选择的版本的符号链接
'/Library/Frameworks/Python.framework/Versions/Current'
删除符号链接的唯一坏处是,如果其他应用程序出于某种原因需要它们。我对为什么创建这些符号链接的看法与 Alex 的评估类似,安装程序试图涵盖所有基础。我的所有版本都已由安装程序安装,尽管我一直在尝试编译自己的版本以启用完整的 64 位支持,并且在编译和安装您自己的版本时,您可以选择在安装过程中不创建符号链接或修改 PATH安装。
I just noticed/encountered this issue on my Mac. I have Python 2.5.4, 2.6.2, and 3.1.1 on my machine, and was looking for a way to easily change between them at will. That is when I noticed all the symlinks for the executables, which I found in both '/usr/bin' and '/usr/local/bin'. I ripped all the non-version specific symlinks out, leaving python2.5, python2.6, etc, and wrote a bash shell script that I can run as root to change one symlink I use to direct the path to the version of my choice
'/Library/Frameworks/Python.framework/Versions/Current'
The only bad thing about ripping the symlinks out, is if some other application needed them for some reason. My opinion as to why these symlinks are created is similar to Alex's assessment, the installer is trying to cover all of the bases. All of my versions have been installed by an installer, though I've been trying to compile my own to enable full 64-bit support, and when compiling and installing your own you can choose to not have the symlinks created or the PATH modified during installation.