python pip - 从本地目录安装 [英] python pip - install from local dir

查看:173
本文介绍了python pip - 从本地目录安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须下载一个 git python repo 并安装,因为 pypi 版本没有更新.

I have to download a git python repo and install since the pypi version is not updated.

通常我会这样做:

pip install mypackage
pip install mypackage[redis]

现在我将 repo 克隆到以下文件夹中:

Now I have the repo cloned in the following folder:

/opt/mypackage

/opt/mypackage

那么如何不使用 pypi 版本而是使用本地版本来运行以下安装?

So how to I run to install the below not using the pypi version but the local?

pip --flag /opt/mypackage install mypackage
pip --flag /opt/mypackage install mypackage[redis]

有可用的 pip 标志,但我不知道如何完成:

There are the pip flags available and I don't see how to accomplish :

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

推荐答案

你需要做的就是运行

pip install /opt/mypackage

和 pip 将在 /opt/mypackage 中搜索 setup.py,构建一个轮子,然后安装它.

and pip will search /opt/mypackage for a setup.py, build a wheel, then install it.

使用-e 标记为 pip install 在评论和这个答案中的建议是这要求只要您想使用该模块,原始源目录就保持原样.如果您是从事源代码工作的开发人员,那固然很好,但如果您只是想安装一个包,那就是错误的选择.

The problem with using the -e flag for pip install as suggested in the comments and this answer is 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.

或者,您甚至根本不需要从 Github 下载存储库.pip 支持 使用包括 HTTP 在内的各种协议直接从 git repos 安装、HTTPS 和 SSH 等.有关示例,请参阅我链接到的文档.

Alternatively, you don't even need to download the repo from Github at all. pip supports installing directly from git repos using a variety of protocols including HTTP, HTTPS, and SSH, among others. See the docs I linked to for examples.

这篇关于python pip - 从本地目录安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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