AttributeError:模块“ win32ctypes.pywin32.win32api”没有属性“错误”

时间:2019-10-25 11:30:37

标签: python

(venv) C:\Users\idanf\PycharmProjects\untitled>pyinstaller -w -F -i "C:\Users\idanf\PycharmProjects\untitled\logo.png" gui.py

在顶部有我用来创建exe的命令。 py文件中的文件。

我正在尝试将gui.py(用于gui的pyqt5 lib)制作为exe文件并收到此错误。

如何修复它或创建exe。其他方式提交文件?

我尝试使用cmd和pycharm以及相同的问题。

如果需要,我可以提供代码。

如果我需要提供更多信息,请告诉我

80 INFO: PyInstaller: 3.5
81 INFO: Python: 3.7.3
81 INFO: Platform: Windows-10-10.0.18362-SP0
83 INFO: wrote C:\Users\idanf\PycharmProjects\untitled\gui.spec
87 INFO: UPX is not available.
89 INFO: Extending PYTHONPATH with paths
['C:\\Users\\idanf\\PycharmProjects\\untitled',
 'C:\\Users\\idanf\\PycharmProjects\\untitled']
89 INFO: checking Analysis
117 INFO: checking PYZ
135 INFO: checking PKG
144 INFO: Building because C:\Users\idanf\PycharmProjects\untitled\build\gui\gui.exe.manifest changed
144 INFO: Building PKG (CArchive) PKG-00.pkg
463 WARNING: One binary added with two internal names.
464 WARNING: ('libGLESv2.dll',
 'C:\\users\\idanf\\anaconda3\\lib\\site-packages\\PyQt5\\Qt\\bin\\libGLESv2.dll',
 'BINARY')
464 WARNING: was placed previously at
465 WARNING: ('PyQt5\\Qt\\bin\\libGLESv2.dll',
 'C:\\users\\idanf\\anaconda3\\lib\\site-packages\\PyQt5\\Qt\\bin\\libGLESv2.dll',
 'BINARY')
14719 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
14724 INFO: Bootloader c:\users\idanf\pycharmprojects\untitled\venv\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
14725 INFO: checking EXE
14725 INFO: Building EXE because EXE-00.toc is non existent
14725 INFO: Building EXE from EXE-00.toc
14730 INFO: Copying icons from C:\Users\idanf\PycharmProjects\untitled\logo.png
Traceback (most recent call last):
  File "c:\users\idanf\pycharmprojects\untitled\venv\lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 35, in pywin32error
    yield
  File "c:\users\idanf\pycharmprojects\untitled\venv\lib\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
    return _dll._LoadLibraryEx(fileName, 0, flags)
  File "c:\users\idanf\pycharmprojects\untitled\venv\lib\site-packages\win32ctypes\core\ctypes\_util.py", line 42, in check_null
    raise make_error(function, function_name)
OSError: [WinError 193] <no description>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\idanf\pycharmprojects\untitled\venv\lib\site-packages\PyInstaller\utils\win32\icon.py", line 231, in CopyIcons
    hsrc = win32api.LoadLibraryEx(srcpath, 0, LOAD_LIBRARY_AS_DATAFILE)
  File "c:\users\idanf\pycharmprojects\untitled\venv\lib\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
    return _dll._LoadLibraryEx(fileName, 0, flags)
  File "C:\Users\idanf\Anaconda3\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "c:\users\idanf\pycharmprojects\untitled\venv\lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
    raise error(exception.winerror, exception.function, exception.strerror)
win32ctypes.pywin32.pywintypes.error: (193, 'LoadLibraryExW', '<no description>')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\idanf\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\idanf\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\idanf\PycharmProjects\untitled\venv\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
  File "c:\users\idanf\pycharmprojects\untitled\venv\lib\site-packages\PyInstaller\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\users\idanf\pycharmprojects\untitled\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\idanf\pycharmprojects\untitled\venv\lib\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\idanf\pycharmprojects\untitled\venv\lib\site-packages\PyInstaller\building\build_main.py", line 791, in build
    exec(code, spec_namespace)
  File "C:\Users\idanf\PycharmProjects\untitled\gui.spec", line 33, in <module>
    console=False , icon='C:\\Users\\idanf\\PycharmProjects\\untitled\\logo.png')
  File "c:\users\idanf\pycharmprojects\untitled\venv\lib\site-packages\PyInstaller\building\api.py", line 444, in __init__
    self.__postinit__()
  File "c:\users\idanf\pycharmprojects\untitled\venv\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "c:\users\idanf\pycharmprojects\untitled\venv\lib\site-packages\PyInstaller\building\api.py", line 534, in assemble
    icon.CopyIcons(tmpnm, self.icon)
  File "c:\users\idanf\pycharmprojects\untitled\venv\lib\site-packages\PyInstaller\utils\win32\icon.py", line 232, in CopyIcons
    except win32api.error as W32E:
AttributeError: module 'win32ctypes.pywin32.win32api' has no attribute 'error'

2 个答案:

答案 0 :(得分:1)

一旦我使用了 .ico,它就对我有用。

我使用此代码将任何类型转换为 .ico :

from PIL import Image
from tkinter import filedialog, Tk
from getpass import getuser

# any path possible
def convert(path):
    print("converting")
    #path = str(path)
    print(path)
    img = Image.open(path)
    #where is the '.' ?
    extension = path.find('.')
    img.save(path[:extension]+".ico")


# get a path name for a file
gui = Tk()
#gui.iconbitmap('C:/Users/Severin/OneDrive/Desktop/icon.ico')
user = getuser()

# Get the file
filepath = filedialog.askopenfilename()
# Split the filepath to get the directory
#directory = os.path.split(file)[0]
convert(filepath)

答案 1 :(得分:0)

我是python的新手。但是,我有同样的错误。当我尝试这些东西时,它对我有用。

  1. 尝试将.ico文件用作应用程序图标
  2. 尝试将该.ico文件的目录更改为脚本目录,然后再次运行。