Python3.7 Venv Does Not Create Virtual Environment Directory
Solution 1:
It should work, I tested it several times (e.g.: [SO]: PyWin32 (226) and virtual environments). And yes, they are 2 different kinds of animals:
Example:
e:\Work\Dev\StackOverflow\q059885771>sopr.bat *** Set shorter prompt to better fit when pasted in StackOverflow (or other) pages *** [prompt]> set PY PYTHONPATH=e:\Work\Dev\Utils\current [prompt]> dir /b [prompt]> "c:\Install\pc064\Python\Python\03.07.06\python.exe" -c "import sys, venv;print(sys.version);print(venv)" 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] <module 'venv' from 'c:\\Install\\pc064\\Python\\Python\\03.07.06\\lib\\venv\\__init__.py'> [prompt]> "c:\Install\pc064\Python\Python\03.07.06\python.exe" -m venv usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] ENV_DIR [ENV_DIR ...] venv: error: the following arguments are required: ENV_DIR [prompt]> time<nul The current time is: 21:51:57.12 Enter the new time: [prompt]> "c:\Install\pc064\Python\Python\03.07.06\python.exe" -m venv ".\venv_dir" [prompt]> echo %errorlevel% 0 [prompt]> time<nul The current time is: 21:52:10.54 Enter the new time: [prompt]> [prompt]> dir /b venv_dir [prompt]> "venv_dir\Scripts\python.exe" Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> ^Z [prompt]>
Notes (things to pay attention to):
- Make sure that things are actually what you think they are: use full paths (like I did for the Python executable). To see what interpreter is invoked in your case, type
where python3
in the console- Might also apply this to the environment directory
- Enclose paths in dblquotes ("${SOME_PATH}"), as they might contain spaces (and the command interpreter will interpret the part after the SPACE as an argument to the one before)
- Check the command return code
- Check environment variables (e.g.: PYTHONPATH) that might impact the behavior
- Of course, Python should be valid (no errors encountered during installation, no files deleted / modified afterwards, ...)
When all the above checks pass, you should be able to create and use a (venv created) virtual environment.
Update #0
I took a look at the URL added in the question: [SuperUser]: Typing “python” on Windows 10 (version 1903) command prompt opens Microsoft store (mentioning @Update, @TusharGautam, @MattJecha, @Ramhound great answers, containing useful info and resources).
Apparently, it is because of the 2 App Installer related items from App execution aliases. Then I went further, and also installed Python 3.7 from Microsoft Store. Both (App Installer and Python 3.7) place some items (including executables) in "%USERPROFILE%\AppData\Local\Microsoft\WindowsApps". The funny thing is that they are 0 bytes sized, and they are neither shortcuts nor symlinks. I tend to think they don't actually exist on the filesystem, but are some kind of "mock entries" that Win displays and acts as if they would be real (the same thing MS did when displaying the .NET assemblies (which are basically .dll files) as directories in Windows Explorer).
In the image below, I chose the 2 boxed items as examples:
When checking one, the other gets automatically unchecked, which makes sense as both point to the same "executable" (python3.exe).
[prompt]> :: Python3.7 (python3.exe - installed from Microsoft Store) checked [prompt]> dir "c:\Users\cfati\AppData\Local\Microsoft\WindowsApps\py*" Volume in drive C is SSD0-WIN Volume Serial Number is F2CE-FA29 Directory of c:\Users\cfati\AppData\Local\Microsoft\WindowsApps 20/01/24 12:32 0 python3.exe 20/01/24 12:12 <DIR> PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0 1 File(s) 0 bytes 1 Dir(s) 197,737,488,384 bytes free [prompt]> python3 -c "import sys, os;print(\"VER: {0:}\nEXE: {1:}\nCWD: {2:}\nPyPATH: {3:}\".format(sys.version, sys.executable, os.getcwd(), sys.path))" VER: 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 01:54:44) [MSC v.1916 64 bit (AMD64)] EXE: C:\Users\cfati\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe CWD: e:\Work\Dev\StackOverflow\q059885771 PyPATH: ['', 'e:\\Work\\Dev\\Utils\\current', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\\python37.zip', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\\DLLs', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\\lib', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\\lib\\site-packages'] [prompt]> echo %errorlevel% 0 [prompt]> [prompt]> :: App Installer (python3.exe) checked [prompt]> dir "c:\Users\cfati\AppData\Local\Microsoft\WindowsApps\py*" Volume in drive C is SSD0-WIN Volume Serial Number is F2CE-FA29 Directory of c:\Users\cfati\AppData\Local\Microsoft\WindowsApps 20/01/24 12:35 0 python3.exe 20/01/24 12:12 <DIR> PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0 1 File(s) 0 bytes 1 Dir(s) 197,737,291,776 bytes free [prompt]> python3 -c "import sys, os;print(\"VER: {0:}\nEXE: {1:}\nCWD: {2:}\nPyPATH: {3:}\".format(sys.version, sys.executable, os.getcwd(), sys.path))" Access is denied. [prompt]> :: !!! "This app can't run on your PC" popped up !!! [prompt]> echo %errorlevel% 5
As a note, the executable ("C:\Users\cfati\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe") is also a "mock entry", the real one is actually located in "%ProgramFiles%\WindowsApps"
From [MS.DevBlogs]: Who put Python in the Windows 10 May 2019 Update? (emphasis is mine):
While Python continues to remain completely independent from the operating system, every install of Windows will include
python
andpython3
commands that take you directly to the Python store page.
So, there you go, python3is not actuallypython3 (of course, appplies to python as well). The funny thing is that in your case it "worked", while in mine it complained (ERROR_ACCESS_DENIED).
Conclusions:
- I must insist on always using the full paths. That way you are not impacted by changes happening in the OS (well, your files might get deleted or corrupted, but then you'd have bigger issues)
- Specifying the full path every time, would soon become very annoying, that's why the PATH environment variable could / should be used. Of course, this works fine (and significantly improves the experience) in probably 90+% of the cases, but there are some (for example when other installed apps / tools that also ship Python, add their dirs into PATH) where it can trigger funny results
Solution 2:
Make sure you're in Admin mode (Windows+X button > PowerShell(Admin) > click YES); this should take you to
PS C:\WINDOWS\system32>
move to where you installed your Python. then type the following:
python -m venv C:\<your-existing-project-directory>\<venv-name-u-want-to-use>
VENV will create that a directory inside the C:\
For more info: https://docs.python.org/3/library/venv.html
Post a Comment for "Python3.7 Venv Does Not Create Virtual Environment Directory"