Mailing List Archive

several issues with pyinstaller on Windows 10
On Windows 10 I have installed:

P:\W10>python --version
Python 3.10.0

P:\W10>pyinstaller --version
4.7

I can compile a VERY simple Python program:

P:\W10>type argv.pv
#!/usr/bin/python3

import sys

for a in sys.argv: print("["+a+"]")


P:\W10>pyinstaller.exe --onefile tcpbm.py

But I can run it only once:

P:\W10\dist>argv a b
[dist\argv]
[a]
[b]

P:\W10\dist>argv a b
The process cannot access the file because it is being used by another process.

P:\W10\dist>argv 1 2 zzz
The process cannot access the file because it is being used by another process.


Compiling a little more complex program (with net IO) fails:

P:\W10>pyinstaller.exe --onefile tcpbm.py
140 INFO: PyInstaller: 4.7
140 INFO: Python: 3.10.0
171 INFO: Platform: Windows-10-10.0.19041-SP0
171 INFO: wrote P:\W10\tcpbm.spec
171 INFO: UPX is not available.
203 INFO: Extending PYTHONPATH with paths
['P:\\W10']
531 INFO: checking Analysis
547 INFO: Building Analysis because Analysis-00.toc is non existent
547 INFO: Initializing module dependency graph...
562 INFO: Caching module graph hooks...
593 INFO: Analyzing base_library.zip ...
4656 INFO: Processing pre-find module path hook distutils from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
4656 INFO: distutils: retargeting to non-venv dir 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib'
5781 INFO: Caching module dependency graph...
6031 INFO: running Analysis Analysis-00.toc
6031 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by C:\Users\admin\AppData\Local\Programs\Python\Python310\python.exe
6187 INFO: Analyzing P:\W10\tcpbm.py
6250 INFO: Processing module hooks...
6250 INFO: Loading module hook 'hook-difflib.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6250 INFO: Loading module hook 'hook-distutils.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6250 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6250 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6390 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6390 INFO: Loading module hook 'hook-lib2to3.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6484 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6484 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6484 INFO: Loading module hook 'hook-sysconfig.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6484 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6500 INFO: Loading module hook 'hook-xml.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6546 INFO: Loading module hook 'hook-_tkinter.py' from 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6734 INFO: checking Tree
6734 INFO: Building Tree because Tree-00.toc is non existent
6749 INFO: Building Tree Tree-00.toc
6890 INFO: checking Tree
6890 INFO: Building Tree because Tree-01.toc is non existent
6890 INFO: Building Tree Tree-01.toc
7031 INFO: checking Tree
7031 INFO: Building Tree because Tree-02.toc is non existent
7031 INFO: Building Tree Tree-02.toc
7062 INFO: Looking for ctypes DLLs
7078 INFO: Analyzing run-time hooks ...
7093 INFO: Including run-time hook 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
7093 INFO: Including run-time hook 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
7109 INFO: Including run-time hook 'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
7109 INFO: Looking for dynamic libraries
7546 INFO: Looking for eggs
7546 INFO: Using Python library
C:\Users\admin\AppData\Local\Programs\Python\Python310\python310.dll
7562 INFO: Found binding redirects:
[]
7562 INFO: Warnings written to P:\W10\build\tcpbm\warn-tcpbm.txt
7624 INFO: Graph cross-reference written to P:\W10\build\tcpbm\xref-tcpbm.html
7640 INFO: checking PYZ
7640 INFO: Building PYZ because PYZ-00.toc is non existent
7640 INFO: Building PYZ (ZlibArchive) P:\W10\build\tcpbm\PYZ-00.pyz
8125 INFO: Building PYZ (ZlibArchive) P:\W10\build\tcpbm\PYZ-00.pyz completed successfully.
8155 INFO: checking PKG
8155 INFO: Building PKG because PKG-00.toc is non existent
8155 INFO: Building PKG (CArchive) tcpbm.pkg
9890 INFO: Building PKG (CArchive) tcpbm.pkg completed successfully.
9890 INFO: Bootloader C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
9890 INFO: checking EXE
9890 INFO: Building EXE because EXE-00.toc is non existent
9890 INFO: Building EXE from EXE-00.toc
9890 INFO: Copying bootloader EXE to P:\W10\dist\tcpbm.exe
9921 INFO: Copying icon to EXE
9921 INFO: Copying icons from ['C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
9937 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
9937 INFO: Writing RT_ICON 1 resource with 3752 bytes
9937 INFO: Writing RT_ICON 2 resource with 2216 bytes
9937 INFO: Writing RT_ICON 3 resource with 1384 bytes
9937 INFO: Writing RT_ICON 4 resource with 37019 bytes
9937 INFO: Writing RT_ICON 5 resource with 9640 bytes
9937 INFO: Writing RT_ICON 6 resource with 4264 bytes
9937 INFO: Writing RT_ICON 7 resource with 1128 bytes
9968 INFO: Copying 0 resources to EXE
9968 INFO: Emedding manifest in EXE
9968 INFO: Updating manifest in P:\W10\dist\tcpbm.exe
10203 INFO: Updating resource type 24 name 1 language 0
Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 35, in pywin32error
yield
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\win32ctypes\pywin32\win32api.py", line 229, in EndUpdateResource
_resource._EndUpdateResource(handle, discard)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\win32ctypes\core\ctypes\_util.py", line 64, in check_false
raise make_error(function, function_name)
OSError: [WinError 110] The system cannot open the device or file specified.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\__main__.py", line 124, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\__main__.py", line 58, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 782, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 714, in build
exec(code, spec_namespace)
File "P:\W10\tcpbm.spec", line 23, in <module>
exe = EXE(pyz,
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\api.py", line 507, in __init__
self.__postinit__()
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\datastruct.py", line 155, in __postinit__
self.assemble()
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\api.py", line 666, in assemble
self.manifest.update_resources(self.name, [1])
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", line 902, in update_resources
UpdateManifestResourcesFromXML(dstpath, self.toprettyxml().encode("UTF-8"), names, languages)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", line 990, in UpdateManifestResourcesFromXML
winresource.UpdateResources(dstpath, xmlstr, RT_MANIFEST, names or [name], languages or [0, "*"])
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\utils\win32\winresource.py", line 189, in UpdateResources
win32api.EndUpdateResource(hdst, 0)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\win32ctypes\pywin32\win32api.py", line 228, in EndUpdateResource
with _pywin32error():
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 153, in __exit__
self.gen.throw(typ, value, traceback)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
raise error(exception.winerror, exception.function, exception.strerror)
win32ctypes.pywin32.pywintypes.error: (110, 'EndUpdateResourceW', 'The system cannot open the device or file specified.')


For my Windows knowledge is near zero (I am an UNIX guy) I cannot
interpret these error messages. What is going wrong?


The source code is:

https://fex.rus.uni-stuttgart.de/fop/rA3oDJfN/tcpbm.py


--
Ullrich Horlacher Server und Virtualisierung
Rechenzentrum TIK
Universitaet Stuttgart E-Mail: horlacher@tik.uni-stuttgart.de
Allmandring 30a Tel: ++49-711-68565868
70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/
--
https://mail.python.org/mailman/listinfo/python-list
Re: several issues with pyinstaller on Windows 10 [ In reply to ]
On 11/18/21, Ulli Horlacher <framstag@rus.uni-stuttgart.de> wrote:
>
> P:\W10\dist>argv a b
> The process cannot access the file because it is being used by another
> process.

Try searching for open handles for "argv.exe" using Sysinternals
Process Explorer [1]. Terminate the offending process.

Since you're inexperienced with Windows, here's a brief explanation of
ERROR_SHARING_VIOLATION (32).

File objects that are opened for filesystem files have a
read-write-delete sharing mode if the open requests any
read-write-delete data access, but not if the open only has metadata
access (e.g. timestamps, ID, attributes, extended attributes,
security). Note that delete access includes the right to rename a
file.

The share mode flags and associated data access rights are as follows:

FILE_SHARE_READ
- FILE_READ_DATA | FILE_EXECUTE
FILE_SHARE_WRITE
- FILE_WRITE_DATA | FILE_APPEND_DATA
FILE_SHARE_DELETE
- DELETE

For example, if an existing open for a file has any data access and
doesn't share read access, then trying to open the file with execute
access will fail as a sharing violation. The security context of the
open request doesn't matter. For example, SYSTEM and administrators
aren't privileged to bypass the sharing mode. It can only be bypassed
from the kernel.

Unfortunately the system error message for ERROR_SHARING_VIOLATION is
misleading. The sharing mode has nothing to do with processes. It's
strictly a function of the File objects that are opened for the file.

Python's open() and os.open() functions share read and write access,
but they do not share delete access. For example, overlapping calls to
open('spam.txt', 'w') are allowed. For os.stat(), the share mode of
existing opens doesn't matter because it opens the file with metadata
access only.

Sharing data access can get messy. Each open has its own file pointer
in the associated OS file object. For example, say an open writes 10
bytes and flushes the buffer. Then a second open(..., 'w') call
overwrites the file, truncating it to 0 bytes. When the original open
writes to the file again, the OS will back fill the file with 10 null
bytes.

Windows also provides byte-range shared and exclusive locking that can
exceed the current size of the file. A byte-range lock doesn't prevent
opening the file with read, write, or delete access, and it doesn't
prevent deleting the file. It causes write or read-write operations on
the range to fail with ERROR_LOCK_VIOLATION (33).

> win32ctypes.pywin32.pywintypes.error: (110, 'EndUpdateResourceW',
> 'The system cannot open the device or file specified.')

This is likely due to a sharing violation. EndUpdateResourceW() [2]
requires exclusive access to the target file. If its internal open
fails for any reason, it maps all errors to this generic
ERROR_OPEN_FAILED (110) error code.

---
[1] https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer
[2] https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-endupdateresourcew
--
https://mail.python.org/mailman/listinfo/python-list