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

50,459

Solution 1

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.)

Solution 2

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.

Solution 3

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

Therefore, as the attribution of a new path didn't work, I just deleted my .idea, that is automatically loaded each time I open my project's directory.

It automatically regenerated the .idea, asked for the script path... And it worked perfectly

CAREFUL => You will automatically lose your project settings, you are deleting the "settings file"

Solution 4

Set the working directory correctly

1. File-> Settings

2. Build, Execution, Deployment -> Console -> Python Console

3. Working directory: [The path to the directory where the file you're currently working on resides.]

Solution 5

I was getting this same error, and the path in "edit configurations" was correct. However, this is what eventually got my code working again.

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

2) I commented something I knew would compile in the file. (my list of imports)

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

Share:
50,459
R.G.
Author by

R.G.

Programmer, editor and video game fan.

Updated on July 09, 2022

Comments

  • R.G.
    R.G. almost 2 years

    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