"Cannot start process, the working directory … does not exist" error in PyCharm

Question:

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

This error occurred after creating a package (mypackage) for test purposes, moving files to it (including Main.py), and moving the files back to the root folder afterwards.

The package mypackage was empty after that, but PyCharm still thought that 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.

  • 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.
Asked By: R.G.

||

Answers:

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

Answered By: R.G.

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.

Answered By: Guest

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.

Answered By: engineer1221

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”

Answered By: Nqsir

The issue kept popping up over and over in PyCharm. So I created a new project and loaded the needed script. Then I provided the directory to path and assigned the default Python version that I wanted to use… and it worked. Then I was able to finally use “execute line in console” once again.

Answered By: Oleg Ban

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

Answered By: victorkolis

I had this problem because I renamed my project, it was "xx" I renamed it to "yy", what I did was I went through the directory of .idea in the "yy", in any of those files (all XML files) if there were the name "xx", I replaced it with "yy"

Answered By: Babak Akbarzade

I experienced this problem after moving my project to a different root directory. None of the above solutions worked for me.

I solved it by opening my entire project folder, instead of just the python file I was trying to run. And then running the file I wanted, while the entire project was loaded into PyCharm.

Answered By: Sheldonfrith

open the qtdesigner work dictionary setting and choose your project path then click OK, don’t not use the mysterious work dictionary path by default

Answered By: yunfei bai

In my case Run -> Edit Configuration didn’t help.
I’ve solved it changing the value of "WORKING_DIRECTORY" attribute in .idea -> workspace.xml

<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/your/correct/path/here" />

Answered By: Marcel

I am a beginner so appreciated this 6 year and 6 month discussion. I couldn’t add a comment. I setup PyCharm 2022.1.1 and a Python 3.10.4 virtual environment with pyside2 and pyside6 on Ubuntu 22.04. I tried all the suggestions above and could get none of them to work for me. Following these instructions: https://pythonpyqt.com/how-to-install-pyqt5-in-pycharm/ both pyside2-designer (Qt5Designer) and pyside6-designer from my virtual environment were added as external tools. pyside2-designer failed with the working directory error and pyside6-designer worked without any error. Looking closer at pyside2-designer selecting the working directory with the browse button, I still could not create file – exit code was 127 – but the Qt5 Designer was available for existing ui files. I used pyside2 because PyQt5-tools could not be pip installed in my python3.10.4 virtual env.

Answered By: Sildeag

This worked for me on PyCharm 2021.3.2:

enter image description here

Answered By: Contango
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.