10

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.

The Pointer
  • 2,226
  • 7
  • 22
  • 50
  • This happens to me when I rename the project after creating it as untitled. Try creating a new environment or sometimes I just start the project again if the amount of code is small and copy the old code into the new project – Lewis Morris Aug 03 '20 at 04:04
  • @LewisMorris I am now getting the following error: `Cannot retrieve the version of the detected SDK: /usr/local/bin/python3.7` – The Pointer Aug 03 '20 at 04:07
  • I just opened my terminal and was faced with a big error message. See my edit. – The Pointer Aug 03 '20 at 04:08
  • Have you tried navigating to this folder. Is it valid? Do you find the python runtime in there? If not try using an existing interpreter, pointing it to the correct folder, or creating a new venv – Lewis Morris Aug 03 '20 at 05:00

6 Answers6

4

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.

Lewis Morris
  • 1,916
  • 2
  • 28
  • 39
4

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

1

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
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
0

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

xcode-select --install
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
0

You may want to check the contents of the 'activate' script inside your venv. It contains a few hardcoded, absolute paths to files and directories within your environment. If you change something in that environment, e.g. 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.

Sandor
  • 76
  • 4
0

For me, the problem was that I created the virtual environment through the PyCharm settings and ticked "Inherit global site-packages", I think. Once I removed the virtual environment and created it using the old fashioned way, i.e.

mkvirtualenv projectname --python=python3.10

everything fell into place.

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197