--install-option ='-prefix'`和`--root`和`--target`之间的差异(python) [英] Pip (python) differences between `--install-option='--prefix'` and `--root` and `--target`

查看:605
本文介绍了--install-option ='-prefix'`和`--root`和`--target`之间的差异(python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来, pip文档缺乏太多措辞,涉及用于处理源代码和目的地.

我遇到了奇怪的事情,用pip3安装Sphinx并使用可用选项看似允许我将其精确安装在想要的位置(出于某些原因,我希望将每件东西都放在自己的目录中).我说的是播放",不是说我没有阅读文档也没有尝试--help,而是因为pip3 help install并没有帮助,并且pip install 官方文档页面对此内容太短,实际上说的不超过pip3 help install.

这是完成的实验和观察结果.

--root

的第一种情况

下载了当前的Sphinx存储库tarball ,将其解压缩,进入新创建的目录并执行以下操作:

pip3 install --root /home/<user-name>/apps/sphinx -e .

我虽然这与--prefix相同,但没有明显的--prefix选项可用.令我惊讶的是,它在Python3的bin目录中安装了命令(该命令也本地安装在其自己的目录中)以及其库目录中的某些内容,奇怪的是,我得到了一个而不是/home/<user-name>/apps/sphinx目录/home/<user-name>/apps/sphinx/home/<user-name>/apps/sphinx/…:它将指定的路径附加到其自身.

最后一点特别有意义吗? --root的目的是什么?

--target

的第二种情况

然后我虽然不是--root,但可能是--target,所以我做了(清理后):

pip3 install --target /home/<user-name>/apps/sphinx -e .  

它不起作用,抱怨--home选项无法识别.

它抱怨的是什么--home(我没有指定),什么是--target?

--install-option='--prefix=…'

有关的第三种情况

经过一些网络搜索和StackOverflow上的一个线程之后,我尝试了以下方法:

pip3 install --install-option='--prefix=/home/<user-name>/apps/sphinx' -e .

它只是抱怨无法安装.pth文件,而我的PYTHONPATH出了点问题,可以通过添加变量定义重新启动它来解决:

export PYTHONPATH=/home/<user-name>/apps/sphinx/lib/python3.4/site-packages
pip3 install --install-option='--prefix=/home/<user-name>/apps/sphinx' -e .

我什至在目录实际存在且没有安装任何内容之前,都必须设置PYTHONPATH,但这还是可以的(pip是否应该在此过程中更新PYTHONPATH本身并提醒设置肯定是一个有争议的问题.

这是个不错的选择,也是不太清楚的选择.

另一个上一个相关的人:

--editable--src有什么区别?

更新#1

我不知道它是否与Sphinx有关,但我注意到了另外两件事.

pip3 install --install-option='--prefix=<install-dir>' -e <repository-dir>

其中 repository-dir 是Sphinx的本地签出,Sphinx被安装在 install-dir 中,由pip3 list列出,但无法卸载.

相反,正在做

pip3 install --install-option='--prefix=<install-dir>' Sphinx

也就是说,让pip3检索档案,Sphinx未安装在 install-dir 中,而是安装在python目录中,由pip3 list列出,并且可以卸载. /p>

取决于源是本地存储库还是远程档案,它不会安装在同一位置,也不会安装或将要卸载.

依赖关系不受影响,在两种情况下都以相同的方式处理(安装在预期的位置,列出的位置和可卸载的位置).

更新#2

--root的行为使我感到一种假根(例如构建Debian软件包或交叉编译时得到的假根).如果意图是相同的,那么相反,那是让我惊讶的道路.

解决方案

第一个显而易见的问题:为什么不从

因此,您可以发出命令(如有必要,使用sudo前缀)

pip3 install -e /path/to/pkg

其中/path/to/pkg是可在其中找到setup.py(提取文件的位置)的目录.

要回答其他问题:

  1. --root <dir>

  2. 用于更改pip应该在其中安装软件包资源的文件系统的根目录,而不是更改在何处找到软件包.

    使用
  3. --target 告诉pip在哪个文件夹中安装软件包.

  4. --install-option 用于设置setup.py将使用的一些变量,而不更改pip在文件中查找的位置.

The pip documentation lacks too much wordings (to my eyes), about parameters to deal with source and destinations.

I've experienced strange things installing Sphinx with pip3 and playing with the options available to seemingly allow me to install it precisely where I wanted (for some reasons, I want to have each thing in its own directory). I say "playing", not that I did not read the doc nor tried --help, but because the pip3 help install did not help, and the pip install official documentation page is too short on this and actually says not more than the pip3 help install.

Here are the experiments done and the observations.

First case with --root

I downloaded the current Sphinx repository tarball, unpacked it, get into the newly created directory and did:

pip3 install --root /home/<user-name>/apps/sphinx -e .

I though this would be the same as --prefix, as there was no --prefix option visibly available. To my surprise, it installed the commands in the bin directory of Python3 (which is also installed locally in its own directory) along to some things in its library directory, and strange, instead of a /home/<user-name>/apps/sphinx directory, I get a /home/<user-name>/apps/sphinx/home/<user-name>/apps/sphinx/…: it appended the specified path to itself.

How especially the last point does make sense? What's the purpose of --root?

Second case with --target

Then I though if it's not --root, that may be --target, so I did (after a clean up):

pip3 install --target /home/<user-name>/apps/sphinx -e .  

It did not work, complaining about an unrecognized --home option.

What is this --home (which I did not specified) it complains about, and what exactly is --target?

Third case with --install-option='--prefix=…'

After some web‑searching and a thread on StackOverflow, I tried this:

pip3 install --install-option='--prefix=/home/<user-name>/apps/sphinx' -e .

It just complained it could not install a .pth file and something is wrong with my PYTHONPATH, which was addressable restarting the same with the addition of a variable definition:

export PYTHONPATH=/home/<user-name>/apps/sphinx/lib/python3.4/site-packages
pip3 install --install-option='--prefix=/home/<user-name>/apps/sphinx' -e .

I just had to the set PYTHONPATH even before the directory actually exists and anything was installed in it, but this one was OK (whether or not pip should update PYTHONPATH itself during the process and remind to set it up definitively, is a debatable question).

This option, which was the good one, was also the less clearly visible one.

Another last related one:

What's the difference between --editable and --src?

Update #1

I can't tell if it's Sphinx related, but I noticed two additional things.

Doing

pip3 install --install-option='--prefix=<install-dir>' -e <repository-dir>

where repository-dir is a local check out of Sphinx, Sphinx gets installed in install-dir, is listed by pip3 list but can't be uninstalled.

On the opposite, doing

pip3 install --install-option='--prefix=<install-dir>' Sphinx

that is, letting pip3 retrieving an archive, Sphinx is not installed in install-dir, is installed in the python directory instead, is listed by pip3 list and can be uninstalled.

Depending on whether the source is a local repository or a remote archive, it won't be installed at the same location and will not be or will be uninstallable.

Dependencies were not affected, were handled the same way in both cases (installed where expected, listed, and uninstallable).

Update #2

The behaviour with --root make me feel about a kind of fake‑root (like the one you get when building a Debian package or when cross‑compiling). If it's intended to be the same, then the path which surprised me, is on the contrary, expected.

解决方案

First and obvious question: why don't you just install the package from PyPI?

sudo pip install sphinx

If you want to install anything that has a setup.py file with pip you can use the --editable flag:

-e, --editable <path/url>

Install a project in editable mode (i.e. setuptools "develop mode") from a local project path or a VCS url.

So you can just issue the command (prefix with sudo if necessary):

pip3 install -e /path/to/pkg

where /path/to/pkg is the directory where setup.py can be found (where you extracted the files).

To answer the other questions:

  1. --root <dir> is used to change the root directory of the file system where pip should install package resources, not to change where to find the package.

  2. --target is used to tell pip in which folder to install the package.

  3. --install-option is used to set some variables that will be used by setup.py, not to change where pip should look for the file.

这篇关于--install-option ='-prefix'`和`--root`和`--target`之间的差异(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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