Pycharm won't run program

Viewed 2483

I'm learning Python through a youtube tutorial and took a break of over a month to deal with life. When I returned and tried to run a program I created along with the instructor in Pycharm (Community 2020.2.1) it gives me this error in the console:

Error:Cannot run program "/home/user/PycharmProjects/HelloWorld/venv/bin/python" (in directory "/home/user/PycharmProjects/HelloWorld"): error=2, No such file or directory

Except I can browse to /home/user/PycharmProjects/HelloWorld/venv/bin/, and see the "python" file. Running the file by double-clicking on it returns the following error in Pycharm:

Cannot find file '/home/user/PycharmProjects/HelloWorld/venv/bin/python'

When I go to create a new project, the New Project window does not list any interpreter. Is that my issue?

I've tried reinstalling Pycharm and multiple solutions from Stack and other resources without success. I had no issues with Pycharm at all in July. If it matters; this is the Pycharm that's available in the Linux Mint 19.3 Software Manager.

How can I fix this? Why would taking a break cause this issue?

1 Answers

I've just faced the same issue after I upgraded my macOS to Catalina. In a nutshell, you need to restore broken links in venv and the simplest way to do this is to recreate the Python virtual environment for your project.

Here's my step-by-step solution:

  1. In PyCharm go to PyCharm > Preferences... > Project > Python Interpreter

  2. Click on the settings icon on the right upper corner then select "Show All..." in the dropdown menu. "Python Interpreters" window should appear.

  3. Click on the "-" button on the bottom (it shows "Remove" as a hint). Click OK.

  4. Now you should see <No interpreter> on the right side of "Python Interpreter".

  5. Open a terminal. Go to your project folder, find and remove venv subfolder.

  6. Return to PyCharm. Open the same window (PyCharm > Preferences... > Project > Python Interpreter).

  7. Click on the settings icon on the right upper corner then select "Add.." in the dropdown menu. "Add Python Interpreter" window should appear.

  8. Select "New environment", select the correct location (where the removed venv folder was located), select the correct Base interpreter and check "Inherit global site-packages" if your project requires it.

  9. Profit!

Worked for me with PyCharm 2020.2.2 Community Edition.

Related