简体   繁体   English

PyCharm 错误:无法运行程序,错误=2,没有这样的文件或目录

[英]PyCharm error: Cannot run program, error=2, No such file or directory

I am getting the following error message when attempting to execute Python code in PyCharm:尝试在 PyCharm 中执行 Python 代码时收到以下错误消息:

Cannot run program "/Users/x/.virtualenvs/untitled/bin/python" (in directory "/Users/x/PycharmProjects/untitled"): error=2, No such file or directory无法运行程序“/Users/x/.virtualenvs/untitled/bin/python”(在目录“/Users/x/PycharmProjects/untitled”中):错误=2,没有这样的文件或目录

I made sure everything was updated and restarted my computer, but I still get the same error.我确保所有内容都已更新并重新启动计算机,但仍然出现相同的错误。 I have no idea what the problem is.我不知道问题是什么。


Edit编辑

I just opened my terminal and was faced with this error message:我刚刚打开我的终端并遇到此错误消息:

virtualenvwrapper_run_hook:12: no such file or directory: /usr/local/bin/python3.7 virtualenvwrapper.sh: There was a problem running the initialization hooks.

If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenvwrapper has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.7 and that PATH is set properly.

I have no idea what happened here.我不知道这里发生了什么。 I certainly didn't touch any of this.我当然没有碰过这些。


Edit 2编辑 2

If I execute Python3 --version , I get Python 3.8.5 .如果我执行Python3 --version ,我会得到Python 3.8.5


Edit 3编辑 3

I followed this , but this error remains:我跟着这个,但这个错误仍然存在:

在此处输入图像描述


Edit 4编辑 4

This is the current state:这是当前的 state:

在此处输入图像描述

I think this is related.我认为是相关的。

If it helps at all this is what my venv settings looks like.如果它有帮助,这就是我的 venv 设置的样子。

I don't have the answer as to why it happens, but I find its usually when renaming the project.我不知道为什么会发生这种情况,但我通常在重命名项目时发现它。

在此处输入图像描述

In the past i've recreated the project and copied the project files directly from the old folder to the new one in a file explorer (not pycharm) and its fixed it.在过去,我重新创建了项目并将项目文件直接从旧文件夹复制到文件资源管理器(不是 pycharm)中的新文件夹,并对其进行了修复。

Probably the root library has been deleted or corrupted.可能根库已被删除或损坏。

I suggest to delete the venv library in explorer and then write the following commands in the terminal我建议在资源管理器中删除venv库,然后在终端中编写以下命令

> C:\Users\MY\PycharmProjects\pythonProject>py -m venv venv
> C:\Users\MY\PycharmProjects\pythonProject>cd venv\Scripts
> C:\Users\MY\PycharmProjects\pythonProject\venv\Scripts>activate

This Error Occurs because when you rename the file you need to update the file path name also...发生此错误是因为重命名文件时还需要更新文件路径名...

.......Solution........... .......解决方案...........

  1. click on Edit Configurations (near the green 'run' play button)单击编辑配置(靠近绿色的“运行”播放按钮)

  2. Where it says 'Script Path' at the end of the string is where you find the name of your file在字符串末尾显示“脚本路径”的位置是您找到文件名称的位置

  3. Change the name to the updated file name将名称更改为更新的文件名

For me, it was the symbolic link in the project.对我来说,它是项目中的符号链接。 Running this command fixed it:运行此命令修复它:

xcode-select --install

You may want to check the contents of the 'activate' script inside your venv.您可能需要检查 venv 中“激活”脚本的内容。 It contains a few hardcoded, absolute paths to files and directories within your environment.它包含一些硬编码的绝对路径,指向您环境中的文件和目录。 If you change something in that environment, eg move a file or directory around, these paths can easily become invalid.如果您在该环境中更改某些内容,例如移动文件或目录,这些路径很容易变得无效。

Similar issues can arise when you, for example, create a virtual environment inside a virtual machine, then open files in PyCharm from outside that machine.例如,当您在虚拟机创建虚拟环境,然后从该机器外部打开 PyCharm 中的文件时,可能会出现类似问题。

This happens in macOs when you upgrade the OS.当您升级操作系统时,这会在 macOS 中发生。 You can get rid of this by running the blow command in your terminal.您可以通过在终端中运行 blow 命令来摆脱这种情况。

xcode-select --install xcode-选择--安装

暂无
暂无

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

相关问题 无法运行程序“ pip --version”(在目录“。”中):error = 2,没有这样的文件或目录 - Cannot run program “pip --version” (in directory “.”): error=2, No such file or directory PYCHARM 错误--java.io.IOException:无法运行程序“python3”:CreateProcess 错误=2,系统找不到指定的文件 - PYCHARM Error-- java.io.IOException: Cannot run program "python3": CreateProcess error=2, The system cannot find the file specified 错误:无法运行ssh:没有此类文件或目录 - error: cannot run ssh: No such file or directory PySpark:无法运行程序“/home/user/venv/bin/python”:错误=2,没有这样的文件或目录 - PySpark : Cannot run program “/home/user/venv/bin/python”: error=2, No such file or directory 无法运行程序(python)没有这样的文件或目录 - Cannot run program (python) No such file or directory 为什么我在 macOS Catalina 下收到错误:Cannot run 'uic': “execvp: No such file or directory” for a PySide2 program? - Why do I get the error: Cannot run 'uic': “execvp: No such file or directory” for a PySide2 program under macOS Catalina? 尝试在 pycharm 中运行简单的 kivy 程序时出错 - Error when trying to run simple kivy program in pycharm Java执行shell命令-错误[无法运行程序“sh”:CreateProcess错误=2,系统找不到指定的文件] - Java execute shell command - error [Cannot run program "sh": CreateProcess error=2, The system cannot find the file specified] 无法在 PyCharm 上运行 python 文件 - Cannot run python file on PyCharm java.io.IOException:无法运行程序“python”(在目录“D:\\Doc\\module\\subject”中):CreateProcess error=2, - java.io.IOException: Cannot run program "python" (in directory "D:\Doc\module\subject"): CreateProcess error=2,
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM