Bazel Python依赖关系错误-在获取存储库python_external_deps期间发生错误

问题描述

我正在使用的一个回购协议使用Bazel,并且由于其中一个验证我的设置是否正确的Bazel命令而遇到以下错误

repo %  bazel query infra/...

Loading: 0 packages loaded
INFO: Repository python_external_deps instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule pip_repository defined at:
  /private/var/tmp/_bazel_septerr/2bcb6e5a56cd66d1868dc15259a19a8b/external/rules_python_external/defs.bzl:46:33: in <toplevel>
DEBUG: Rule 'rules_python_external' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1587525369 +1000"
DEBUG: Repository rules_python_external instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  /private/var/tmp/_bazel_septerr/2bcb6e5a56cd66d1868dc15259a19a8b/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
ERROR: An error occurred during the fetch of repository 'python_external_deps':
   Traceback (most recent call last):
    File "/private/var/tmp/_bazel_septerr/2bcb6e5a56cd66d1868dc15259a19a8b/external/rules_python_external/defs.bzl",line 41,column 13,in _pip_repository_impl
        fail("rules_python_external Failed: %s (%s)" % (result.stdout,result.stderr))
Error in fail: rules_python_external Failed:  (  ERROR: Command errored out with exit status 1:
   command: /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /private/var/tmp/_bazel_septerr/2bcb6e5a56cd66d1868dc15259a19a8b/external/pypi__pip/pip install --ignore-installed --no-user --prefix /private/var/folders/9j/xp6km4954fz256491861l2qr0000gn/T/pip-build-env-2niyw4p8/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.cbhq.net --extra-index-url https://pypi.python.org/simple/ -- 'setuptools>=40.8.0' wheel
       cwd: None
  Complete output (9 lines):
  Looking in indexes: https://pypi.cbhq.net,https://pypi.python.org/simple/
  Collecting setuptools>=40.8.0
    Using cached https://files.pythonhosted.org/packages/44/a6/7fb6e8b3f4a6051e72e4e2218889351f0ee484b9ee17e995f5ccff780300/setuptools-50.3.0-py3-none-any.whl
  Collecting wheel
    Using cached https://files.pythonhosted.org/packages/a7/00/3df031b3ecd5444d572141321537080b40c1c25e1caa3d86cdd12e5e919c/wheel-0.35.1-py2.py3-none-any.whl
  Installing collected packages: setuptools,wheel
  ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/3.7'
  Consider using the `--user` option or check the permissions.
  
  ----------------------------------------
ERROR: Command errored out with exit status 1: /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /private/var/tmp/_bazel_septerr/2bcb6e5a56cd66d1868dc15259a19a8b/external/pypi__pip/pip install --ignore-installed --no-user --prefix /private/var/folders/9j/xp6km4954fz256491861l2qr0000gn/T/pip-build-env-2niyw4p8/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.cbhq.net --extra-index-url https://pypi.python.org/simple/ -- 'setuptools>=40.8.0' wheel Check the logs for full command output.
Traceback (most recent call last):
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/python3.framework/Versions/3.7/lib/python3.7/runpy.py",line 193,in _run_module_as_main
    "__main__",mod_spec)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/python3.framework/Versions/3.7/lib/python3.7/runpy.py",line 85,in _run_code
    exec(code,run_globals)
  File "/private/var/tmp/_bazel_septerr/2bcb6e5a56cd66d1868dc15259a19a8b/external/rules_python_external/extract_wheels/__main__.py",line 5,in <module>
    extract_wheels.main()
  File "/private/var/tmp/_bazel_septerr/2bcb6e5a56cd66d1868dc15259a19a8b/external/rules_python_external/extract_wheels/__init__.py",line 70,in main
    [sys.executable,"-m","pip","wheel","-r",args.requirements]
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/python3.framework/Versions/3.7/lib/python3.7/subprocess.py",line 395,in check_output
    **kwargs).stdout
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/python3.framework/Versions/3.7/lib/python3.7/subprocess.py",line 487,in run
    output=stdout,stderr=stderr)
subprocess.CalledProcessError: Command '['/Applications/Xcode.app/Contents/Developer/usr/bin/python3','-m','pip','wheel','-r','/Users/septerr/src/sgupta/repo/requirements.txt.external']' returned non-zero exit status 1.
)
DEBUG: Rule 'c_rules_ruby' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1595625326 -0700"
DEBUG: Repository c_rules_ruby instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  /private/var/tmp/_bazel_septerr/2bcb6e5a56cd66d1868dc15259a19a8b/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
DEBUG: Rule 'com_github_atlassian_bazel_tools' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1586491416 +1000"
DEBUG: Repository com_github_atlassian_bazel_tools instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  /private/var/tmp/_bazel_septerr/2bcb6e5a56cd66d1868dc15259a19a8b/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
ERROR: no such package '@python_external_deps//': rules_python_external Failed:  (  ERROR: Command errored out with exit status 1:
   command: /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /private/var/tmp/_bazel_septerr/2bcb6e5a56cd66d1868dc15259a19a8b/external/pypi__pip/pip install --ignore-installed --no-user --prefix /private/var/folders/9j/xp6km4954fz256491861l2qr0000gn/T/pip-build-env-2niyw4p8/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.cbhq.net --extra-index-url https://pypi.python.org/simple/ -- 'setuptools>=40.8.0' wheel
       cwd: None
  Complete output (9 lines):
  Looking in indexes: https://pypi.cbhq.net,'/Users/septerr/src/sgupta/repo/requirements.txt.external']' returned non-zero exit status 1.
)
Loading: 0 packages loaded
    currently loading: infra/loadtesting/locust ... (3 packages)

WORKSPACE文件具有以下与Python相关的语句:

###
# Python
###

load("@rules_python//python:repositories.bzl","py_repositories")

py_repositories()

# Only needed if using the packaging rules.
load("@rules_python//python:pip.bzl","pip_repositories")

pip_repositories()

load("@rules_python//python:pip.bzl","pip3_import")

# Create a central repo that kNows about the dependencies needed for
# requirements.txt.
pip3_import(
    name = "python_deps",requirements = "//:requirements.txt",)

# Load the central repo's install function from its `//:requirements.bzl` file,# and call it.
load("@python_deps//:requirements.bzl","pip_install")

pip_install()

# With transitive dependencies in requirements.txt
# See example of use in //data/pkg.bzl
load("@rules_python_external//:repositories.bzl","rules_python_external_dependencies")

rules_python_external_dependencies()

load("@rules_python_external//:defs.bzl",pip_install_external = "pip_install")

pip_install_external(
    name = "python_external_deps",requirements = "//:requirements.txt.external",)

解决方法

我只需更改/ Library / Python目录的权限就可以解决此问题。

sudo chown -R <username> /Library/Python