Comments (9)
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.
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.
@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.
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.
@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.
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.
@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.
@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.
@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)
- Missing LICENSE in wheels HOT 4
- AssertionError with Python embeddable package HOT 1
- Py_OptimizeFlag not set correctly during Python initialization
- OSError: [WinError 87] The parameter is incorrect. HOT 2
- PYTHONPATH module location HOT 1
- Exe is created by doesn't run (opens then closes)
- Simple pygame example tries to lookup files inside of `library.zip` HOT 1
- Support Python 3.12 HOT 23
- Impossible to specify different version info for each of the binaries with the new freeze API. HOT 3
- pynput import break the file HOT 1
- PYTHONIOENCODING is ignored
- pendulum package doesn't initialize when unpacking from zipfile
- add version for python 3.12 too
- usage missing
- Does py2exe support 'QtWebEngineWidgets' of PySide6?
- How do I get an app using jaydebapi to work as an executable ?
- Failure to import zipextimporter with error "No module named '_memimporter'"
- [freeze][zipfile] Dependent packages and modules are not zipped to library.zip or packed to .exe bin
- ImportError: MemoryLoadLibrary failed loading PyQt5\QtWidgets.pyd: The specified module could not be found. (126)
- no open .whl in windows
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from py2exe.