Repository navigation
Closed
Labels
Description
- Install Python 3.7 from Microsoft Store
- get error on trying to create new virtualenv
Microsoft Windows [Version 10.0.18908.1000]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\jodox>mkdir \temp\example
C:\Users\jodox>cd \temp\example
C:\temp\example>virtualenv .virtualenv
Using base prefix 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1008.0_x64__qbz5n2kfra8p0'
New python executable in C:\temp\example\.virtualenv\Scripts\python.exe
Command C:\temp\example\.vir...v\Scripts\python.exe -m pip config list had error code 1
Installing setuptools, pip, wheel...
Complete output from command C:\temp\example\.vir...v\Scripts\python.exe - setuptools pip wheel:
Traceback (most recent call last):
File "<stdin>", line 10, in <module>
File "C:\Users\jodox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv_support\pip-19.1.1-py2.py3-none-any.whl\pip\_internal\__init__.py", line 19, in <module>
File "C:\Users\jodox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv_support\pip-19.1.1-py2.py3-none-any.whl\pip\_vendor\urllib3\__init__.py", line 8, in <module>
File "C:\Users\jodox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv_support\pip-19.1.1-py2.py3-none-any.whl\pip\_vendor\urllib3\connectionpool.py", line 7, in <module>
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1008.0_x64__qbz5n2kfra8p0\Lib\socket.py", line 49, in <module>
import _socket
ImportError: DLL load failed: Access is denied.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 13, in <module>
ImportError: cannot import name 'main' from 'pip' (C:\Users\jodox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv_support\pip-19.1.1-py2.py3-none-any.whl\pip\__init__.py)
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1008.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1008.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\jodox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts\virtualenv.exe\__main__.py", line 9, in <module>
File "C:\Users\jodox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv.py", line 831, in main
symlink=options.symlink,
File "C:\Users\jodox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv.py", line 1123, in create_environment
install_wheel(to_install, py_executable, search_dirs, download=download)
File "C:\Users\jodox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv.py", line 973, in install_wheel
_install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
File "C:\Users\jodox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv.py", line 1060, in _install_wheel_with_search_dir
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
File "C:\Users\jodox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\virtualenv.py", line 924, in call_subprocess
raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
OSError: Command C:\temp\example\.vir...v\Scripts\python.exe - setuptools pip wheel failed with error code 1
C:\temp\example>pip list
Package Version
---------------- ----------
certifi 2019.3.9
pipenv 2018.11.26
virtualenv 16.6.0
virtualenv-clone 0.5.3
C:\temp\example>
Reacted by Armando Cordova
Activity
gaborbernat commentedon Jun 2, 2019
@zooba this feels like bad packaging on Windows store side 🤔?
JoDoX commentedon Jun 2, 2019
@gaborbernat I think bug in virtualenv, because venv module work fine
gaborbernat commentedon Jun 2, 2019
Not really man. venv provisions the created venv with whatever you have bundled. Here importing the network stack fails (which virtualenv does to install latest pip/setuptools). Pass in a --no-download and virtualenv should also work.
JoDoX commentedon Jun 2, 2019
@gaborbernat I don't want virtualenv, but pipenv use it and no have option to pass args
gaborbernat commentedon Jun 2, 2019
It still boils down to a packaging issue of core, as _socket is not importable 🤔 Will need to validate this though.
gaborbernat commentedon Jun 6, 2019
@pfmoore this seems pip related 🤔 but strangely manifests when called from virtualenv by putting the wheel on the python path 👍
Edit: NM, seems our new virtualenv doesn't have access to _socket, my bad 🤦♂
gaborbernat commentedon Jun 6, 2019
So trying to import _socket on a freshly created virtualenv fails with:
While doing the same from the installed python
Now inspecting the access data for this file:
Looking at this I'm not sure what's this missing 🤔
[-]Not work on Windows 10 with Python 3.7 from Microsoft Store[/-][+]Microsoft Store installed python (3.7 - Windows 10) based virtualenvs cannot access pyd DLLs[/+]pfmoore commentedon Jun 6, 2019
I've never used the Store distribution of Python. I'd suggest asking @zooba for help here, as he's the expert on that distribution.
@JoDoX Can you do a simple test? Start up Python, and run
That should work with no errors. If you get an error, then the issue is with something in Python, rather than with virtualenv (or pip).
gaborbernat commentedon Jun 6, 2019
@pfmoore see my post above. Those commands work if starting it from the installed python. However, they fail from within the virtual environment python. Seems to be related somehow with the fact that the DLLs can be only accessed if run from the installed Python. Once you copy the executable it seems to lose the ability to access the upstream DLLs. Not sure given this the issue is virtualenv or Windows store packaging related.
Edit:
Creating a venv and looking at the startup log shows somehow venvs actually try loading the pyd from the original location. It actually loads everything from the original location. Both Include and Lib are empty. In virtualenv we copy these over for now.... Maybe there's a better way to create venvs than what we have now 🤔 Will need to investigate.
vs
pfmoore commentedon Jun 6, 2019
@gaborbernat Ah, sorry - I skimmed your post and misunderstood what you were saying. My bad.
I certainly wouldn't rule out that copying the Python executable might cause issues. We really need @zooba here, as I'm not aware of any developer-level docs on how the Store build works, and I'm not sufficiently familiar with the code to go diving into it.
zooba commentedon Jun 6, 2019
Yeah, you can't copy the executable. Once it's outside the app package it won't have its context properly activated by the operating system.
You can either symlink it or copy the
python.exethat's invenv/scripts/nt. It's a special copy of the py.exe launcher that will look forpyvenv.cfgto find the actual one to launch. (Or if you don't want to use that file, you can build another version of it that looks for your preferred config settings.)pfmoore commentedon Jun 6, 2019
Somewhat offtopic, but can you point me at the code that makes this be the case (and/or the relevant MS docs on this)? I'd like to understand the store app better than I currently do (I basically understand nothing about MS Store apps at the moment), so I don't have to keep pinging you on this stuff ;-)
zooba commentedon Jun 6, 2019
I'm not sure that this part is even documented, and if it is, it'll probably be deep inside the MSIX docs or possibly in some AppV specifications if you can find that (which is the older version of the isolation technology used).
The packages are meant to be used as apps, primarily, which means a single entry point (and prevent other apps from using our DLLs). So we can't
LoadLibraryfiles in the package until we've verified that we belong to the package, and in the general case the only way to do that is to launch the originalpython.exe.Oh, and to be clear, these are all deliberate, by-design OS restrictions. Python did not choose to make any of this happen, so there's no code in CPython for it. Though the parts of launcher.c hidden behind the
VENV_REDIRECTdefine may be interesting (and unsupported, internal details...)5 remaining items
pfmoore commentedon Jun 10, 2019
Understood. The existing process needs to remain so that Python 2 is supported, but if we can avoid it where core venv is available that's great.
gaborbernat commentedon Jun 10, 2019
Started a separate discussion in #1366 👍
zooba commentedon Jun 17, 2019
Sorry I missed this, @pfmoore (Github notifications don't always get my attention...).
You can install/uninstall the store Python with no side-effects - this is actually one of it's biggest features. (Though a downside of this is that it can't update the real user registry, and so PEP 514 isn't quite sufficient, since overwriting values would break the clean install/uninstall cycle.)
gaborbernat commentedon Jun 18, 2019
I think we talked over Twitter that it would not be an issue of overwrite if per pep 514 we use a different company (e.g. Microsoft Store) instead of PythonCore. And then we just need to update py.exe to accept that too.
neoOpus commentedon Aug 15, 2019
using venv instead of virtualenv solves the issue for me
[-]Microsoft Store installed python (3.7 - Windows 10) based virtualenvs cannot access pyd DLLs[/-][+]microsoft store python support[/+]gaborbernat commentedon Dec 23, 2019
The old virtualenv cannot and will not support this. virtualenv 20, the rewrite, should. We need to validate, sadly AFAIK it's not possible to add the store python to the Azure CI. @zooba can you confirm that this still is the case, and will be going ahead?
gaborbernat commentedon Jan 9, 2020
In first iteration we can just mark the builtin/self-do method not support the store; to check if the python is store pyhton @zooba suggested:
gaborbernat commentedon Jan 21, 2020
This now has been achieved as part of #1502. Virtualenv will correctly mark the store python as not compatible with its builtin strategy and fallback to delegate the task to the venv module of the store python. The test suite of the project passes. Furthermore, now we will use the symlink instead of the copy method if the Windows OS supports it (we test this by trying to create a symlink inside a temp folder).
Built-in support for Microsoft Store within the virtualenv may be done in a future subsequent ticket, probably by improving our cpython3windows class to use the new techniques needed for this.