Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTK3 msys2 ModuleNotFoundError: No module named '_struct' #4125

Open
jrezai opened this issue Mar 14, 2019 · 14 comments

Comments

@jrezai
Copy link

commented Mar 14, 2019

The official way to install GTK3 on Windows is to use msys2 (www.msys2.org).
I followed the instructions on gtk.org which explains how to install GTK3 using msys2.

I managed to install and configure msys2 successfully and my Python script runs successfully using msys2 - on Windows 10 64-bit.

Now I want to package my Python script, so I can send it to others:
I've used PyInstaller to generate an .exe (on Windows 10 64-bit), using the msys2 terminal, but when I attempt to run my program's .exe (generated by PyInstaller), I get the following error, and my program doesn't run:

[8476] mod is NULL - structTraceback (most recent call last):
  File "C:/msys64/mingw64/lib/python3.7/struct.py", line 13, in <module>
    from _struct import *
ModuleNotFoundError: No module named '_struct'
[8476] mod is NULL - pyimod02_archiveTraceback (most recent call last):
  File "C:/msys64/mingw64/lib/python3.7/site-packages/pyinstaller-3.5.dev0+8c27d2668-py3.7.egg/PyInstaller/loader/pyimod02_archive.py", line 28, in <module>
    import struct
ModuleNotFoundError: No module named 'struct'
[8476] mod is NULL - pyimod03_importersTraceback (most recent call last):
  File "C:/msys64/mingw64/lib/python3.7/site-packages/pyinstaller-3.5.dev0+8c27d2668-py3.7.egg/PyInstaller/loader/pyimod03_importers.py", line 24, in <module>
    from pyimod02_archive import ArchiveReadError, ZlibArchiveReader
ModuleNotFoundError: No module named 'pyimod02_archive'
Traceback (most recent call last):
  File "site-packages/pyinstaller-3.5.dev0+8c27d2668-py3.7.egg/PyInstaller/loader/pyiboot01_bootstrap.py", line 15, in <module>
ModuleNotFoundError: No module named 'pyimod03_importers'
[8476] Failed to execute script pyiboot01_bootstrap

Any ideas?

Thank you.

@PippoGC

This comment has been minimized.

Copy link

commented Mar 23, 2019

Hi there,

I am facing the same problem using the same environment; currently running python 3.7.2 with Eclipse 4.9. I have also tried to isolate the problem by removing all references to GTK3 by creating a simple python script that just prints a string. Here the results:
1/ with the option --onefile, it works
2/ with the option --onedir does not work and generate the above traceback.

BTW, this traceback is same as the one reported in #4027 [ModuleNotFoundError: No module named '_struct'] ; Not sure why this thread is set as closed since I cannot find how it was addressed

Thank you !

@jrezai

This comment has been minimized.

Copy link
Author

commented Mar 27, 2019

I ended up using both PyInstaller and cx_Freeze to make my program work. I haven't done full testing yet, but my script runs with the generated .exe that cx_Freeze made.

I used PyInstaller to find the dependencies that my Python script needed, and then I used cx_Freeze to generate the final .exe. It would be easier if PyInstaller could be used alone to generate the final .exe package (without the _struct traceback), instead of using two separate tools.

@sirDeniel

This comment has been minimized.

Copy link

commented Apr 26, 2019

@jrezai @PippoGC I would like to make some "documentation" of the steps you made to get that executable. I got some kind of distributable and published it on this repository but I don't consider as a real solution. We can create some repo with examples and anyone can join to add experience. Greetings.

@mitras2

This comment has been minimized.

Copy link

commented Apr 29, 2019

I can confirm this is a problem.
I can give logs and files on request.

It would be great if this issue could be solved, becaus it basically breaks building GTK3 applications im Windows (MSYS)

@gpraceman

This comment has been minimized.

Copy link

commented May 16, 2019

I am facing the same error. Python 3.7.3 x86 environment on MSYS2 and on Windows 10 x64. PyInstaller 3.4

