PermissionError: [Errno 13] 权限被拒绝:pipenv 安装请求的“Pipfile”

Sah*_*and 4 python pip

我正在尝试遵循有关 pipenv 和 virtualenv 的指南:http ://docs.python-guide.org/en/latest/dev/virtualenvs/ 。问题是,我在尝试时遇到了问题$ pipenv install requests(在我的情况下我认为应该是$python3 -m pipenv install requests因为只是pipenv返回未找到的命令。)

为什么权限被拒绝?

我是一个终端菜鸟,所以请耐心等待。

$ pip3 install --user pipenv

$ python3 -m pipenv

Usage: __main__.py [OPTIONS] COMMAND [ARGS]...

$ python3 -m pipenv install requests

Creating a Pipfile for this project...
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/sahandzarrinkoub/Library/Python/3.6/lib/python/site-packages/pipenv/__main__.py", line 4, in <module>
    cli()
  File "/Users/sahandzarrinkoub/Library/Python/3.6/lib/python/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Users/sahandzarrinkoub/Library/Python/3.6/lib/python/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Users/sahandzarrinkoub/Library/Python/3.6/lib/python/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/sahandzarrinkoub/Library/Python/3.6/lib/python/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/sahandzarrinkoub/Library/Python/3.6/lib/python/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/sahandzarrinkoub/Library/Python/3.6/lib/python/site-packages/pipenv/cli.py", line 895, in install
    ensure_project(three=three, python=python)
  File "/Users/sahandzarrinkoub/Library/Python/3.6/lib/python/site-packages/pipenv/cli.py", line 180, in ensure_project
    ensure_pipfile(validate=validate)
  File "/Users/sahandzarrinkoub/Library/Python/3.6/lib/python/site-packages/pipenv/cli.py", line 141, in ensure_pipfile
    project.create_pipfile()
  File "/Users/sahandzarrinkoub/Library/Python/3.6/lib/python/site-packages/pipenv/project.py", line 219, in create_pipfile
    self.write_toml(data, 'Pipfile')
  File "/Users/sahandzarrinkoub/Library/Python/3.6/lib/python/site-packages/pipenv/project.py", line 226, in write_toml
    with open(path, 'w') as f:
PermissionError: [Errno 13] Permission denied: 'Pipfile'
Run Code Online (Sandbox Code Playgroud)

Mic*_*l S 5

确保您已将UserBase的 bin 目录添加到您的路径中(遵循文档中的注释框您所关注查看如何执行此操作)。

您提到的第三个命令应该是:pipenv install requests.


更长的版本:

自从您开始使用命令行以来,我将更深入地了解一些命令行概念(以及其他想要更深入参考的人)。

您显示三个命令:

  • pip3 install --user pipenv
  • 这是完美的,它安装pipenv作为用户包(不适用于整个系统)
  • python3 -m pipenv
  • 这没有任何作用。您看到返回的是“使用消息”。它是说这个命令需要一些 main.py 程序、选项(可选,因为在括号中)、一个命令(强制性)和可能更多的参数。如果您看到一条使用消息,则表示您没有按照作者预期的方式调用该程序。
  • python3 -m pipenv install requests
  • 这应该只是pipenv install requests. 但是,除非您将 UserBase 的 bin 添加到您的路径中(您会收到pipenv: command not found错误),否则它不会起作用。

PATH的 shell 将在您的位置搜索您列出的命令。请参阅在Mac、LinuxWindows上更改您的路径。

正如您所关注的文档所提到的,您想运行python3 -m site,您将获得如下输出:

$ python -m site
  .
  .
  .
USER_BASE: '/Users/<myusername>/Library/Python/3.6' (exists)
USER_SITE: '/Users/<myusername>/Library/Python/3.6/lib/python/site-packages' (exists)
ENABLE_USER_SITE: True
Run Code Online (Sandbox Code Playgroud)

既然您知道自己的USER_BASE位置,请/bin在末尾添加一个并将其添加到您的 PATH 中。再次查看特定于操作系统的说明,但在 OSX 上,您可以添加export PATH="$PATH:/Users/<myusername>/Library/Python/3.6/bin到您的~/.profile运行中source ~/.profile,当您输入命令时,您的 shell 现在将搜索该目录pipenv