简体   繁体   English

选择用于鸡蛋安装的Python版本或安装站点软件包的并行版本

[英]Choose Python version for egg installation or install parallel versions of site-package

Via fink install I put the following Python version on my Mac OS X computer: 通过fink install我在Mac OS X计算机上放置了以下Python版本:

  • python2.3 , python2.3
  • python2.4 , python2.4
  • python2.5 , python2.5
  • python2.6 . python2.6

Further, python is alias for python2.6 on my system. 此外, python是我系统上python2.6别名。

  1. I want to install an egg , eg easy_install networkx-0.36-py2.5.egg , where I have to use python 2.5 instead of version 2.6. 我想安装一个鸡蛋 ,例如easy_install networkx-0.36-py2.5.egg ,在这里我必须使用python 2.5而不是2.6版本。 Is this possible without changing the python alias? 是否可以在不更改python别名的情况下进行?

  2. Can you tell me, whether and how I can install networkx-0.36-py2.5 and networkx-1.0rc1-py2.6 in parallel? 您能告诉我,是否以及如何并行安装networkx-0.36-py2.5networkx-1.0rc1-py2.6

  3. How can I install a site-package in a way, that it is available for different Python versions? 如何以一种可用于不同Python版本的方式安装站点包?

easy_install is part of the setuptools package. easy_installsetuptools软件包的一部分。 Fink has separate setuptools packages for python 2.5 and python 2.6: Fink为python 2.5和python 2.6提供了单独的setuptools软件包:

fink install setuptools-py25 setuptools-py26

You can then download and install networkx to both versions: 然后,您可以下载networkx并将其安装到两个版本:

/sw/bin/easy_install-2.5 networkx
/sw/bin/easy_install-2.6 networkx

If you need a particular version of the package: 如果您需要特定版本的软件包:

/sw/bin/easy_install-2.5 networkx==0.36
/sw/bin/easy_install-2.6 networkx==0.36

Edit: Read Ned Deily's answer before you read this one 编辑:阅读内德·迪利的答案,然后再阅读


1. 1。

On my system I have different easy_install script for each python version: 在我的系统上,每个python版本都有不同的easy_install脚本:

  • /usr/bin/easy_install-2.5 /usr/bin/easy_install-2.5
  • /usr/bin/easy_install-2.6 /usr/bin/easy_install-2.6

The contents of the 2.6 version looks like this: 2.6版本的内容如下所示:

#!/System/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
import sys
sys.argv[0] = sys.argv[0].replace('-2.6', '')
# EASY-INSTALL-ENTRY-SCRIPT: 'setuptools==0.6c9','console_scripts','easy_install'
__requires__ = 'setuptools==0.6c9'
import sys
from pkg_resources import load_entry_point

sys.exit(
   load_entry_point('setuptools==0.6c9', 'console_scripts', 'easy_install')()
)

Now, if you not already have those scripts on you machine, you could create those by using the above as template. 现在,如果您的计算机上还没有这些脚本,则可以使用上述脚本作为模板来创建它们。 Just change the first line so it points to the right python interpreter. 只需更改第一行,使其指向正确的python解释器即可。 Probably something like: 大概是这样的:

#!/sw/bin/python23

And change the third line to match the current script name; 并更改第三行以匹配当前脚本名称; meaning, if the script is called easy_install-2.3, then it should look like this: 意思是,如果脚本名为easy_install-2.3,则它应如下所示:

sys.argv[0] = sys.argv[0].replace('-2.3', '')

And of course if you are not using setuptools version 0.6c9 than you will have to change this, too. 当然,如果您没有使用setuptools版本0.6c9,则也必须更改此设置。


An alternative is to run the easy_install script as an argument of the right python version. 另一种方法是将easy_install脚本作为正确的python版本的参数运行。 Like this: 像这样:

$ python23 /some/path/easy_install networkx-0.36-py2.5.egg

2. 2。

Each python version has a different site-lib, so they are independent from each other. 每个python版本都有一个不同的site-lib,因此它们彼此独立。 You can install different modules and versions for different python versions 您可以为不同的python版本安装不同的模块和版本

3. 3。

You could make the env variable PYTHONPATH point to a common directory or add a common directory to sys.path in your scripts. 您可以使env变量PYTHONPATH指向公共目录,或者在脚本中将公共目录添加到sys.path But be aware that some modules work only with certain python versions and include C code that has to be compiled for each python version... 但是请注意,某些模块仅适用于某些python版本,并且包含必须为每个python版本编译的C代码...

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

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