Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm tells me "Cannot start process, the working directory ... does not exist"

I've seen this question being asked before (at least twice), but I haven't found a solution so far, so I'll ask the question again with some more details.

The Problem

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

When did this error occur?

After I created a package mypackage for test purposes, moved files to it (inluding my main file), and moved the files back to the root folder afterwards.

The package mypackage was empty after that, but PyCharm still thought that the main file (Main.py) is located in that package. I could still run the program until I deleted the empty package, but path errors occurred. After deleting the package, I was unable to start it.

Additional Info

  • I can still run the other files that used to be in mypackage and are now in my root directory again
  • I can still create and run new files in my root directory
like image 785
R.G. Avatar asked Oct 20 '15 06:10

R.G.


People also ask

How do I add a directory to PyCharm?

Create directoriesSelect File | New | Directory. Select New | Directory from the context menu. Press Alt+Insert and select Directory.

How do I change the default working directory in PyCharm?

button in the submenu appearing when clicking on your currently selected run configuration in the top right of PyCharm, you are able to edit the fields (and therefore also the working directory) of Python run configurations by selecting Python from the Templates (also called Defaults in versions pre-2018) and ...

How do I change the working directory in PyCharm terminal?

Press Alt+Right and Alt+Left to switch between active tabs. Alternatively, you can press Alt+Down to see the list of all terminal tabs.


2 Answers

It happens because when you create a file it automatically assigns the working directory to it's configuration, which of course is the one where you created it.

You can change that by going into Run -> Edit Configurations. Click on the folder icon in Script path: and correct the path to the file. Click OK to save and you should be able to Run the file again.

like image 109
Guest Avatar answered Sep 20 '22 03:09

Guest


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

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

like image 37
R.G. Avatar answered Sep 20 '22 03:09

R.G.