Repository: pyinstaller/pyinstaller
Pull request: Remove support for python from the windows store
When using python from the windows store with PyInstaller, there are permissions errors that require a major mod to the UAC system in the underlying windows kernel to work around. 

It's caused by the `WindowsApps` directory, which, for security reasons, even when running as *admin* you can't even *read* the directory. This means that when PyInstaller trys to copy the python DLLs and libraries, it fails. You can work around this, but the method risks jailbreaking if done improperly, which can void warranty. 

This can be "fixed" by saying that we don't support that build of python. (Note that that is actually standard CPython)

Closes #4507 

Problem statement:
pyinstaller can't use at Windows-10-10.0.18362-SP0
I also try pyinstaller3.5 and PyInstaller: 4.0.dev0 
it didnt work
64 INFO: PyInstaller: 4.0.dev0+a9b299995
65 INFO: Python: 3.7.5
66 INFO: Platform: Windows-10-10.0.18362-SP0
69 INFO: wrote D:\python_code\arbor_api_test\Arbor_api_proflieing.spec
70 INFO: UPX is not available.
76 INFO: Extending PYTHONPATH with paths
['D:\\python_code\\arbor_api_test', 'D:\\python_code\\arbor_api_test']
76 INFO: checking Analysis
76 INFO: Building Analysis because Analysis-00.toc is non existent
78 INFO: Initializing module dependency graph...
81 INFO: Caching module graph hooks...
88 INFO: Analyzing base_library.zip ...
2823 INFO: Caching module dependency graph...
2918 INFO: running Analysis Analysis-00.toc
Traceback (most recent call last):
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\pywin32\pywintypes.py", line 35, in pywin32error
    yield
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
    return _dll._LoadLibraryEx(fileName, 0, flags)
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\core\ctypes\_util.py", line 42, in check_null
    raise make_error(function, function_name)
OSError: [WinError 1920] 系統無法存取該檔案。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.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.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\__main__.py", line 112, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\building\build_main.py", line 732, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\building\build_main.py", line 679, in build
    exec(code, spec_namespace)
  File "D:\python_code\arbor_api_test\Arbor_api_proflieing.spec", line 17, in <module>
    noarchive=False)
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\building\build_main.py", line 242, in __init__
    self.__postinit__()
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\building\build_main.py", line 393, in assemble
    redirects=self.binding_redirects)[1:])
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\depend\bindepend.py", line 226, in Dependencies
    for ftocnm, fn in getAssemblyFiles(pth, manifest, redirects):
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\depend\bindepend.py", line 402, in getAssemblyFiles
    for assembly in getAssemblies(pth):
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\depend\bindepend.py", line 353, in getAssemblies
    res = GetManifestResources(pth)
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\utils\win32\winmanifest.py", line 1005, in GetManifestResources
    return winresource.GetResources(filename, [RT_MANIFEST], names, languages)
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\utils\win32\winresource.py", line 168, in GetResources
    hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE)
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
    return _dll._LoadLibraryEx(fileName, 0, flags)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Users\miku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
    raise error(exception.winerror, exception.function, exception.strerror)
win32ctypes.pywin32.pywintypes.error: (1920, 'LoadLibraryExW', '系統無法存取該檔案。')
系統無法存取該檔案。means 'system cannot access the file'

Hints from issue discussion:
@mikumiku2468 Do you have a minimum example for us to reproduce this with? From the title of the Issue, it sounds like you think this is an issue caused by the version of Windows you are using, do you have some reason to suspect that?
I forgot to say 
I have two computer
ver 1903 build number 18362.418  doesn't work 
but
ver 1803  build number 17134.950 is work
so I think is os problem 

我也遇到了这个问题
我是win10 1903
我的解决方法是：