@springermac springermac referenced a pull request that will close this issue May 19, 2019
@gpraceman

This comment has been minimized.

Copy link

commented Jun 5, 2019

I even tried using the latest dev package (as of yesterday) and still get this same error on two fresh Windows 10 x64 and Python 3.7 environments.

An unusual thing I see in the dist folder is a "_struct-cpython-37m" folder, which contains a single DLL file, named "dllruct-cpython-37m.dll". If I change the name of that file to "_struct-cpython-37m.dll" and copy it to the root dist folder, I no longer get the "No module named '_struct'" error. Now I get a "No module named 'zlib'" error. Then I notice that there is a "zlib-cpython-37m" folder with a single file named "dllb-cpython-37m.dll" in it. So, I change its name to "zlib-cpython-37m.dll" and copy it to the root dist folder. No more "No module named 'zlib'" error. Now I get a "zlib.error: Error -3 while decompressing data: incorrect header check". At least some progress. Not sure how to proceed from here.

Hopefully, this information will help. It sure seems that something is fouled up with how things are getting packaged.

@gpraceman

This comment has been minimized.

Copy link

commented Jun 18, 2019

I implemented the proposed changes from @springermac, along with the proposed edits by @htgoebel and that resolved that error for me. See #4240. I was now able to get my Gtk3+ app packaged up.

However, when running the app, I ended up with a "No module named 'packaging.specifiers'" error. To fix that, I edited the site-packages/pkg_resources/__ init __.py file, lines 89-92, and changed the __ import __()'s to regular import statements. Now my Gtk3 app will run. Huge relief.

springermac added a commit to springermac/pyinstaller that referenced this issue Jun 21, 2019

springermac added a commit to springermac/pyinstaller that referenced this issue Jun 21, 2019

@danyeaw

This comment has been minimized.

Copy link
Contributor

commented Aug 10, 2019

So using the latest version of the develop branch, I am still getting this error when using msys2 with mingw64 and import pkg_resources. I do not get these errors when testing with the offical Python in Windows 10. To fix this in msys2, I can run pyinstaller --hidden-import _struct. Is this an appropriate fix for this, to add the hidden import for pkg_resources using a hook?

@gpraceman

This comment has been minimized.

Copy link

commented Aug 10, 2019

@danyeaw This is not yet implemented into the Dev branch. I couldn't wait, so I downloaded the source code and implemented the proposed changes. That fixed my packaging issue with MSYS2.

@danyeaw

This comment has been minimized.

Copy link
Contributor

commented Aug 11, 2019

@gpraceman Your changes in #4240 don't work for me when applied to the develop branch.

@gpraceman

This comment has been minimized.

Copy link

commented Aug 12, 2019

@danyeaw Technically, they aren't my changes. I just took the changes that @springermac proposed, along with the proposed edits by @htgoebel and applied those to the dev code.

@danyeaw

This comment has been minimized.

Copy link
Contributor

commented Aug 12, 2019

@gpraceman Sorry I wasn't trying to blame you that it wasn't working. 😀 I appreciate that you made a PR with the suggested changes of others, I am just trying to figure out a working fix we can get in the develop branch now.

@kakyoism

This comment has been minimized.

Copy link

commented Aug 21, 2019

@danyeaw Do you still have this issue with the latest pyinstaller? I downloaded and built the latest package for msys2, and the _struct error is still there. It can be reproduced with a hello-world script:

import sys
import os
from os.path import abspath, basename, dirname, exists, join


_script_dir = abspath(dirname(__file__))

with open(join(_script_dir, 'hello.txt'), 'w') as f:
	f.writelines(['hello world!\n'])
print('Hello World!')
input('Press any key to continue.')
@danyeaw

This comment has been minimized.

Copy link
Contributor

commented Aug 22, 2019

@kakyoism Yes, I still have this issue when using pkg_resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.