30

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.

Laura López
  • 471
  • 1
  • 4
  • 12
  • 4
    When you open a project open the directory not a specific python file. Instead of ~/Documents/myProject/main.py open ~/Documents/myProject – user1068430 Feb 17 '15 at 15:53

10 Answers10

32

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

chiffa
  • 2,026
  • 3
  • 26
  • 41
  • 4
    To anyone for which this is not obvious (like me), this will also reset all of your editor preferences. FYI. – wst Aug 28 '17 at 00:54
  • @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... – chiffa Aug 28 '17 at 03:27
  • Window config, inspections, and several others are all stored in the project by default. – wst Aug 28 '17 at 18:45
  • @wst - sorry to hear that, I moved most of my configs out and didn't realize that. – chiffa Aug 28 '17 at 18:58
  • 1
    Another warning, updating Python Interpreter takes ages after removing the .idea folder... – m-dz Dec 12 '17 at 11:52
32

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

Megamind
  • 333
  • 1
  • 3
  • 6
14

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.

Laura López
  • 471
  • 1
  • 4
  • 12
  • 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. – Tanya Branagan Aug 11 '18 at 18:54
9
  • 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.

Alice Vixie
  • 422
  • 4
  • 10
2

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.

Mike49
  • 473
  • 1
  • 5
  • 17
1

I solved this by replacing all instances of the old filename and old directory with the new one in .idea/workspace.xml

It can be done with PyCharm running.

Tanner
  • 630
  • 1
  • 7
  • 20
1

@user1068430 has the answer in the comments to the question:

When you open a project open the directory not a specific python file. Instead of ~/Documents/myProject/main.py open ~/Documents/myProject

If you "open" the .py file then you'll have to set the working directory (File > Settings > Build, Execution, Deployment > Console > Python Console > Working Directory) every time. If you "open" the directory containing the .py file, then PyCharm will open and all of your .py files will be available in the left window. Select one of them and you're good to go.

Mark Cramer
  • 2,614
  • 5
  • 33
  • 57
1

i had the same issue, the error comes up when i want to upgrade my packages and when i run my project "this FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\youruser\AppData\Local\Temp\gen_py\3.7\__init__.py'" i found that the Temp file in C:\Users\youruser\AppData\Local was corrupt and it was fixed by deleting the "Temp" file, once deleted it will automatically create a new one with "gen_py" in it

Zeus
  • 11
  • 2
  • 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 – BHA Bilel May 29 '20 at 04:56
0

To anyone with similar issues: Python interpreter virtual environment is where your python.exe sits. The working directory is where your script sits. To make everything easier, open a new project, scroll to location where you script is stored, and select. Click the interpreter option, click existing (if old one worked) or choose the python.exe. When asked, open the project in a new window, close old one to avoid confusion. source = banging my head against the console for past few hours.

El_1988
  • 339
  • 3
  • 13
0

if the above mentioned solutions are not working, you can restart a new project. file > New project... then, create a new project.