English 中文(简体)
在Mac上将python模块安装到非默认版本的python
原标题:Install python module to non default version of python on Mac

我的Mac上安装了几个不同版本的Python。默认版本是2.5,所以当我安装模块时,它会安装到2.5。我需要能够将一些模块安装到不同版本的Python中,因为我正在处理使用不同版本的项目。有人知道如何做到这一点吗?谢谢你的帮助。

最佳回答

如果使用setup.py进行安装,只需通过适当版本的Python运行即可,例如:

python2.6 setup.py install

如果您使用的是easy_install,那么对应的Python版本应该有一个名为easy_install-N.N的版本,例如。

easy_install-2.6 some_module

如果您正在处理需要不同版本Python的不同项目,请考虑使用virtualenv(和virtualenvwrapper)-它允许您启动和使用多个环境,每个环境都有自己版本的Python和一组库。示例用法如下:

$ python -V
Python 2.5.4
$ mkvirtualenv --python=python2.6 foo
foo $ python -V
Python 2.6.1
foo $ pip install some_mod # installs module in foo s library, rather
                           # than site wide
foo $ deactivate # leave the virtual env
$ python -m some_mod
/path/to/python: No module named some_mod

要稍后返回到foo环境,请使用workon

$ workon foo
foo $ python -m some_mod # no error, apns available within the env
foo $ 

因此,您可以使用virtualenv为您安装的每个Python版本维护单独的环境。在这些环境中,pip和easy_install只是做了正确的事情。

问题回答

如果您通过setuptools(即<code>python setup.py</code>)进行安装,它将安装到您使用的python可执行文件的lib目录中(除非它是一个损坏的包)。

如果您使用macports安装了它们,则您运行(以root身份):

port select --set python <python_version>

提示:要列出可用版本,请运行:

port select --list python

否则,您可以设置$PYTHON_PATH环境变量,并将所需的PYTHON路径添加到$PATH的环境变量中。

您还需要更新/Library/Frameworks/python.framework中的python.current(或类似名称的东西)符号链接。


我强烈建议使用软件包管理器安装所有版本(homebrewfink等),因此它们将更易于管理。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签