In my opinion, the best way to handle python packages is to have a set of Python installations separate from the system Python, one for each version you need. This way I do not pollute the main python with old versions of packages, and I can delete them and reinstall them without any of my projects having problems.
Details:
On OS X, using the Macports versions are fine. The same is probably true for homebrew, although I never used it. (On Linuxes I install Python from source into /opt/pythonxx/, for example /opt/python25/, /opt/python26/, /opt/python27 and /opt/python31.)
I then never install any packages into these Pythons, with the exception of virtualenv, distribute and pip, which I install in all of them. When I want to install a package for a project, I make a virtualenv for that project with the python version I use for it:
$ cd /home/projects
$ /opt/python27/bin/virtualenv acoolproject
$ cd acoolproject
$ ./bin/pip install ThepackageIneed.
As you install each projects dependencies separately, you avoid dependency issues and version conflicts and version confusion.
You can enable and disable environments with virtualenv, I tend never to do that, I use the python executable explicitly instead:
$ ./bin/python main.py
or
$ /home7projects/acoolproject/bin/python
If I need things that you can't just install with pip, like Plone, or nginx or varnish, I use zc.buildout to make a replicatable environment configuration, zc.buildout will also run in isolation, so no packages gets installed in the main pythons.
If you're using Homebrew, you'll probably want to use pip to install Python packages. pip can be installed via Homebrew, but Homebrew doesn't include formulae for other Python packages. But it's pretty easy to install packages using pip -- as simple as
$ pip install <package>
(The package name can be found on PyPI.) If you installed pip via Homebrew, that's all you need to do.
发布评论
评论(3)
我强烈建议以下几点。我使用它们进行基本的包管理。
应该有帮助的教程/博客:
I would suggest the following strongly. I use them for basic package management.
Tutorial / blogs that should help:
在我看来,处理 python 包的最佳方法是拥有一组与系统 Python 分开的 Python 安装,每个版本对应一个您需要的版本。
这样我就不会用旧版本的包污染主 python,并且我可以删除它们并重新安装它们,而我的任何项目都不会出现问题。
详细信息:
在 OS X 上,使用 Macports 版本就可以了。自制程序可能也是如此,尽管我从未使用过它。 (在 Linux 上,我将 Python 从源代码安装到 /opt/pythonxx/ 中,例如 /opt/python25/、/opt/python26/、/opt/python27 和 /opt/python31。)
然后我从不将任何软件包安装到这些 Python 中,但
virtualenv
、distribute
和pip
除外,我在所有这些 Python 中都安装了它们。当我想为项目安装包时,我使用我使用的 python 版本为该项目创建一个 virtualenv:当您单独安装每个项目依赖项时,可以避免依赖项问题以及版本冲突和版本混乱。
您可以使用 virtualenv 启用和禁用环境,我倾向于从不这样做,而是显式使用 python 可执行文件:
或者
如果我需要无法仅使用 pip 安装的东西,例如 Plone、nginx 或 varnish,我使用 zc .buildout 进行可复制的环境配置,zc.buildout 也将独立运行,因此主 python 中不会安装任何包。
In my opinion, the best way to handle python packages is to have a set of Python installations separate from the system Python, one for each version you need.
This way I do not pollute the main python with old versions of packages, and I can delete them and reinstall them without any of my projects having problems.
Details:
On OS X, using the Macports versions are fine. The same is probably true for homebrew, although I never used it. (On Linuxes I install Python from source into /opt/pythonxx/, for example /opt/python25/, /opt/python26/, /opt/python27 and /opt/python31.)
I then never install any packages into these Pythons, with the exception of
virtualenv
,distribute
andpip
, which I install in all of them. When I want to install a package for a project, I make a virtualenv for that project with the python version I use for it:As you install each projects dependencies separately, you avoid dependency issues and version conflicts and version confusion.
You can enable and disable environments with virtualenv, I tend never to do that, I use the python executable explicitly instead:
or
If I need things that you can't just install with pip, like Plone, or nginx or varnish, I use zc.buildout to make a replicatable environment configuration, zc.buildout will also run in isolation, so no packages gets installed in the main pythons.
如果您使用 Homebrew,您可能需要使用
pip
来安装 Python 包。pip
可以通过 Homebrew 安装,但 Homebrew 不包含其他 Python 包的公式。但使用 pip 安装软件包非常简单——就像(软件包名称可以在 PyPI 上找到)一样简单。如果您通过 Homebrew 安装了 pip,那么您只需要做这些。
If you're using Homebrew, you'll probably want to use
pip
to install Python packages.pip
can be installed via Homebrew, but Homebrew doesn't include formulae for other Python packages. But it's pretty easy to install packages using pip -- as simple as(The package name can be found on PyPI.) If you installed pip via Homebrew, that's all you need to do.