```
# 第一个地方
# 根据错误信息提示找到"win32api.py"文件
# 修改大约40行
def LoadLibraryEx(fileName, handle, flags):
    # 添加这一行,改为你的python路径
    fileName = r"C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\python.exe"
    if not handle == 0:
        raise ValueError("handle != 0 not supported")
    with _pywin32error():
        return _dll._LoadLibraryEx(fileName, 0, flags)


def EnumResourceTypes(hModule):
```

```
# 第二个地方
# 修改完第一个错误运行会报第二个同样的错误
# 根据错误提示修改"pefile.py"文件
# 修改大约1795行
    def __parse__(self, fname, data, fast_load):
        """Parse a Portable Executable file.

        Loads a PE file, parsing all its structures and making them available
        through the instance's attributes.
        """
        # 添加这一行,同样改为你的python路径
        fname = r"C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\python.exe"
        if fname is not None:
            stat = os.stat(fname)
            if stat.st_size == 0:
                raise PEFormatError('The file is empty')
            fd = None
```
ps：可能会在某些地方可以修改为全局的python路径吧，我没有找到。

I have this problem, too
This is win10 1903
My solution is:

```
# First place
# Find the "win32api. py" file according to the error message prompt
# Modify about 40 lines
def LoadLibraryEx(fileName, handle, flags):
    # Add this line and change it to your Python path
    fileName = r"C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\python.exe"
    if not handle == 0:
        raise ValueError("handle != 0 not supported")
    with _pywin32error():
        return _dll._LoadLibraryEx(fileName, 0, flags)


def EnumResourceTypes(hModule):
```

```
# Second place
# After modifying the first error, the second error will be reported
# Modify the "pefile. py" file according to the error prompt
# Modify about 1795 lines
    def __parse__(self, fname, data, fast_load):
        """Parse a Portable Executable file.

        Loads a PE file, parsing all its structures and making them available
        through the instance's attributes.
        """
        # Add this line and change it to your Python path
        fname = r"C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\python.exe"
        if fname is not None:
            stat = os.stat(fname)
            if stat.st_size == 0:
                raise PEFormatError('The file is empty')
            fd = None
```
ps：Maybe it can be changed to global Python path in some places. I didn't find it.

Hard-coded path is a bad idea
> 
> 
> Hard-coded path is a bad idea

那你有更好的解决办法吗？
Also having this issue, though this is my first attempt to use pyinstaller.
This Works:
- Python: 3.8.1 64bit
- Windows 10: 10.0.17134.1009
- PyInstaller: latest master branch
Has this been fixed? I'm still seeing this with pyinstaller 3.6 
Seeing this as well
Python 3.8.1 64-bit
Windows 10 v1909: 10.0.18363.592

Commit message: Remove support for python from the windows store

When using python from the windows store with PyInstaller, there are permissions errors that require a major mod to the UAC system in the underlying windows kernel to work around. 

It's caused by the damned `WindowsApps` directory, which, for security reasons, even running as *admin* can't even *read* the directory. This means that when PyInstaller (trys to) copy the python dlls and librarys, it fails. You can work around this, but the method risks jailbreaking, which voids warranty. 

This can be "fixed" by saying that we don't support that build of python. (Note that that is actually standard CPython)

Patch to review:
diff --git a/README.rst b/README.rst
index 22de50b1239..d263dac84bc 100644
--- a/README.rst
+++ b/README.rst
@@ -72,6 +72,8 @@ Requirements and Tested Platforms
 - Windows (32bit/64bit):
 
  - Windows XP or newer.
+ - We don't support python installed from the windows store due to 
+   permission errors that can't be easily fixed.
     
 - GNU/Linux (32bit/64bit)
 


Code review comments:
diff_hunk: @@ -72,6 +72,8 @@ Requirements and Tested Platforms
 - Windows (32bit/64bit):
 
  - Windows XP or newer.
+ - We don't support python installed from the windows store due to 
path: README.rst
text: @user1:
Python, not python; Windows, not windows; add a link (perhaps the following).

```
`permission errors <https://github.com/pyinstaller/pyinstaller/pull/4702>`_
```

@author:
Will do