'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:

Cannot run program "/Users/x/.virtualenvs/untitled/bin/python" (in directory "/Users/x/PycharmProjects/untitled"): error=2, No such file or directory

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

If I execute Python3 --version, I get Python 3.8.5.


Edit 3

I followed this, but this error remains:

enter image description here


Edit 4

This is the current state:

enter image description here

I think this is related.



Solution 1:[1]

If it helps at all this is what my venv settings looks like.

I don't have the answer as to why it happens, but I find its usually when renaming the project.

enter image description here

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.

Solution 2:[2]

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

> 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

Solution 3:[3]

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

Solution 4:[4]

For me, it was the symbolic link in the project. Running this command fixed it: xcode-select --install

Solution 5:[5]

This happens in macOs when you upgrade the OS. You can get rid of this by running the blow command in your terminal.

xcode-select --install

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lewis Morris
Solution 2 Wai Ha Lee
Solution 3 user15015004
Solution 4 Jason T
Solution 5 Vikrant Vishwakarma