python pip - 从本地目录安装

Tam*_*mpa 23 python python-2.7

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

通常我会这样做:

pip install mypackage
pip install mypackage[redis]
Run Code Online (Sandbox Code Playgroud)

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

的/ opt/mypackage的

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

pip --flag /opt/mypackage install mypackage
pip --flag /opt/mypackage install mypackage[redis]
Run Code Online (Sandbox Code Playgroud)

有可用的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
Run Code Online (Sandbox Code Playgroud)

Mat*_*DMo 50

你需要做的就是跑步

pip install /opt/mypackage
Run Code Online (Sandbox Code Playgroud)

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

在评论和答案中建议使用-e标志的问题是,这要求原始源目录保留到您想要使用模块的时间.如果你是一名开发源代码的开发人员,那就太好了,但是如果你只是想安装一个软件包,那就错了.pip install

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

  • @Tampa 据我所知,`pip install /opt/mypackage[redis]` 应该可以工作。 (3认同)

fab*_*gli 17

您正在寻找有关pip安装的帮助.您可以使用以下命令找到它: pip install --help

运行pip install -e /path/to/package以某种方式安装软件包,您可以编辑软件包,当新的导入调用查找它时,它将导入已编辑的软件包代码.这对于包开发也非常有用.

  • 正如我在[我的答案](/sf/answers/2907599411/)中解释的那样,使用“-e”安装要求包源位于同一位置(在本例中为“/opt/mypackage” ) 永远,这可能是不可取的,或者如果它位于 `/tmp` 中,甚至是不可能的。将“pip”直接指向包含“setup.py”的目录绝对是正确的方法。 (3认同)