pip install --user -e /home/me/package/ 权限被拒绝

rey*_*nlp 12 python pip

--editable我正在尝试使用 模式安装本地包pip。当我发出命令时...

$ python3.7 -m pip install --user -e /home/me/my_pkg/
Run Code Online (Sandbox Code Playgroud)

...它正确安装了所有依赖项,但是当它尝试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'
Run Code Online (Sandbox Code Playgroud)

我不明白我怎么会收到该--user标志的权限错误。我不想全局安装这个包,所以使用sudo pip install ...不是一个选项。如何让 pipeditable仅为当前用户安装软件包?

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

Clé*_*ent 11

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

目前的解决方法是修改您的setup.py()以包含此内容:

import site
import sys
site.ENABLE_USER_SITE = "--user" in sys.argv[1:]
Run Code Online (Sandbox Code Playgroud)

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

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