7

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.

1 Answer 1

31

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.

Sign up to request clarification or add additional context in comments.

5 Comments

It worked!!! Thank you very much! Sadly, I'm new so I cannot upvote your answer.
Glad to hear! I think you can still accept my answer on your own question (that is, the answer we are commenting on) Appreciate it if you would
god bless, i've been searching forever
you are an absolute hero I've been looking everywhere for a solution to this problem
Scratching my head as to why my 3.9.x virtualenv wasn't working but my 3.10.x was fine. This was why - I had just installed Microsoft c++ build tools. I had more than one text file with a name beginning "Your" in my C:\Users directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.