Search code examples
pythonvirtualenv

Unable to create process using '...\python.exe' | error in virtual environment


I'm unable to use python within the virtual environment. Python works fine outside of the virtual environment. I'm using Python 3.10.2

I keep on getting the error below when trying to run any python commands.

'C:\Users\User\AppData\Local\Programs\Python\Python310\python.exe'

It might be relevant to mention that I was unable to create the virtual environment through the 'python -m venv env' command. Error generated was

Error: Command '['C:\\Users\\User\\Documents\\Python Projects\\PDFtoText\\env\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 101.

I had to add 'without-pip' to the end of the command to create the virtual environment. Weird thing is, I was able to use pip within the virtual environment without having to manually install it.

The path to python is in the environmental variables.

I tried reinstalling python but that did not help.

Lastly, all these errors started occurring after I downloaded Visual Studio Community 2022.


Solution

  • Short answer, I bet you have a space in your Window's account name (say Your Account is where your account is saved so you have C:\Users\Your Account folder, and there is also a text file C:\Users\Your ("Your" being the first part of your user name). MSVS2022 (maybe earlier versions, too) is known to leave this log file which exposes a bug in Python venv's python launcher. Delete this text file, and your problem should be solved.

    See my question/answer for more details.