在Mac上将python模块安装到非默认版本的python [英] Install python module to non default version of python on Mac

查看:69
本文介绍了在Mac上将python模块安装到非默认版本的python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a couple different versions of Python installed on my Mac. The default version is 2.5, so when I install a module it gets installed to 2.5. I need to be able to install some modules to a different version of Python because I am working on projects that use different versions. Any one know how to accomplish this? Thanks for your help.

推荐答案

如果使用setup.py进行安装,只需通过相应版本的Python运行它,例如:

If you're installing using setup.py, just run it via the appropriate version of Python, e.g.:

python2.6 setup.py install

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

If you're using easy_install there should be a version for the corresponding Python version called easy_install-N.N, e.g.

easy_install-2.6 some_module

如果您正在从事需要不同版本Python的不同项目,请考虑使用 virtualenv (和 virtualenvwrapper )-它允许您启动并使用具有各自版本的多个环境Python和一组库.用法示例如下:

If you're working on different projects that require different versions of Python, consider using virtualenv (and virtualenvwrapper) - it allows you to fire up and use multiple environments each with its own version of Python and set of libraries. Example usage would be something like:

$ 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:

To go back to the foo environment later, use workon:

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

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

So you can use virtualenv to maintain separate environments for each version of Python you have installed. Within those environments, pip and easy_install just do the right thing.

这篇关于在Mac上将python模块安装到非默认版本的python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