Unable to convert py files to exe using pyinstaller - python

I was trying to convert my python program to a standalone executable file. However, after running pyinstaller, it runs into an error and doesn't output the file. This is the log:
60 INFO: PyInstaller: 3.6
60 INFO: Python: 3.8.3
60 INFO: Platform: Windows-10-10.0.18362-SP0
61 INFO: wrote C:\Users\username\Downloads\pip\test.spec
63 INFO: UPX is not available.
64 INFO: Extending PYTHONPATH with paths
['C:\\Users\\username\\Downloads\\pip', 'C:\\Users\\username\\Downloads\\pip']
64 INFO: checking Analysis
65 INFO: Building Analysis because Analysis-00.toc is non existent
65 INFO: Initializing module dependency graph...
67 INFO: Caching module graph hooks...
71 INFO: Analyzing base_library.zip ...
1900 INFO: Processing pre-find module path hook distutils
1900 INFO: distutils: retargeting to non-venv dir 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\\lib'
3116 INFO: Caching module dependency graph...
3200 INFO: running Analysis Analysis-00.toc
Traceback (most recent call last):
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\win32ctypes\pywin32\pywintypes.py", line 35, in pywin32error
yield
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
return _dll._LoadLibraryEx(fileName, 0, flags)
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\win32ctypes\core\cffi\_dll.py", line 23, in _LoadLibraryEx
result = check_null(
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\win32ctypes\core\cffi\_util.py", line 81, in __call__
self._raise_error(function_name)
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\win32ctypes\core\cffi\_util.py", line 92, in _raise_error
raise exception
OSError: [WinError 1920] The file cannot be accessed by the system
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\building\build_main.py", line 734, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\building\build_main.py", line 681, in build
exec(code, spec_namespace)
File "C:\Users\username\Downloads\pip\test.spec", line 6, in <module>
a = Analysis(['test.py'],
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\building\build_main.py", line 244, in __init__
self.__postinit__()
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
self.assemble()
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\building\build_main.py", line 393, in assemble
self.binaries.extend(bindepend.Dependencies([('', python, '')],
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\depend\bindepend.py", line 228, in Dependencies
for ftocnm, fn in getAssemblyFiles(pth, manifest, redirects):
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\depend\bindepend.py", line 404, in getAssemblyFiles
for assembly in getAssemblies(pth):
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\depend\bindepend.py", line 355, in getAssemblies
res = GetManifestResources(pth)
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\utils\win32\winmanifest.py", line 1007, in GetManifestResources
return winresource.GetResources(filename, [RT_MANIFEST], names, languages)
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\utils\win32\winresource.py", line 170, in GetResources
hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE)
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
return _dll._LoadLibraryEx(fileName, 0, flags)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
raise error(exception.winerror, exception.function, exception.strerror)
win32ctypes.pywin32.pywintypes.error: (1920, 'LoadLibraryEx', 'The file cannot be accessed by the system')
I also tried using brentvollebregt's auto-py-to-exe but ran into the same error.
Does it have to do with admin rights? Do I have to run command prompt as an admin in order to use pyinstaller? Or do I have to be logged-in as the admin?

Please use google before posting a question on stackoverflow, this is the original question: https://stackoverflow.com/a/60320831/12533273
You may have two versions of python3 installed and that's cousing a problem, try uninstalling all versions of python and then reinstalling them.

.\pyinstaller --onefile -w 'filename.py'
or
pyinstaller --onefile -w 'filename.py'
use the above two commands in the powershell while you went to the page of conversion should be made.
https://media.geeksforgeeks.org/wp-content/uploads/20200202204743/Screenshot-5013.png

Related

Pyinstaller is showing 'Failed to execute script 'app' due to unhandled exception: expected...' [duplicate]

I am trying to build an .exe file from .py file using pysinstaller and Python 3.7.2.
It worked with Python 3.6; then I re-installed the last version of Python (3.7.2) and tried to generate an exe file, but pyinstaller barfs.
Below is the error report I get.
(venv) C:\Users\user\Desktop\untitled1>pyinstaller test.py
53 INFO: PyInstaller: 3.4
53 INFO: Python: 3.7.2
54 INFO: Platform: Windows-10-10.0.17134-SP0
58 INFO: wrote C:\Users\user\Desktop\untitled1\test.spec
60 INFO: UPX is not available.
61 INFO: Extending PYTHONPATH with paths
['C:\\Users\\user\\Desktop\\untitled1', 'C:\\Users\\user\\Desktop\\untitled1']
61 INFO: checking Analysis
187 INFO: checking PYZ
236 INFO: checking PKG
237 INFO: Building PKG because PKG-00.toc is non existent
238 INFO: Building PKG (CArchive) PKG-00.pkg
Traceback (most recent call last):
File "C:\Users\user\Desktop\untitled1\venv\Scripts\pyinstaller-script.py", line 11, in <module>
load_entry_point('PyInstaller==3.4', 'console_scripts', 'pyinstaller')()
File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\user\Desktop\untitled1\venv\lib\site- packages\PyInstaller\building\build_main.py", line 838, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\Users\user\Desktop\untitled1\venv\lib\site- packages\PyInstaller\building\build_main.py", line 784, in build
exec(text, spec_namespace)
File "<string>", line 29, in <module>
File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\building\api.py", line 424, in __init__
strip_binaries=self.strip, upx_binaries=self.upx,
File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\building\api.py", line 196, in __init__
self.__postinit__()
File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
self.assemble()
File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\building\api.py", line 273, in assemble
pylib_name = os.path.basename(bindepend.get_python_library_path())
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 214, in basename
return split(p)[1]
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 183, in split
p = os.fspath(p) TypeError: expected str, bytes or os.PathLike object, not NoneType
What could be the problem?
I found the following solution: replace bindepend.py from <myProject_path>\venv\Lib\site-packages\PyInstaller\depend with the file provided by Loran425 on github here
As I have read from many forums here and here and discussions regarding this issue caused by Pyinstaller.
If you are using Pycharm or any virtual environment. Unfortunatelly Pycharm creates its local vertual environment in venvpath once you indicate the interpreter. So, you should set the external tool (pyinstaller) to the real path of your python 3.7 .exe as the picture shows here.
For Linux users, follow my other answer here.
In my case the problem occurs when I'm using the standard library's venv, but not when I'm using virtualenv. (However I had to use virtualenv==16.1.0 because of another bug.)
The bug was resolved in version 3.6 of PyInstaller. Just update and will work fine.
It may be from an ill-formed spec file, something as simple (yet difficult to find) as a commented or missing argument.
When I comment out name in exe,
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
# name='my_app',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
icon='resources/icons/icon.ico',
version='resources/version/version.py')
I get the following traceback:
146666 INFO: Building PYZ (ZlibArchive) c:\projects\my-env\app\qc\tools\my_app\build\my_app_old\PYZ-00.pyz completed successfully.
Traceback (most recent call last):
File "C:\Users\lorem\Anaconda3\envs\my-env\Scripts\pyinstaller-script.py", line 10, in <module>
sys.exit(run())
File "C:\Users\lorem\Anaconda3\envs\my-env\lib\site-packages\PyInstaller\__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\lorem\Anaconda3\envs\my-env\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\lorem\Anaconda3\envs\my-env\lib\site-packages\PyInstaller\building\build_main.py", line 720, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\Users\lorem\Anaconda3\envs\my-env\lib\site-packages\PyInstaller\building\build_main.py", line 667, in build
exec(code, spec_namespace)
File "my_app_old.spec", line 49, in <module>
version='resources/version/version.py')
File "C:\Users\lorem\Anaconda3\envs\my-env\lib\site-packages\PyInstaller\building\api.py", line 382, in __init__
self.name = os.path.join(CONF['distpath'], os.path.basename(self.name))
File "C:\Users\lorem\Anaconda3\envs\my-env\lib\ntpath.py", line 214, in basename
return split(p)[1]
File "C:\Users\lorem\Anaconda3\envs\my-env\lib\ntpath.py", line 183, in split
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
The application builds when name is included.

Pyinstaller Unable to Convert Fully

Specs
Python Version 3.9.6 (DL'd and installed from Python's website, not
Microsoft Store etc.)
Windows 10
Problem
I've tried to package python file in cmd using pyinstaller filename.py and pyinstaller --onefile Simple.py to *.exe which does not seem to work:
73 INFO: PyInstaller: 4.3 73 INFO: Python: 3.9.5 125 INFO: Platform:
Windows-10-10.0.19043-SP0 126 INFO: wrote
C:\Users\Baven\Desktop\Forexe\Simple.spec 186 INFO: UPX is available.
188 INFO: Extending PYTHONPATH with paths
['C:\Users\Baven\Desktop\Forexe',
'C:\Users\Baven\Desktop\Forexe'] 197 INFO: checking Analysis 197
INFO: Building Analysis because Analysis-00.toc is non existent 197
INFO: Initializing module dependency graph... 200 INFO: Caching module
graph hooks... 215 INFO: Analyzing base_library.zip ... 2561 INFO:
Processing pre-find module path hook distutils from
'C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\hooks\pre_find_module_path\hook-distutils.py'.
2561 INFO: distutils: retargeting to non-venv dir 'C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib'
4598 INFO: Caching module dependency graph... 4789 INFO: running
Analysis Analysis-00.toc Traceback (most recent call last): File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32ctypes\pywin32\pywintypes.py",
line 35, in pywin32error
yield File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32ctypes\pywin32\win32api.py",
line 43, in LoadLibraryEx
return _dll._LoadLibraryEx(fileName, 0, flags) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32ctypes\core\ctypes_util.py",
line 42, in check_null
raise make_error(function, function_name) OSError: [WinError 1920] The file cannot be accessed by the system.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py",
line 197, in run_module_as_main
return run_code(code, main_globals, None, File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py",
line 87, in run_code
exec(code, run_globals) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts\pyinstaller.exe_main.py",
line 7, in File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller_main.py",
line 114, in run
run_build(pyi_config, spec_file, **vars(args)) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller_main.py",
line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\building\build_main.py",
line 737, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\building\build_main.py",
line 684, in build
exec(code, spec_namespace) File "C:\Users\Baven\Desktop\Forexe\Simple.spec", line 7, in
a = Analysis(['Simple.py'], File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\building\build_main.py",
line 242, in init
self.postinit() File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\building\datastruct.py",
line 160, in postinit
self.assemble() File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\building\build_main.py",
line 391, in assemble
self.binaries.extend(bindepend.Dependencies([('', python, '')], File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\depend\bindepend.py",
line 224, in Dependencies
for ftocnm, fn in getAssemblyFiles(pth, manifest, redirects): File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\depend\bindepend.py",
line 403, in getAssemblyFiles
for assembly in getAssemblies(pth): File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\depend\bindepend.py",
line 354, in getAssemblies
res = GetManifestResources(pth) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\utils\win32\winmanifest.py",
line 1016, in GetManifestResources
return winresource.GetResources(filename, [RT_MANIFEST], names, languages) File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\utils\win32\winresource.py",
line 170, in GetResources
hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE) File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32ctypes\pywin32\win32api.py",
line 43, in LoadLibraryEx
return _dll._LoadLibraryEx(fileName, 0, flags) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\contextlib.py",
line 135, in exit
self.gen.throw(type, value, traceback) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32ctypes\pywin32\pywintypes.py",
line 37, in pywin32error
raise error(exception.winerror, exception.function, exception.strerror) win32ctypes.pywin32.pywintypes.error: (1920,
'LoadLibraryExW', 'The file cannot be accessed by the system.')
C:\Users\Baven\Desktop\Forexe>pyinstaller --onefile Simple.py 72 INFO:
PyInstaller: 4.3 72 INFO: Python: 3.9.5 122 INFO: Platform:
Windows-10-10.0.19043-SP0 123 INFO: wrote
C:\Users\Baven\Desktop\Forexe\Simple.spec 166 INFO: UPX is available.
168 INFO: Extending PYTHONPATH with paths
['C:\Users\Baven\Desktop\Forexe',
'C:\Users\Baven\Desktop\Forexe'] 177 INFO: checking Analysis 177
INFO: Building Analysis because Analysis-00.toc is non existent 178
INFO: Initializing module dependency graph... 181 INFO: Caching module
graph hooks... 196 INFO: Analyzing base_library.zip ... 2579 INFO:
Processing pre-find module path hook distutils from
'C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\hooks\pre_find_module_path\hook-distutils.py'.
2580 INFO: distutils: retargeting to non-venv dir 'C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib'
4596 INFO: Caching module dependency graph... 4777 INFO: running
Analysis Analysis-00.toc Traceback (most recent call last): File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32ctypes\pywin32\pywintypes.py",
line 35, in pywin32error
yield File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32ctypes\pywin32\win32api.py",
line 43, in LoadLibraryEx
return _dll._LoadLibraryEx(fileName, 0, flags) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32ctypes\core\ctypes_util.py",
line 42, in check_null
raise make_error(function, function_name) OSError: [WinError 1920] The file cannot be accessed by the system.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py",
line 197, in run_module_as_main
return run_code(code, main_globals, None, File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py",
line 87, in run_code
exec(code, run_globals) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts\pyinstaller.exe_main.py",
line 7, in File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller_main.py",
line 114, in run
run_build(pyi_config, spec_file, **vars(args)) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller_main.py",
line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\building\build_main.py",
line 737, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\building\build_main.py",
line 684, in build
exec(code, spec_namespace) File "C:\Users\Baven\Desktop\Forexe\Simple.spec", line 7, in
a = Analysis(['Simple.py'], File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\building\build_main.py",
line 242, in init
self.postinit() File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\building\datastruct.py",
line 160, in postinit
self.assemble() File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\building\build_main.py",
line 391, in assemble
self.binaries.extend(bindepend.Dependencies([('', python, '')], File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\depend\bindepend.py",
line 224, in Dependencies
for ftocnm, fn in getAssemblyFiles(pth, manifest, redirects): File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\depend\bindepend.py",
line 403, in getAssemblyFiles
for assembly in getAssemblies(pth): File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\depend\bindepend.py",
line 354, in getAssemblies
res = GetManifestResources(pth) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\utils\win32\winmanifest.py",
line 1016, in GetManifestResources
return winresource.GetResources(filename, [RT_MANIFEST], names, languages) File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\PyInstaller\utils\win32\winresource.py",
line 170, in GetResources
hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE) File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32ctypes\pywin32\win32api.py",
line 43, in LoadLibraryEx
return _dll._LoadLibraryEx(fileName, 0, flags) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\contextlib.py",
line 135, in exit
self.gen.throw(type, value, traceback) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32ctypes\pywin32\pywintypes.py",
line 37, in pywin32error
raise error(exception.winerror, exception.function, exception.strerror) win32ctypes.pywin32.pywintypes.error: (1920,
'LoadLibraryExW', 'The file cannot be accessed by the system.')
What I've also done and retried to package, all of which led to the outcome above (except the UPX)
Reinstalled
Restarted (also updated Windows)
Trying the conversion in virtual environment
Fixed the UPX (186 INFO: UPX is available.) by downloading and placing upx.exe in the *.py folder
Disabled (off) both (python & python3) App Installer in App execution aliases
What I find strange
Python version shown in cmd is still 3.9.5; also 3.9.5 in IDLE which changed to 3.9.6 after rebooting my PC
Other Python users can convert without issue
WindowsApps folder access returned none (e.g. return _run_code(code, main_globals, None, File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py",)
When manually accessing the WindowApps folder, the notification "You don't currently have permission to access this folder." is shown. If that is the root cause, anyway to allow Python to access it?
Here's the link to the python file and what was converted: https://drive.google.com/file/d/1L8vVEc4z6LYxgN6XHWwJlujVsicMgfMy/view
I have also tried the below code as a *.py file:
#!/usr/bin/python
import sqlite3
conn = sqlite3.connect('test.db')
print "Opened database successfully";
The below was the outcome:
Traceback (most recent call last): File
"C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mysql\connector\network.py",
line 574, in open_connection
self.sock.connect(sockaddr) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively
refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py",
line 197, in _run_module_as_main
return _run_code(code, main_globals, None, File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py",
line 87, in run_code
exec(code, run_globals) File "c:\Users\Baven.vscode\extensions\ms-python.python-2021.6.944021595\pythonFiles\lib\python\debugpy_main.py",
line 45, in
cli.main() File "c:\Users\Baven.vscode\extensions\ms-python.python-2021.6.944021595\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py",
line 444, in main
run() File "c:\Users\Baven.vscode\extensions\ms-python.python-2021.6.944021595\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py",
line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("main")) File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py",
line 268, in run_path
return _run_module_code(code, init_globals, run_name, File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py",
line 97, in _run_module_code
_run_code(code, mod_globals, init_globals, File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py",
line 87, in run_code
exec(code, run_globals) File "c:\Users\Baven\Desktop\demo_mysql_test.py", line 3, in
mydb = mysql.connector.connect( File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mysql\connector_init.py",
line 273, in connect
return MySQLConnection(*args, **kwargs) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mysql\connector\connection.py",
line 107, in init
self.connect(**kwargs) File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mysql\connector\abstracts.py",
line 1003, in connect
self._open_connection() File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mysql\connector\connection.py",
line 350, in _open_connection
self._socket.open_connection() File "C:\Users\Baven\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mysql\connector\network.py",
line 576, in open_connection
raise errors.InterfaceError( mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL
server on 'localhost:3306' (10061 No connection could be made because
the target machine actively refused it)
They (both pyinstaller and SQL) seem to be connected to one root cause.
This fixed the issue:
python3 -m pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip

I have downloaded pyinstaller, but when I try to convert the python files, it says [Errno 13] Permission denied

I installed pyinstaller through python -m pip install command. For a reason, pip is not in my path so that's how I did it. Then, it downloads pyinstaller and it gives me a warning that it's not in the path.
I ignore it and proceed to transform the directory where my project is. I wait a few moments and then if shows me this error message:
the cmd window error
C:\Users\dhiaa>pyinstaller echecs
88 INFO: PyInstaller: 3.6
89 INFO: Python: 3.8.1
89 INFO: Platform: Windows-10-10.0.17763-SP0
92 INFO: wrote C:\Users\dhiaa\echecs.spec
93 INFO: UPX is not available.
95 INFO: Extending PYTHONPATH with paths
['C:\\Users\\dhiaa', 'C:\\Users\\dhiaa']
96 INFO: checking Analysis
96 INFO: Building Analysis because Analysis-00.toc is non existent
96 INFO: Initializing module dependency graph...
100 INFO: Caching module graph hooks...
111 INFO: Analyzing base_library.zip ...
5848 INFO: Processing pre-find module path hook distutils
5850 INFO: distutils: retargeting to non-venv dir 'c:\\users\\dhiaa\\lib'
9865 INFO: Caching module dependency graph...
10167 INFO: running Analysis Analysis-00.toc
10172 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\users\dhiaa\python.exe
10332 INFO: Analyzing C:\Users\dhiaa\echecs
Traceback (most recent call last):
File "c:\users\dhiaa\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\dhiaa\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\dhiaa\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "c:\users\dhiaa\lib\site-packages\PyInstaller\__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\users\dhiaa\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\users\dhiaa\lib\site-packages\PyInstaller\building\build_main.py", line 734, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\users\dhiaa\lib\site-packages\PyInstaller\building\build_main.py", line 681, in build
exec(code, spec_namespace)
File "C:\Users\dhiaa\echecs.spec", line 6, in <module>
a = Analysis(['echecs'],
File "c:\users\dhiaa\lib\site-packages\PyInstaller\building\build_main.py", line 244, in __init__
self.__postinit__()
File "c:\users\dhiaa\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
self.assemble()
File "c:\users\dhiaa\lib\site-packages\PyInstaller\building\build_main.py", line 416, in assemble
priority_scripts.append(self.graph.run_script(script))
File "c:\users\dhiaa\lib\site-packages\PyInstaller\depend\analysis.py", line 249, in run_script
self._top_script_node = super(PyiModuleGraph, self).run_script(pathname)
File "c:\users\dhiaa\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1391, in run_script
with open(pathname, 'rb') as fp:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\dhiaa\\echecs'
> PermissionError: [Errno 13] Permission denied
I have a folder containing all my python files, it's not only one python file.
I used git on the main file of my project. Could it affect its accesibility? I also tried just to copy paste the entire project to some other places and the same permission error appears in cmd (even when in admin mode).
Can you do it again in a CMD opened as administrator?
Can you find c:\users\dhiaa\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py on disk?

pyinstaller script not found

I created my project with python 3.7. when I run 'pyinstaller --onefile -w dunamicGUI.py' command in terminal from /Users/mdarifulislam/Documents/GitHub/ZKProject/pythonServer/ directory it shows
40 INFO: PyInstaller: 3.5
40 INFO: Python: 2.7.16
47 INFO: Platform: Darwin-19.2.0-x86_64-i386-64bit
48 INFO: wrote /Users/mdarifulislam/Documents/GitHub/ZKProject/pythonServer/dunamicGUI.spec
54 INFO: UPX is not available.
Traceback (most recent call last):
File "/usr/local/bin/pyinstaller", line 10, in <module>
sys.exit(run())
File "/usr/local/lib/python2.7/site-packages/PyInstaller/__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "/usr/local/lib/python2.7/site-packages/PyInstaller/__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/usr/local/lib/python2.7/site-packages/PyInstaller/building/build_main.py", line 844, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "/usr/local/lib/python2.7/site-packages/PyInstaller/building/build_main.py", line 791, in build
exec(code, spec_namespace)
File "/Users/mdarifulislam/Documents/GitHub/ZKProject/pythonServer/dunamicGUI.spec", line 17, in <module>
noarchive=False)
File "/usr/local/lib/python2.7/site-packages/PyInstaller/building/build_main.py", line 190, in __init__
raise ValueError("script '%s' not found" % script)
ValueError: script '/Users/mdarifulislam/Documents/GitHub/ZKProject/pythonServer/dunamicGUI.py' not found
Now what will be the solution.

Script not found when using pyinstaller

I am trying to convert a python script to an exe file. I have added the python script to a folder together with pyinstaller, and I use the right PATH in CMD:
C:\Users\ola nordmann\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts\pyinstaller>pyinstaller --onefile CreatWordDoc.py
126 INFO: PyInstaller: 3.5
126 INFO: Python: 3.7.5
126 INFO: Platform: Windows-10-10.0.18362-SP0
127 INFO: wrote C:\Users\ola nordmann\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts\pyinstaller\CreatWordDoc.spec
132 INFO: UPX is not available.
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\ola nordmann\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts\pyinstaller\pyinstaller.exe\__main__.py", line 7, in <module>
File "C:\Users\ola nordmann\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\ola nordmann\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\ola nordmann\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\building\build_main.py", line 844, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\Users\ola nordmann\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\building\build_main.py", line 791, in build
exec(code, spec_namespace)
File "C:\Users\ola nordmann\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts\pyinstaller\CreatWordDoc.spec", line 17, in <module>
noarchive=False)
File "C:\Users\ola nordmann\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\building\build_main.py", line 190, in __init__
raise ValueError("script '%s' not found" % script)
ValueError: script 'C:\Users\ola nordmann\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts\pyinstaller\CreatWordDoc.py' not found
This is what it shows.
I know there are some similar questions here, but I have not found a solution yet.
I found the solution. I had to first install Python from their own website instead of the Windows store. Then I had to add it to a PATH. After this it still did not work because I used Python 3.8.0, so I had to install pyinstaller development version.

Categories