问题描述
我有一个网站框架,我想在多个项目中使用,但我不想将我的框架提交给 PyPi.无论如何我可以告诉我的 setup.py 从特定位置安装框架吗?
I have a framework for a site that I want to use in multiple projects but I don't want to submit my framework to PyPi. Is there anyway I can tell my setup.py to install the framework from a specific location?
这是我当前的 setup.py
Here is my current setup.py
from setuptools import setup
setup(
name='Website',
version='0.2.1',
install_requires=[
'boto>=2.6',
'fabric>=1.4',
'lepl>=5.1',
'pygeoip>=0.2.4',
'pylibmc>=1.2.3',
'pymongo>=2.2',
'pyyaml>=3.1',
'requests>=0.12',
'slimit>=0.7.4',
'thrift>=0.8.0',
'tornado>=2.3',
],
)
这些依赖项实际上是我的框架的所有依赖项,所以如果我能以某种方式包含它,我只能在此处列出框架.
Those dependencies are actually all the dependencies for my framework so if I could include it somehow I could only have the framework listed here.
推荐答案
看起来您的所有需求都是公开的(在 PyPI 上),并且您不需要它们的特定版本,只需足够新"即可.在 2016 年,当您可以指望每个人都拥有最新版本的 pip
时,您真的无事可做.如果你只是 pip install .
从源目录或 pip install git+https://url/to/package
或类似的,它只会拉取最新版本的依赖离线.您的包不在 PyPI 上这一事实不会阻止 pip 在那里找到它的依赖项.
It looks like all of your requirements are public (on PyPI), and you don't need specific versions of them, just "new enough". In 2016, when you can count on everyone having a recent-ish version of pip
, there's really nothing to do. If you just pip install .
from the source directory or pip install git+https://url/to/package
or similar, it will just pull the latest versions of the dependencies off the net. The fact that your package isn't on PyPI won't stop pip from finding its dependencies there.
或者,如果您想将它们全部存储在本地,您可以设置本地 PyPI 索引.尽管在这种情况下,将您的包推送到相同的本地索引并从那里安装它可能会更简单.
Or, if you want to stash them all locally, you can set up a local PyPI index. Although in that case, it probably would be simpler to push your package to that same local index, and install it from there.
如果您需要更复杂的东西,需求文件可以照顾好你.
If you need anything more complicated, a requirements file can take care of that for you.
特别是,如果您需要将包分发给组织中可能没有设置您团队的本地索引的其他人,或者由于某种原因您无法首先设置本地索引,您可以把所有必要的信息放在需求文件中——或者,如果更合适的话,放在用来安装你的包的命令行上(如果你坚持使用 easy_install
或旧版本的pip).
In particular, if you need to distribute the package to other people in your organization who may not have your team's local index set up, or for some reason you can't set up a local index in the first place, you can put all the necessary information in the requirements file--or, if it's more appropriate, on the command line used to install your package (which even works if you're stuck with easy_install
or ancient versions of pip
).
该文档提供了完整的详细信息,这篇博文 对其进行了非常详细的解释很好,但简短的版本是这样的:
The documentation gives full details, and this blog post explains it very nicely, but the short version is this:
如果您有本地 PyPI 索引,请提供
--extra-index-url=http://my.server/path/to/my/pypi/
.
如果你有一个 HTTP 服务器,你可以将包放在上面,并且你可以在你的服务器中启用自动索引目录内容"选项,只需提供 --find-links=http://my.server/path/to/my/packages/
.
If you've got an HTTP server that you can drop the packages on, and you can enable the "auto index directory contents" option in your server, just provide --find-links=http://my.server/path/to/my/packages/
.
如果你想使用本地文件(或 SMB/AFP/etc. 文件共享),创建一个简单的 HTML 文件,只包含指向所有本地包的链接,并提供 --find-links=file:///path/to/my/index.html
.
If you want to use local files (or SMB/AFP/etc. file sharing), create a trivial HTML file with nothing but links to all local packages, and provide --find-links=file:///path/to/my/index.html
.
同样,这些可以在安装这个包,运行这个"(或一个 curl | sh
安装脚本)的命令行上,但通常你只想把它们放在一个需求文件.如果是这样,请确保每个选项只使用一个值(例如,如果您想添加两个额外的索引,请添加两个 --extra-index-url
参数)并将每个参数放在自己的行上.
Again, these can go on the command line of a "to install this package, run this" (or a curl | sh
install script), but usually you just want to put them in a requirements file. If so, make sure to use only one value per option (e.g., if you want to add two extra indexes, add two --extra-index-url
params) and put each one on its own line.
需求文件还允许您指定每个包的特定版本,因此您可以确保人们使用您开发和测试的相同代码进行部署,这在此类情况下通常很有用.
A requirements file also lets you specify specific versions of each package, so you can be sure people are deploying with the same code you developed and tested with, which is often useful in these kinds of situations.
这篇关于使用 setuptools 从位置安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!