Working directory error

56,066

Solution 1

I finally solved the problem.

I think it all started because the first project that I opened with pycharm was in my "download" folder, so the working directory was automatically set to a temporal folder by default and allthough I moved the project to another folder and I manually changed the working directory from the terminal, it was not working.

The solution was creating a new project and giving a correct path to the new project. It seems very easy but it was not that obvious.

Solution 2

Another solution is to close the project, run rm -rf .idea and re-open it. Apparently Pycharm gets confused by some direct folder manipulation and doesn't reflect it properly in his .idea/*.xml files

Solution 3

I also got this error, and it got resolved by setting the default working directory. Follow the below path, and set the Working Directory to the folder where your code resides.

File > Settings > Build, Execution, Deployment > Console > Python Console > Working Directory ...

Solution 4

  • In the upper right corner click on small next to your main to run (look to the left from green right-pointing triangle)
  • Select Edit configurations.
  • In ▼ Python select the proper configuration name.
  • Look at the Configuration panel.
  • Fix items Script and Working directory.

Solution 5

I had this same problem and just had to reinstall pycharm. It's a quickfix and I can't ensure it won't happen again.

Share:
56,066
Laura López
Author by

Laura López

Updated on February 17, 2022

Comments

  • Laura López
    Laura López over 2 years

    I am working with PyCharm 4.04. Since I installed it, every time I open it, as default directory I get this:

    C:\Users\Laura\AppData\Local\Temp\main.py1.tmp>cd

    Which gives me an error when trying to use the console:

    Error:Cannot start process, the path specified for working directory is not a directory

    But even if I change the directory, the message does not disappear.

    The terminal, though, it does work and I can run projects, but I would like to use the console.

  • su79eu7k
    su79eu7k about 8 years
    This is proper solution. You don't need to create project on every file.
  • Kumar Sambhav Pandey
    Kumar Sambhav Pandey almost 7 years
    Fairly easy and straightforward.
  • wst
    wst almost 7 years
    To anyone for which this is not obvious (like me), this will also reset all of your editor preferences. FYI.
  • chiffa
    chiffa almost 7 years
    @wst only if you are storing them in the project's .idea. Usually it blows up only interpreter and the bookmarks; other properties and configs tend to be stored elsewhere...
  • wst
    wst almost 7 years
    Window config, inspections, and several others are all stored in the project by default.
  • chiffa
    chiffa almost 7 years
    @wst - sorry to hear that, I moved most of my configs out and didn't realize that.
  • m-dz
    m-dz over 6 years
    Another warning, updating Python Interpreter takes ages after removing the .idea folder...
  • Tanya Branagan
    Tanya Branagan almost 6 years
    This was the answer for me, I downloaded a project and no matter that I moved the py file and changed the working directory, it was still referencing the temp folder.
  • BHA Bilel
    BHA Bilel about 4 years
    Hello, thanks for your answer, i have a similar problem but i don't have the file you're talking about. I'm trying to access a file inside my project, when i enter the correct path is gets transformed into ".../appdata/local/temp/..." instead of the given path, however, non existing path/file would stay the same ! any help would be appreciated
  • Mianen
    Mianen over 3 years
    After a restart of Pycharm this solution worked for me as well. I needed to set both Working Directory and Interpreter in the settings Megamind mentions.