使用pip install --user -e /home/me/package/时出现“权限被拒绝”的错误。

12

我正在尝试使用pip--editable模式安装本地软件包。当我输入以下命令时...

$ python3.7 -m pip install --user -e /home/me/my_pkg/

...当它正确安装所有依赖项后,尝试安装my_pkg本身时,我遇到了以下问题...

  Running setup.py develop for udar
    Running command /usr/bin/python3.7 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/me/my_pkg/setup.py'"'"'; __file__='"'"'/home/me/my_pkg/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps --user --prefix=
    running develop
    WARNING: The user site-packages directory is disabled.
    error: can't create or remove files in install directory

    The following error occurred while trying to add or remove files in the
    installation directory:

        [Errno 13] Permission denied: '/usr/local/lib/python3.7/dist-packages/test-easy-install-901889.write-test'

    The installation directory you specified (via --install-dir, --prefix, or
    the distutils default setting) was:

        /usr/local/lib/python3.7/dist-packages/

    Perhaps your account does not have write access to this directory?  If the
    installation directory is a system-owned directory, you may need to sign in
    as the administrator or "root" account.  If you do not have administrative
    access to this machine, you may wish to choose a different installation
    directory, preferably one that is listed in your PYTHONPATH environment
    variable.

    For information on other options, you may wish to consult the
    documentation at:

      https://setuptools.readthedocs.io/en/latest/easy_install.html

    Please make the appropriate changes for your system and try again.

ERROR: Command errored out with exit status 1: /usr/bin/python3.7 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/me/my_pkg/setup.py'"'"'; __file__='"'"'/home/me/my_pkg/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps --user --prefix= Check the logs for full command output.
Exception information:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/pip/_internal/cli/base_command.py", line 180, in _main
    status = self.run(options, args)
  File "/usr/local/lib/python3.7/dist-packages/pip/_internal/cli/req_command.py", line 204, in wrapper
    return func(self, options, args)
  File "/usr/local/lib/python3.7/dist-packages/pip/_internal/commands/install.py", line 402, in run
    pycompile=options.compile,
  File "/usr/local/lib/python3.7/dist-packages/pip/_internal/req/__init__.py", line 85, in install_given_reqs
    pycompile=pycompile,
  File "/usr/local/lib/python3.7/dist-packages/pip/_internal/req/req_install.py", line 768, in install
    unpacked_source_directory=self.unpacked_source_directory,
  File "/usr/local/lib/python3.7/dist-packages/pip/_internal/operations/install/editable_legacy.py", line 46, in install_editable
    cwd=unpacked_source_directory,
  File "/usr/local/lib/python3.7/dist-packages/pip/_internal/utils/subprocess.py", line 244, in call_subprocess
    raise InstallationSubprocessError(proc.returncode, command_desc)
pip._internal.exceptions.InstallationSubprocessError: Command errored out with exit status 1: /usr/bin/python3.7 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/me/my_pkg/setup.py'"'"'; __file__='"'"'/home/me/my_pkg/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps --user --prefix= Check the logs for full command output.
Removed build tracker: '/tmp/pip-req-tracker-hvg66sl4'

我不明白为什么使用--user标志后会出现权限错误。我不想全局安装此软件包,因此不能使用sudo pip install ...。如何让pip只为当前用户安装一个editable软件包?

$ python3.7 -m pip --version
pip 21.1.1 from /home/rob/.local/lib/python3.7/site-packages/pip (python 3.7)

1
尝试创建虚拟环境了吗? - Shawn Ramirez
@phd 唯一的输出是 ~/.dbus,我已经修复了它,但它并没有改变行为。不过这是个好建议。 - reynoldsnlp
那么,“警告:用户站点软件包目录已禁用。”非常奇怪。echo $PYTHONNOUSERSITE - phd
@phd,该变量未设置。 - reynoldsnlp
2
看起来这是一个已知的问题:https://github.com/pypa/pip/issues/7953 当使用PEP 517(pyproject.toml)时,无法将editable安装到用户站点。 - reynoldsnlp
显示剩余2条评论
2个回答

11

这是一个bug。问题正在 https://github.com/pypa/pip/issues/7953 进行跟踪。

现在的解决方法是修改您的setup.py(),将其包含以下内容:

import site
import sys
site.ENABLE_USER_SITE = "--user" in sys.argv[1:]

或者,如果您使用setup.cfg或pyproject.toml,可以在命令行上使用类似以下内容的东西:

$ python3 -c 'import setuptools, site, sys; site.ENABLE_USER_SITE = 1; sys.argv[1:] = ["develop", "--user"]; setuptools.setup()'

4

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