4

I found similar posts, mostly related to linux on venv having an issue with working. python 3.8 venv missing activate command However, I am confused on how to solve it on windows, and what is happening.

I installed python3.8 from downloading it on pythons website. Then I follow the 3.8 documentation https://docs.python.org/3/library/venv.html which shows:

python3 -m venv /path/to/new/virtual/environment

I do this but then get the following error:

Error: Command '['E:\\py_envs\\hf4\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 101.

When I use: python -m venv --without-pip hf4

and then hf4\Scripts\activate

It works for activation. What I don't understand is that I can then run pip and it is there during the activated environment. It seems a maybe related issue, is that anything I have installed on my system python is also available. For example, in the activated session:

(hf4) E:\py_envs>where pip
C:\Users\local user\AppData\Local\Programs\Python\Python38\Scripts\pip.exe

One question is naturally how to fix this, the other is that I would appreciate an explanation as to what is happening to better understand it. Does it search first for the active environment, and if it can't find it, defaults to a system version?

001001
  • 327
  • 2
  • 11
  • [This](https://stackoverflow.com/questions/26215790/venv-doesnt-create-activate-script-python3) contains many different solutions (yes, it's for Ubuntu, but minimal adjustments are needed for it to work for Windows 10). – Nemanja Mirić May 06 '20 at 18:35
  • @NemanjaMirić these are the same answers; someone saying 6 years ago ubuntu shipped with a broken version. I also found the same question without an answer https://stackoverflow.com/questions/61371606/returned-non-zero-exit-status-101-giving-an-error-when-i-tried-create-a-virtual . Is it really 6 years with this issue across platforms existing and the python docs pretends like it works? – 001001 May 06 '20 at 18:45
  • It's not an issue across platforms, it's something on your end. I'm not sure which answers you are referring to when you say "these are the same answers", the URL you linked contains only one answer, while the one I linked contains multiple which may have been of help. – Nemanja Mirić May 06 '20 at 21:29
  • 1
    @NemanjaMirić those didn't work either for me, even trying to start a python terminal in venv doesn't work. I uninstalled, deleted any remaining python folders, and reinstalled the latest python and still have the same problem. Also just to clarify, I was trying to make the point that (admittedly looking back, it was more aggressive than I would like) those old answers on a different OS are not helping me understand exactly what the problem is on my system. – 001001 May 06 '20 at 22:17

3 Answers3

7

I had the same problem (with both Python 3.7 and 3.8), I believe it was due to a Windows update when I enrolled in the Windows Insiders program, but that could have just been a coincidence.

PS C:\Users\Your Name\AppData\Local\Programs\Python\Python38> ./python -m venv c:\TEMP\py38-venv
Error: Command '['c:\\TEMP\\py38-venv\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 101.

This worked around the problem in my case:

  • Uninstall Python.
  • Install with the Custom option.
  • Use the "Install for all users".

Install for all users

After this it worked fine:

PS C:\Utilities\PythonBase\Python38> .\python -m venv c:\temp\venv-py38
PS C:\Utilities\PythonBase\Python38>

Of course you'll have to go through and fix any venvs you've been using, but if you're in the same situation as me they won't have been working anyway.

tttjj
  • 158
  • 7
  • 1
    Wow, even though its a month later, I had literally given up on the problem and just ran it on another computer. This actually solved it. For others, there is also one menu before this one. When you click "Custom" it had a menu without "Install for all users", you have to click next. Also, the main menu says "Install for all users" which I had been doing, but it seems this location of that box changes the install directory. Thank you! – 001001 Jun 05 '20 at 19:14
2

Thanks. I faced the same issue and this thread worked around for me. I uninstalled Python and installed 3.9. Python version (which was available for me at the time) checking "Install for all users" in advanced installing. Remember to check "Add the PATH" box so that you can run Python from the command prompt.

1

I unistall all newest version and reinstall python 3.7.9 checking "install for all users" option on instalation, try again to create a project.

Navas Ema
  • 61
  • 3