如何阻止 Mac OS X 上的 Python 安装将内容放入我的主目录中?
我正在尝试在 Mac 上从源代码安装 Python。 (OS X 10.6.2,Python-2.6.5.tar.bz2)我以前做过这个,而且很简单,但由于某种原因,这次在 ./configure
和 make
,sudo make install
将一些东西放在我的主目录中,而不是我期望的 /usr/local/... 中。 .py 文件没问题,但 .so 文件不行...
RobsMac Python-2.6.5 $ sudo make install
[...]
/usr/bin/install -c -m 644 ./Lib/anydbm.py /usr/local/lib/python2.6
/usr/bin/install -c -m 644 ./Lib/ast.py /usr/local/lib/python2.6
/usr/bin/install -c -m 644 ./Lib/asynchat.py /usr/local/lib/python2.6
[...]
运行 build_scripts
运行 install_lib
创建 /Users/rob/Library/Python
创建 /Users/rob/Library/Python/2.6
创建 /Users/rob/Library/Python/2.6/site-packages
复制 build/lib.macosx-10.4-x86_64-2.6/_AE.so -> /用户/抢/图书馆/ Python/2.6/site-packages
复制 build/lib.macosx-10.4-x86_64-2.6/_AH.so -> /用户/抢/图书馆/ Python/2.6/site-packages
复制 build/lib.macosx-10.4-x86_64-2.6/_App.so -> /用户/抢/图书馆/ Python/2.6/site-packages
[...]
随后,这会导致需要这些 .so 文件的导入失败。为了 例如...
RobsMac Python-2.6.5 $ python
Python 2.6.5(r265:79063,2010 年 4 月 28 日,13:40:18)
达尔文上的 [GCC 4.2.1(Apple Inc. build 5646)(点 1)]
输入“帮助”、“版权”、“制作人员”或“许可证”以获取更多信息。
>>>>>导入 zlib
回溯(最近一次调用最后一次):
文件“”,第 1 行,位于
ImportError:没有名为 zlib 的模块
有什么想法是错误的吗?
谢谢, 抢
I'm trying to install Python from source on my Mac. (OS X 10.6.2, Python-2.6.5.tar.bz2) I've done this before and it was easy, but for some reason, this time after ./configure
, and make
, the sudo make install
puts things some things in my home directory instead of in /usr/local/... where I expect. The .py files are okay, but not the .so files...
RobsMac Python-2.6.5 $ sudo make install
[...]
/usr/bin/install -c -m 644 ./Lib/anydbm.py /usr/local/lib/python2.6
/usr/bin/install -c -m 644 ./Lib/ast.py /usr/local/lib/python2.6
/usr/bin/install -c -m 644 ./Lib/asynchat.py /usr/local/lib/python2.6
[...]
running build_scripts
running install_lib
creating /Users/rob/Library/Python
creating /Users/rob/Library/Python/2.6
creating /Users/rob/Library/Python/2.6/site-packages
copying build/lib.macosx-10.4-x86_64-2.6/_AE.so -> /Users/rob/Library/
Python/2.6/site-packages
copying build/lib.macosx-10.4-x86_64-2.6/_AH.so -> /Users/rob/Library/
Python/2.6/site-packages
copying build/lib.macosx-10.4-x86_64-2.6/_App.so -> /Users/rob/Library/
Python/2.6/site-packages
[...]
Later, this causes imports that require those .so files to fail. For
example...
RobsMac Python-2.6.5 $ python
Python 2.6.5 (r265:79063, Apr 28 2010, 13:40:18)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zlib
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named zlib
Any ideas what is wrong?
thanks,
Rob
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
哦。我已经回答了我自己的问题。最近,由于某些愚蠢的原因,我创建了一个 ~/.pydistutils.cfg 文件。我忘记删除那个文件了。其内容是:
[安装]
install_lib = ~/Library/Python/$py_version_short/site-packages
install_scripts = ~/bin
make install
调用setup.py
,并且此文件覆盖了正常的setup.py
行为。抢
Doh. I've answered my own question. Recently I created a ~/.pydistutils.cfg file, for some stupid reason. I forgot to delete that file. It's contents were:
[install]
install_lib = ~/Library/Python/$py_version_short/site-packages
install_scripts = ~/bin
make install
callssetup.py
, and this file was overriding the normalsetup.py
behavior.Rob
一般来说,当你的系统上已经有Python(或直接从源代码获取的任何东西)或者有包管理器可以为你安装Python时,安装它并不是一个好主意。我强烈建议您不要手动安装 Python...Mac OS X 10.6 Snow Leopard 附带了开箱即用的 Python 2.6;如果您想要较新版本的 Python 2.6,那么您应该安装 MacPorts,并使用:
然后您可以使用
python_select
在系统版本和 MacPort 版本之间切换。不过,如果您决定从源代码手动安装,则方法是运行“make distclean”(或再次单独解压代码),然后运行“./configure --help”以获得完整的列表配置选项。在 Mac OS X 上,它可能默认为 /usr/local 以外的其他位置,在这种情况下,您可以通过使用“./configure --prefix=/usr/local”调用配置来强制将其安装在该位置。
In general, installing Python (or anything directly from the source) when it is already available on your system or when there are package managers that will install it for you, is not a very good idea. I strongly advise you against installing Python manually... Mac OS X 10.6 Snow Leopard comes with Python 2.6 out of the box; if you want a newer version of Python 2.6, then you should install MacPorts, and use:
You can then use the
python_select
to toggle between the system's version and MacPort's version.If you are determined to install manually from the source, though, the way to do it would be to run "make distclean" (or untar the code separately again), then run "./configure --help" for a full list of configuration options. It is possible that on Mac OS X, it defaults to something other than /usr/local, in which case you could force it to install in that location by invoking configure with "./configure --prefix=/usr/local".
您检查过 make 期望的参数或变量吗?您可能可以使用一个 make 变量来覆盖该行为。无论如何,您尝试过 MacPorts 吗?对于您想要完成的任务来说,这可能是一个更好的解决方案。
Have you checked the parameters or variables make expects? There probably is a make variable you can use to override that behavior. In any case, have you tried MacPorts? It may be a better solution to what you are trying to accomplish.