Pip安装--target =。Alfred-Workflow会出错

9
我正在按照这些说明在macOS上安装一个python库。
但是每次运行这个命令:pip install --target=. Alfred-Workflow,我都会遇到错误。
我总是得到以下错误:
pip install --target=. Alfred-Workflow       
Collecting Alfred-Workflow
Installing collected packages: Alfred-Workflow
Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 247, in move_wheel_files
    prefix=prefix,
  File "/usr/local/lib/python2.7/site-packages/pip/locations.py", line 153, in distutils_scheme
    i.finalize_options()
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/install.py", line 264, in finalize_options
    "must supply either home or prefix/exec-prefix -- not both"
DistutilsOptionError: must supply either home or prefix/exec-prefix -- not both

我试着通过谷歌搜索来寻找答案,但还是无法弄清楚。感谢任何帮助。


尝试去掉等号= - pip install -t . Alfred-Workflow - MattDMo
不起作用。 给出类似的消息:http://i.imgur.com/hu5q9qp.png - Nikita
2个回答

17

这个问题回答了你错误消息的最后一行所指的内容(我在谷歌上搜索时找到了它)。

起初,我也遇到了和你一样的错误消息,但是在执行以下步骤之后,问题得以解决:

$ echo "[install]
prefix=" > ~/.pydistutils.cfg

它可用:

$ pip install --target=. Alfred-Workflow
Collecting Alfred-Workflow
Installing collected packages: Alfred-Workflow
Successfully installed Alfred-Workflow-1.24

重要提示:它会破坏普通的pip install 命令,因此您需要在之后运行rm ~/.pydistutils.cfg.


我做了。在你提供的问题中,它说:“如果你创建一个带有“空前缀”指令的~/.pydistutils.cfg文件,它将解决这个问题,但它会破坏正常的pip操作。”那么我的pip现在也坏了吗? - Nikita
哦,是的,确实如此!感谢指出。我已经在答案中添加了一条注释。 - hansaplast
3
有没有一种方法可以在不破坏正常的pip安装和每次运行此命令后都要删除~/.pydistutils.cfg的情况下解决这个问题? - Nikita
根据我链接的问题讨论,显然不是这样的。据我所知,这是一个自制问题,因此您可以重新安装没有Homebrew的Python,我希望通过这种方式解决此问题。 - hansaplast

5
我使用pip和-t(--target)选项安装python模块时遇到了类似的错误。 pip日志显示以下消息:
``` Complete output from command /usr/bin/python -c "import setuptools, tokenize;file='/tmp/pip-build-LvB_CW/xlrd/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-UNJizV-record/install-record.txt --single-version-externally-managed --compile --user --home=/tmp/tmphjBN23 ```
错误如下:
``` can't combine user with prefix, exec_prefix/home, or install_(plat)base ```
根据Python文档中关于备用安装方法的说明,我发现以下信息:
``` 请注意,各种替代安装方案是互斥的:您可以传递--user、--home、--prefix 和 --exec-prefix 或 --install-base 和 --install-platbase,但不能从这些组合中混合使用。 ```
因此,由pip执行的命令具有两个互斥的方案:--user 和 --home(我认为这可能是pip的一个错误)。
我使用 --system 选项避免了错误,在 setup 命令上消除了 --user 标志。
``` pip install -t path_to_dir module_name --system ```
我不知道这种用法的其他含义,但我认为它比修改配置文件更好,这会干扰正常安装。
注:我使用 Ubuntu 15.10 和 pip 1.5.6。

添加了 --system 标志后,它终于可以工作了。谢谢! - Manzurul Hoque Rumi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接