为什么Mac OS X中Python 2.7的命令行工具不在`/usr/local/bin`目录中?

2024-04-25 15:15:15 发布

您现在位置:Python中文网/ 问答频道 /正文

MacOSX的Python2.7安装程序磁盘映像(python-2.7-macosx10.5.dmg)声明:

The installer puts the applications in "Python 2.7" in your Applications folder, command-line tools in /usr/local/bin and the underlying machinery in /Library/Frameworks/Python.framework.

但是,在安装之后,/usr/local/bin/中没有Python 2.7文件。

  • 其他人也看到同样的行为吗?
  • 我假设解决方案只是创建与Python 2.6一样的/usr/local/bin等价的符号链接,或者我忽略了什么?

Tags: thein声明yourbinusrlocalinstaller
3条回答

Steven Majewski's comment声明“我认为我必须在安装程序中显式地选择该选项(“安装命令行工具”),这使我认为我忽略了安装程序中的某些内容。果然,我忽略了Customize选项。见下文。

Optional Customize Python Install http://img.skitch.com/20100716-ede8ausmtch9cb6g4mqp4hcm84.jpg

Select UNIX Command-Line Tools http://img.skitch.com/20100716-817rjbyikr8c4y88xkfj6qeg1p.jpg

11:54 jsmith@upsidedown find /usr -name python2.7
11:54 jsmith@upsidedown

是啊,真糟糕。

我将遵循Python2.6(在我的例子中是2.5)安装程序所做的模式,并创建符号链接(正如您所怀疑的那样)。模式不变,至少:

11:57 jsmith@upsidedown /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Python 2.7 (r27:82508, Jul  3 2010, 21:12:11) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

可能值得一份针对安装程序的错误报告。

org python installer for OS X是一个包含多个包的元包。您可以在安装过程中单击Customize按钮来查看包。/usr/local/bin中的符号链接由UNIX command-line tools包安装。对于2.7版本,默认情况下不再选择该包。您可以通过执行自定义安装并选择该软件包来安装它和符号链接;如果您已经安装了2.7,请仅选择该软件包。

编辑:也就是说,重要的是要认识到,使用OS X Python框架构建,仅仅在搜索路径中使用/usr/local/bin通常是不够的。原因是包中包含的python脚本默认安装在python目录的bin目录中,例如/Library/Frameworks/Python.framework/Versions/2.7/bin。几乎所有使用Distutils默认值或包装Distutils的安装工具(如easy_installDistributesetuptools)或pip)的情况都是如此。这就是为什么会有另一个安装程序包Shell profile updater,它在默认情况下被启用,并试图修改您的登录配置文件,将framework bin目录放在shell搜索路径PATH的前面。如果这样做了,调用python2.7就不需要/usr/local/bin中的符号链接。

相关问题 更多 >