PyCharm tells me: "The process cannot start, the working directory ... does not exist"

I saw that this question was asked before (at least twice), but so far I have not found a solution, so I will ask the question again with more detailed information.

Problem

When I run my main python file, PyCharm keeps telling me Cannot start process, the working directory /home/myname/PyCharmProjects/MyProjectName/mypackage does not exist .

When did this error happen?

After I created the mypackage package for testing purposes, moved the files to it (including my main file) and subsequently moved the files to the root folder.

After that, the mypackage package was empty, but PyCharm still believed that the main file ( Main.py ) was in that package. I could still run the program until I removed the empty package, but path errors occurred. After removing the package, I could not start it.

Additional Information

  • I can still run other files that were previously in mypackage and are now in my root directory.
  • I can create and run new files in the root directory
+13
source share
4 answers

After testing a bit, I found a solution (but not an answer to the question why this error occurs in PyCharm):

Delete the file and create it again. (Either rename or move it and create a new file with the old name, both should work.)

+3
source

This is because when you create a file, it automatically assigns a working directory for its configuration, which, of course, is the one where you created it.

You can change this by going to Run → Edit Configurations . Click on the folder icon in the " Script path: field and correct the path to the file. Click OK to save and you can Run file again.

+11
source

I got the same error, and the path to "edit configurations" was correct. However, this is what eventually made my code work again.

1) I commented out all the code in my file ("ctrl" + "a" + "ctrl" + "/")

2) I commented on something that, as I knew, would compile to a file. (my import list)

3) I ran the python file. This time it is actually completely compiled, and after that I was able to uncomment the rest of the code, and it worked again.

+1
source

I had the same problem, mine is probably related to the explanation given by others, it comes from dir .idea , the *.xml contain the $DIR_PROJECT$ variable.

Therefore, since the indication of the new path did not work, I simply deleted my .idea , which automatically loads every time I open the directory of my project.

He automatically restored .idea , asked the path to the script ... And it worked fine

CAUTION => You automatically lose the settings of your project, you delete the "settings file"

+1
source

All Articles