简体   繁体   English

如何停止将Mac OS X上的Python安装放到主目录中?

[英]How do I stop Python install on Mac OS X from putting things in my home directory?

I'm trying to install Python from source on my Mac. 我正在尝试从Mac上的源代码安装Python。 (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. (OS X 10.6.2,Python-2.6.5.tar.bz2)我之前做过,很容易,但是由于某种原因,这次在./configuremakesudo make install将事情放了一些。东西放在我的主目录中,而不是我期望的/ usr / local / ...中。 The .py files are okay, but not the .so files... .py文件可以,但.so文件不可以...

RobsMac Python-2.6.5 $ sudo make install RobsMac Python-2.6.5 $ sudo make安装
[...] [...]
/usr/bin/install -c -m 644 ./Lib/anydbm.py /usr/local/lib/python2.6 / 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/ast.py /usr/local/lib/python2.6
/usr/bin/install -c -m 644 ./Lib/asynchat.py /usr/local/lib/python2.6 / usr / bin / install -c -m 644 ./Lib/asynchat.py /usr/local/lib/python2.6
[...] [...]
running build_scripts 运行build_scripts
running install_lib 运行install_lib
creating /Users/rob/Library/Python 创建/ Users / rob / Library / Python
creating /Users/rob/Library/Python/2.6 创建/Users/rob/Library/Python/2.6
creating /Users/rob/Library/Python/2.6/site-packages 创建/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 复制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 复制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 复制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. 稍后,这将导致需要这些.so文件的导入失败。 For example... 例如...

RobsMac Python-2.6.5 $ python RobsMac Python-2.6.5 $蟒蛇
Python 2.6.5 (r265:79063, Apr 28 2010, 13:40:18) Python 2.6.5(r265:79063,2010年4月28日,13:40:18)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin 达尔文[GCC 4.2.1(Apple Inc. build 5646)(dot 1)]
Type "help", "copyright", "credits" or "license" for more information. 键入“帮助”,“版权”,“信用”或“许可证”以获取更多信息。
>>> import zlib >>>导入zlib
Traceback (most recent call last): 追溯(最近一次通话):
File "", line 1, in 文件“”,第1行,位于
ImportError: No module named zlib ImportError:没有名为zlib的模块

Any ideas what is wrong? 任何想法有什么问题吗?

thanks, Rob 谢谢,罗布

Doh. h I've answered my own question. 我已经回答了我自己的问题。 Recently I created a ~/.pydistutils.cfg file, for some stupid reason. 最近,出于某些愚蠢的原因,我创建了一个〜/ .pydistutils.cfg文件。 I forgot to delete that file. 我忘了删除该文件。 It's contents were: 它的内容是:

[install] [安装]
install_lib = ~/Library/Python/$py_version_short/site-packages install_lib =〜/ Library / Python / $ py_version_short / site-packages
install_scripts = ~/bin install_scripts =〜/ bin

make install calls setup.py , and this file was overriding the normal setup.py behavior. make install调用setup.py ,此文件已覆盖正常的setup.py行为。

Rob

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. 通常,在系统上已经可以使用Python(或直接从源代码直接获取)时,或者当有软件包管理器为您安装Python时,并不是一个好主意。 I strongly advise you against installing Python manually... Mac OS X 10.6 Snow Leopard comes with Python 2.6 out of the box; 我强烈建议您不要手动安装Python。Mac OS X 10.6 Snow Leopard随附了python 2.6。 if you want a newer version of Python 2.6, then you should install MacPorts, and use: 如果您想要更新版本的Python 2.6,则应安装MacPorts,并使用:

sudo port install python26 python_select

You can then use the python_select to toggle between the system's version and MacPort's version. 然后,您可以使用python_select在系统版本和MacPort版本之间进行切换。

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. 但是,如果确定要从源代码手动安装,则可以执行“ make distclean”(或再次分别解压缩代码),然后运行“ ./configure --help”以获取完整的列表。配置选项。 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". 在Mac OS X上,它可能默认为/ usr / local以外的其他名称,在这种情况下,您可以通过调用“ ./configure --prefix = / usr / local”来强制将其安装在该位置。

Have you checked the parameters or variables make expects? 您是否检查了期望的参数或变量? There probably is a make variable you can use to override that behavior. 可能有一个make变量,可以用来覆盖该行为。 In any case, have you tried MacPorts ? 无论如何,您是否尝试过MacPorts It may be a better solution to what you are trying to accomplish. 它可能是您要完成的目标的更好解决方案。

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

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