Giter Site home page Giter Site logo

Comments (9)

nchidsey avatar nchidsey commented on May 27, 2024

I just got the same error with numpy. Here's a small reproduction. Tried in Python 3.7.2 (64-bit) and 3.7.3 (32-bit), starting with a blank virtualenv.

foo.py:

import numpy
print("ok")

setup.py:

from setuptools import setup
import py2exe
setup(
    name='foo',
    version='1.0',
    console=['foo.py'],
)

build:

pip install numpy
pip install https://github.com/albertosottile/py2exe/releases/download/v0.9.3.1/py2exe-0.9.3.1-cp37-none-win_amd64.whl
python setup.py py2exe

Then running the exe in a new console window:

Traceback (most recent call last):
  File "foo.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "C:\Users\nick\.virtualenvs\tmp-b1da4736-4c9a-4313-808c-4bdae17f2fdb\lib\site-packages\numpy\__init__.py", line 150, in <module>
    from . import random
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "C:\Users\nick\.virtualenvs\tmp-b1da4736-4c9a-4313-808c-4bdae17f2fdb\lib\site-packages\numpy\random\__init__.py", line 180, in <module>
    from . import mtrand
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
SystemError: <method 'load_module' of 'zipimport.zipimporter' objects> returned NULL without setting an error

I have used the same versions of Python, py2exe and numpy before just fine, but I don't know what the difference is yet. Maybe the other project includes more modules that this simple reproduction doesn't include in the build? I don't think the problem is numpy-specific either. I lean toward thinking it has to do with pyd files and the stub pyc's inside the library.zip that import them.

from py2exe.

albertosottile avatar albertosottile commented on May 27, 2024

I have used the same versions of Python, py2exe and numpy before just fine, but I don't know what the difference is yet.

This is quite puzzling. I was expecting at least an upgrade, maybe one of the numpy (and perhaps rawpy) dependencies? I cannot understand how an error like this could appear if none of the modules was updated. If one of you could find which dependency is causing this, it would be of great help.

from py2exe.

Monism1 avatar Monism1 commented on May 27, 2024

@nchidsey I think your problem is fixed if you replace your setup.py with the following:

from setuptools import setup
import py2exe
setup( console=[{'foo.py'},],
       options={"py2exe": {
            "packages": ['numpy'],}})

I.e. explicitly include the numpy package in setup.py

from py2exe.

nchidsey avatar nchidsey commented on May 27, 2024

Correction - numpy was a different version. The current is 1.17.0. If I grab 1.16.4 instead, it works okay. I don't think numpy has any dependencies, at least when installed from the binary wheel. And yes specifying the package in the py2exe option seems to have fixed it.

By the way, the same exception occurs with packages other than numpy. In the few cases I've seen, the exception occurs at the line where it imports a module that is a stub pyc inside the zip file which imports a pyd that is outside the zipfile.

from py2exe.

albertosottile avatar albertosottile commented on May 27, 2024

@Monism1 Interesting though, it appears that also your problem can be fixed in the same way, specifically by changing the setup.py script to

from distutils.core import setup
import py2exe

setup( console=[{ "script": 'converter.py'},],
       options={"py2exe": {
            "packages": ['numpy', 'rawpy','imageio'],}})

I just tested it with a dummy converter.py script that just imports imageio and rawpy on 3.7.4-64 and it worked. Can you please try this on your system? Thanks.

@nchidsey Honestly, I am not sure why that worked on numpy 1.16.4 and now it is apparently broken. But, I always run my numpy tests with the package name explicitely added in the setup.py script. I also encourage everyone to do that with all their dependencies, especially for packages that contain compiled libraries, such as numpy.

from py2exe.

nchidsey avatar nchidsey commented on May 27, 2024

Adding packages to that option worked for numpy and a few others, but didn't work for another, which is still failing with the same exception and pyc-to-pyd combo. I'm trying to debug the DLL loading in Visual Studio. It gets into some Microsoft DLLs and fails there, but don't know why yet.

from py2exe.

albertosottile avatar albertosottile commented on May 27, 2024

@nchidsey It could be that a DLL is not imported for some package and so a hook should be written or adjusted accordingly, but usually this leads to a different error message. In any case, let me know what you find. Thanks for your help.

from py2exe.

Monism1 avatar Monism1 commented on May 27, 2024

@albertosottile Yes actually it works fine! My mistake, I originally added all packages and dependencies (including os and glob) which caused an error (since I guess you should only include external libs) and forgot to re-add numpy. Interestingly Imageio also has Pillow as a dependency but it's not necessary to include that. Maybe the advice of including all package dependencies (if it initially doesn't work) could be included somewhere in the readme? Thanks again.

from py2exe.

albertosottile avatar albertosottile commented on May 27, 2024

@Monism1 I am glad that everything works now, thanks for having confirmed that. This is a fork of py2exe, so all its extensive documentation still applies. In particular, there are some useful tips and tricks available here. Also, I have always found useful all the setup.py scripts that use py2exe and are available in the other open-source repositories.

@nchidsey I am going to close this issue now since the main probem has been deemed solved. Please open a new issue if you find something relevant during your investigations. Thanks for the time you are investing in this project.

from py2exe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.