Faur
Faur

Reputation: 5968

Error running 'filename'. The system cannot find the file specified (PyCharm)

I have a PyCharm project on my Windows, where I am able to run most .py files by pressing Ctrl + Shift + F10 (or running the debugger). In one of the files however I get the error

Error running 'test':
Cannot run program  "\opt\anaconda\bin\python" (in directory "..."): CreateProcess error=2, the system cannot find the file specified.`

The test.py file right now only contains print('hello')

I can do this for the other files, and using 'Execute selection in console' also works fine. Given I am on a Windows machine the "\opt\anaconda\bin\python" part looks suspicious, but I don't know how to fix it.

Any help?


Copying the content to another file (e.g. test_2.py) 'fixes' the problem, but since this is a collaborative project this isn't viable.

Upvotes: 6

Views: 34836

Answers (7)

Honey Gourami
Honey Gourami

Reputation: 150

I had the same problem after downloading a project from GitHub. It ended up being a configuration problem. Creating a new project on PyCharm, pasting the code in it, and using your configuration should solve the problem.

Upvotes: 0

Soumeswar Bhuty
Soumeswar Bhuty

Reputation: 1

Just change the directory in Pycharm IDE by editing the file configuration.

Screenshot 1

Screenshot 2

Upvotes: 0

john
john

Reputation: 37

Pycharm project window

This happens when you try to open a .py file instead of an environment. To avoid this error, first, click: File > Open > PycharmProjects > your_environment_name

For example, when you create a Django project, you create an environment first that is a folder including the project and app folder.

Upvotes: 0

rohit01
rohit01

Reputation: 111

when I installed the pycharm I had the same issue. for this, you really need to understand the concept of the virtual environment. this error comes because you run the file in another directory in which you do not create any virtual environment. let's say you create a virtual environment in any folder located at the desktop now you run the files in any other folder located in /user/AppData/any_folder then it will show the error that the system can't find the file specified. So be sure you run in a file in the same folder in which you created a virtual environment.

Upvotes: 1

kingmi
kingmi

Reputation: 51

This is what I had to do:

  • Check the .idea/workspace.xml for any old venv references (there are several tags like "SDK_HOME" which store the path to the venv) and update as necessary
  • Check the .idea/RunConfigurations for any run configs and update them (or delete and recreate as you like)

Upvotes: 1

Alireza Mazochi
Alireza Mazochi

Reputation: 977

I had the same problem in PyCharm IDE and Windows after adding new libraries and some changes.

I recreated Run/Debug Configurations with these steps (Instead of recreating the whole of project!):

  1. Select Edit Configurations... from top panel in PyCharm IDE enter image description here

  2. Select these files and press delete for deleting them enter image description here

  3. Recreate these files likes this images:

    Click green arrow or press Ctrl + Shift + F10

enter image description here

Upvotes: 1

Ferom
Ferom

Reputation: 71

I think your case is cause by some project environment has changed. I suggest your open the workspace.xml which located in .idea\, check the parameters in it.

or you can delete the directory ".idea" and re-create the project locate in the original path.

Hope it work

Upvotes: 7

Related Questions