简体   繁体   English

PyCharm 错误:[Errno 13] 权限被拒绝

[英]PyCharm error: [Errno 13] Permission denied

I am using PyCharm for executing my Python programs.我正在使用 PyCharm 来执行我的 Python 程序。 Today, I had tried updating all the packages using Project Interpreter.今天,我尝试使用 Project Interpreter 更新所有包。 I received the following error in the process:我在此过程中收到以下错误:

error: [Errno 13] Permission denied错误:[Errno 13] 权限被拒绝

在此处输入图像描述

After which none of my Python libraries are shown in Project Interpreter list.之后,我的 Python 库都没有显示在 Project Interpreter 列表中。

I am using PyCharm Community Edition 2016.2.3 in Mac OS X 10.11.6.我在 Mac OS X 10.11.6 中使用 PyCharm Community Edition 2016.2.3。

It looks like you need to give your interpretter root permissions.看起来你需要给你的解释器 root 权限。 There is a tutorial here on how to do this 这里有一个关于如何做到这一点的教程

The PermissionError: [errno 13] permission denied error occurs when you try to access a file from Python without having the necessary permissions. PermissionError: [errno 13] permission denied错误发生在您尝试在没有必要权限的情况下从 Python 访问文件时。 In your case the file (or directory ???) of interest is /var/folders/2k/_1tccbln53165lgvzvzt3b480000gp/T/tmprqbtrpspycharm-management/setuptools-18.1 .在您的情况下,感兴趣的文件(或目录???)是/var/folders/2k/_1tccbln53165lgvzvzt3b480000gp/T/tmprqbtrpspycharm-management/setuptools-18.1 You might want to use chmod or chown to change access permissions to it.您可能想使用chmodchown更改对它的访问权限。

  1. sudo visudo -f /etc/sudoers.d/python

  2. inside the /etc/sudoers.d/python you just created enter these details in the given format <current_username> <hostname> = (root) NOPASSWD: <full path to python> ie mostly you might have creating a virtual env in pycharm when you start a project.在您刚刚创建的/etc/sudoers.d/python中,以给定格式输入这些详细信息<current_username> <hostname> = (root) NOPASSWD: <full path to python>即大多数情况下,您可能在 pycharm 中创建了一个虚拟环境你开始一个项目。 so in that you would find a bin folder.所以你会找到一个 bin 文件夹。 inside which you will find many python virtual interpreters(mention that absolute path ex /home/<project_foldername>/bin/python).在其中你会发现许多 python 虚拟解释器(提到绝对路径 ex /home/<project_foldername>/bin/python)。

  3. anywhere you can create shell script python-sudo.sh你可以在任何地方创建 shell 脚本python-sudo.sh

  4. inside python-sudo.sh mention like this #!/bin/bash sudo <same_path_you_given_in_"/etc/sudoers.d/python"_file> "$@"python-sudo.sh里面提到这样#!/bin/bash sudo <same_path_you_given_in_"/etc/sudoers.d/python"_file> "$@"

  5. Now open your pycharm and project you need to run/debugg the go to setting > project:projectname > Python Interpreter Click on Wheel Icon and Then click on "Add"现在打开你的pycharm和你需要运行/调试的项目去setting > project:projectname > Python Interpreter点击轮子图标,然后点击“添加”

  6. In the new window that popup select Existing Environment > Select the shell script which you created python-sudo.sh .在弹出的新窗口中选择 Existing Environment > 选择您创建的 shell 脚本python-sudo.sh Then click OK > and then Click Apply然后单击 OK > 然后单击 Apply

  7. Make sure that on top right side of editor near to green run button Run/Debug configuration small drop down menu for your file which you are about to execute/debug click on Edit Configuration and the same python interpreter is selected there as well which is python-sudo.sh .确保在编辑器的右上角靠近绿色运行按钮Run/Debug configuration小下拉菜单,您将要执行/调试的文件单击Edit Configuration ,并且在那里也选择了相同的 python 解释器,即python-sudo.sh

  8. Now try executing/debugging, it should work.现在尝试执行/调试,它应该可以工作。

如果您的代码中有shebang,请尝试删除它,然后尝试运行它......顺便说一句,这对我有用。

I had the same issue after changing python directory.更改 python 目录后我遇到了同样的问题。 Then I changed the interpreter setting to a new python directory then 'Run' the code from the Menu and selected 2nd 'Run' option or you can just use the shortcut as Alt+Shift+F10' and a small window appears with your code file name then select the filename which you cant to Run.然后我将解释器设置更改为一个新的 python 目录,然后从菜单中“运行”代码并选择第二个“运行”选项,或者您可以将快捷方式用作 Alt+Shift+F10,然后会出现一个带有代码文件的小窗口name 然后选择你不能运行的文件名。

This resolved my issue!这解决了我的问题!

enter image description here在此处输入图像描述

I encountered the same problem.我遇到了同样的问题。 When I removed the python libs installed out of Pycharm IDE, I found that there is no installation problem.当我从 Pycharm IDE 中删除安装的 python 库时,我发现没有安装问题。 Please use the pip uninstall command.请使用 pip 卸载命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM