Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

python - pyinstaller not creating .exe (ERROR: base_library.zip could not be created!)

I have a small program on a .py file which takes in data from two separate .xlsx files, plays around with the data using pandas, numpy and then creates a new file within the same directory, and renames + moves one of the old files using os and shutil (as seen below)

worked_file_name, worked_file_name_extension = os.path.splitext("Main data file.xlsx")
cwd = os.getcwd()

for filename in os.listdir(cwd):
    if filename == worked_file_name+worked_file_name_extension:
        shutil.move(os.path.join(cwd, worked_file_name+worked_file_name_extension), os.path.join(cwd + "Old_files", worked_file_name + " " + str(variable) + worked_file_name_extension))

variable being a list of the values from one of the Series within the Main data file.xlsx

Now, when I run pyinstaller --onefile -w py_file_no_spaces.py in CMD (running CMD as admin; no spaces anywhere on the path or the file name) I get the following error:

C:UsersUsuarioDocumentssubfoldersubfolder>pyinstaller --onefile -w py_file_no_spaces.py
93 INFO: PyInstaller: 4.2
93 INFO: Python: 3.8.6
93 INFO: Platform: Windows-10-10.0.18362-SP0
94 INFO: wrote C:UsersUsuarioDocumentssubfoldersubfolderpy_file_no_spaces.spec
97 INFO: UPX is not available.
99 INFO: Extending PYTHONPATH with paths
['C:\Users\Usuario\Documents\subfolder\subfolder',
 'C:\Users\Usuario\Documents\subfolder\subfolder']
125 INFO: checking Analysis
126 INFO: Building Analysis because Analysis-00.toc is non existent
126 INFO: Initializing module dependency graph...
132 INFO: Caching module graph hooks...
142 WARNING: Several hooks defined for module 'win32ctypes.core'. Please take care they do not conflict.
147 INFO: Analyzing base_library.zip ...
2894 INFO: Processing pre-find module path hook distutils from 'C:\Users\Usuario\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\hooks\pre_find_module_path\hook-distutils.py'.
2895 INFO: distutils: retargeting to non-venv dir 'C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib'
4975 INFO: Caching module dependency graph...
5422 ERROR: base_library.zip could not be created!
Traceback (most recent call last):
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0lib
unpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0lib
unpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:UsersUsuarioAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38Scriptspyinstaller.exe\__main__.py", line 7, in <module>
  File "C:UsersUsuarioAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesPyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:UsersUsuarioAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesPyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:UsersUsuarioAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesPyInstalleruildinguild_main.py", line 725, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:UsersUsuarioAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesPyInstalleruildinguild_main.py", line 672, in build
    exec(code, spec_namespace)
  File "C:UsersUsuarioDocumentssubfoldersubfolderpy_file_no_spaces.spec", line 6, in <module>
    a = Analysis(['py_file_no_spaces.py'],
  File "C:UsersUsuarioAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesPyInstalleruildinguild_main.py", line 242, in __init__
    self.__postinit__()
  File "C:UsersUsuarioAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesPyInstalleruildingdatastruct.py", line 160, in __postinit__
    self.assemble()
  File "C:UsersUsuarioAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesPyInstalleruildinguild_main.py", line 350, in assemble
    create_py3_base_library(libzip_filename, graph=self.graph)
  File "C:UsersUsuarioAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesPyInstallerdependutils.py", line 67, in create_py3_base_library
    with zipfile.ZipFile(libzip_filename, mode='w') as zf:
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0libzipfile.py", line 1251, in __init__
    self.fp = io.open(file, filemode)
PermissionError: [Errno 13] Permission denied: 'C:\Users\Usuario\Documents\subfolder\subfolder\build\py_file_no_spaces\base_library.zip'

I assume that the last error (PermissionError: [Errno 13] Permission denied:) is not necessarily what I should be focused on because it would have to do with ERROR: base_library.zip could not be created! (no zip file creation, hence can't be read)

Right or wrong, I'm going by that assumption and have gone through some of the related questions but haven't found a solution yet. So far, I tried:

  • Running without -w and --onefile
  • Uninstalling the library from C: and installing it directly into the subfolder I'm working in (after watching a YouTube video where the guy said that a global install might produce issues)
  • Referencing the .py but creating the pyinstaller result in another folder, as recommended on Permission Error When Trying to Use PyInstaller (with pyinstaller -w --onefile --name "py_file_no_spaces_tool" "C:UsersUsuarioDocumentssubfoldersubfolderpy_file_no_spaces.py" running CMD as admin on the new folder outside of where the .py file is)

I did find a peculiarity after looking at PyInstaller Can't create base_library.zip - When I run print(os.path.exists('C:\Python38-32\build')) on my IDE I get False - furthermore, print(os.listdir('C:\Python38-32')) outputs ['DLLs', 'Doc', 'include', 'keras-master', 'Lib', 'libs', 'LICENSE.txt', 'NEWS.txt', 'python.exe', 'python3.dll', 'python38.dll', 'pythonw.exe', 'Scripts', 'tcl', 'tensorflow-master', 'Tools', 'vcruntime140.dll']

As you can see, I have python installed directly into C (C:python38-32)... Which I don't know if a) I should/is a good idea (not sure why I installed it there to be frank), or b) it's affecting this entire process. After going through the error message I got curious and tried going into C:Program FilesWindowsApps but I get You don't currently have permission to access this folder

Also not considering the python install being an issue since 3.8 seems to be supported now, which many questions in SO seem to be related to

I'm still learning but I'm heavily focused on doing these types of data manipulations using pandas, so these types of issues are completely unfamiliar to me. Any help would be much appreciated!

question from:https://stackoverflow.com/questions/65850660/pyinstaller-not-creating-exe-error-base-library-zip-could-not-be-created

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In the end this would've seemed to be an issue with packages installation / Windows folder accesses. To solve it, I had to create a virtual environment within the folder where my .py file was, then, once the venv was activated, call pyi-makespec --onefile test.py - After that, made sure that the .spec file had all the right info (following this posts suggestions particularly on datas and hidden_exports) before running it. After that is done, the .exe file can be found on the dist folder


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...