4

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.

Malkhafa
  • 43
  • 1
  • 4

1 Answers1

20

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.

kesh
  • 4,515
  • 2
  • 12
  • 20
  • It worked!!! Thank you very much! Sadly, I'm new so I cannot upvote your answer. – Malkhafa Feb 10 '22 at 01:55
  • 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 – kesh Feb 10 '22 at 02:10
  • god bless, i've been searching forever – Azael Jan 18 '23 at 00:50
  • you are an absolute hero I've been looking everywhere for a solution to this problem –  Feb 18 '23 at 10:33
  • 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. – Alex Apr 12 '23 at 12:38