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

我尝试使用谷歌搜索并搜索此内容,但仍然无法弄清楚。感谢您的任何帮助。

4

2 回答 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事后处理。

于 2017-01-13T20:42:25.350 回答
5

我在使用带有 -t(--target) 选项的 pip 安装 python 模块时遇到了类似的错误。

pip 日志显示下一条消息:

命令的完整输出 /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

和下一个错误:

不能将用户与前缀、exec_prefix/home 或 install_(plat)base 结合使用

阅读有关python 文档上的替代安装的信息,我看到了下一个信息

请注意,各种备用安装方案是互斥的:您可以传递 --user 或 --home 或 --prefix 和 --exec-prefix 或 --install-base 和 --install-platbase,但您可以不要混入这些群体。

所以 pip 执行的命令有两个互斥的方案--user--home(我认为这可能是 pip 上的一个 bug)。

我使用--system选项来避免错误,消除了 setup 命令中的 --user 标志。

pip install -t path_to_dir module_name --system

我不知道这种用法的附加含义,但我认为它比修改与正常安装混淆的配置文件更好。

PD:我使用 ubuntu 15.10 和 pip 1.5.6

于 2017-08-10T23:41:25.527 回答