C:\Program Files\Python311\python.exe: can't open file 'C:\\Program': [Errno 2] No such file or directory

When i try to debug my project I am seeing the following error.

```

 * Serving Flask app 'app'
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
 * Restarting with stat
C:\Program Files\Python311\python.exe: can't open file 'C:\\Program': [Errno 2] No such file or directory

Process finished with exit code 2

```

Debugging till the point where this error shows up on the console, i have discovered that python subprocess Popen() cannot work with paths that have spaces in them like "C:\Program Files"

I am not 100% sure about this because it is difficult to debug built in library subprocess.

Debugging the project worked fine earlier. It started breaking all of a sudden.

13

I'm using Python 3.10 and started getting this error today.

5

Pycharm has shipped a faulty product

2

you will need to install pycharm in such a way that there are no spaces in the path to pydev.py

Mine was C:/Program Files/PyCharm Community Edition/plugins/python-ce/helpers/pydev/pydevd.py

there was spaces in Program Files/PyCharm Community Edition/...

i have now installed pycharm in such a way that there are no spaces

C:/Users/<user>/PyCharm/plugins/python-ce/helpers/pydev/pydevd.py

1

Another workaround:

I created a directory junction.

mklink /J C:\PyCharm "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2022.3.2"

And then run PyCharm at C:\PyCharm\bin\pycharm64.exe

13

Juangabriel's answer steered me in the correct direction.  After I created the junction (Community Edition 2023.1), I took one more step of edited the desktop shortcut to have a target of C:\PyCharm\bin\pycharm64.exe.  I used to have to do this back in my Java days, too.  I guess every version upgrade I'll just have to go back and update the junction to point to the newer directory.

1

I'm using Python 3.11 and started getting this error today.
Updated the PyCharm version to: PyCharm 2023.1.4 this morning and the problem is still not resolved.

 

2

Same issue on Community Edition

PyCharm 2023.1.4 (Community Edition)
Build #PC-231.9225.15, built on July 11, 2023
Runtime version: 17.0.7+10-b829.16 amd64

0

Have the same problem. Directory junction helped. 

1

Downgrading Flask and Werkzeug from 2.3.2 to 2.0.3 fixed the problem for me.

0

I uninstalled pycharm and installed it in a path without space (C:\Users\Administrator\AppData\Local\Programs\Pycharm), all went well.

By the way, manually installed pycharm can also be recognized by jetbrains toolbox.

0

PyCharm 2023.1.4 (Community Edition)
Build #PC-231.9225.15, built on July 12, 2023
 

I reinstalled my pycharm this version to space less path “C:\Users\syedh\PyCharm Community Edition 2023.1.2”

Still getting same error. What am i missing?
I am JS developer, start python flask project 1 week ago.

 

 

0

Hasanbadsha creating a directory junction to the source of PyCharm worked out for me. Just as Juangabriel Lorenzo wrote.

1. Open cmd.exe.

2. Run `mklink /J C:\PyCharm "C:\Path\To\Your\PyCharm Community or Professional Edition 2022.3.2"`

3. Run pycharm `C:\PyCharm\bin\pycharm.bat`.

Perhaps symlink could also work, but i didn't test it.

1

I solved the problem by following this link: https://stackoverflow.com/a/44668958/3670782

1. use `mklink` command created link path.

2. change flask parameter debug=True to debug=False

 

4

Had the same problem and Wildr Slimshady 's solution worked! Thanks

0

Downgrading Flask and Werkzeug from 2.3.2 to 2.0.3 fixed the problem for me.

Dominik G solution worked for me. Thanks.

- PyCharm 2023.3.3 Community 
- Python 3.12.

0

I encountered this issue today. Closing PyCharm then going to `AppData\Local\Programs\Pycharm Professional` and removing the space solved the issue for me.

It blows my mind that this is a) still an issue on Windows and that b) software companies don't take it into account.

1

Happened after the lastest update, I switched to VScode, for debugging. This is mildly said shooting yourself in both legs. 
Changing the path was detected only for the community edition but not for Professional. This is small stupid issues that rage-quits people.

2

There are 3 things I noticed that fixed this issue.

1) I navigated to the application settings in toolbox (image below).  Toolbox was complaining of the scripts folder not being found.  (it was highlighted red before I fixed it, but I didn't take a screenshot)

On investigating, I noticed that Toolbox had totally failed to find the directory (at all), which I manually located for it. “%AppData%\Local\JetBrains\Toolbox\scripts”

Upon rerunning the debugger on my app.py file, I was given another error leading me to (2).

2) The directory that Toolbox created on install inside “%AppData%\Local\Programs\PyCharm Professional” was NOT named “PyCharm” (which is what it was looking for).  I changed its name to just “PyCharm”.


Again, rerunning the debugger threw yet another error, which led to item (3)

3) The directory where my project was located had spaces in the directory name (it was in an automagically created OneDrive folder).  Removing them then finally fixed all the issues with the debugger.

 

NOTE: I did not have to create a symlink for this to work.   Running the newest version of pycharm (today). Running a Flask web server.

0

Create a path for pycharm in environment vars like that:

C:\\\Program Files\\JetBrains\\PyCharm Community Edition 2023.3.4\\bin

This work to me.

0

请先登录再写评论。