python pip - 从本地目录安装
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41535915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
python pip - install from local dir
提问by Tampa
I have to download a git python repo and install since the pypi version is not updated.
我必须下载一个 git python repo 并安装,因为 pypi 版本没有更新。
Normally I would do this:
通常我会这样做:
pip install mypackage
pip install mypackage[redis]
Now I have the repo cloned in the following folder:
现在我将 repo 克隆到以下文件夹中:
/opt/mypackage
/选择/我的包
So how to I run to install the below not using the pypi version but the local?
那么如何运行以不使用pypi版本而是使用本地安装以下内容?
pip --flag /opt/mypackage install mypackage
pip --flag /opt/mypackage install mypackage[redis]
There are the pip flags available and I don't see how to accomplish :
有可用的 pip 标志,我不知道如何完成:
Commands:
install Install packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
search Search PyPI for packages.
wheel Build wheels from your requirements.
help Show help for commands.
General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output.
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.
--trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
回答by MattDMo
All you need to do is run
您需要做的就是运行
pip install /opt/mypackage
and pip will search /opt/mypackage
for a setup.py
, build a wheel, then install it.
pip 将搜索/opt/mypackage
a setup.py
,构建一个轮子,然后安装它。
The problem with using the -e
flag for pip install
as suggested in the comments and this answeris that this requires that the original source directory stay in place for as long as you want to use the module. It's great if you're a developer working on the source, but if you're just trying to install a package, it's the wrong choice.
使用注释中建议的-e
标志的问题pip install
和这个答案是,这要求原始源目录保持原位,只要您想使用该模块。如果您是从事源代码工作的开发人员,那就太好了,但如果您只是想安装一个包,那就是错误的选择。
Alternatively, you don't even need to download the repo from Github at all. pip supportsinstalling directly from git repos using a variety of protocols including HTTP, HTTPS, and SSH, among others. See the docs I linked to for examples.
或者,您甚至根本不需要从 Github 下载 repo。pip支持使用各种协议直接从 git repos 安装,包括 HTTP、HTTPS 和 SSH 等。有关示例,请参阅我链接到的文档。
回答by fabianegli
You were looking for help on installations with pip. You can find it with the following command:
您正在寻找有关pip安装的帮助。您可以使用以下命令找到它:
pip install --help
Running pip install -e /path/to/package
installs the package in a way, that you can edit the package, and when a new import call looks for it, it will import the edited package code. This can be very useful for package development.
运行pip install -e /path/to/package
以某种方式安装包,您可以编辑包,当新的导入调用查找它时,它将导入编辑后的包代码。这对于包开发非常有用。