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

Regression with PyInstaller (1.0.1 compared to 1.0) #25

Closed
tasn opened this issue Jul 18, 2019 · 11 comments
Closed

Regression with PyInstaller (1.0.1 compared to 1.0) #25

tasn opened this issue Jul 18, 2019 · 11 comments

Comments

@tasn
Copy link

tasn commented Jul 18, 2019

Trying to use PyInstaller to package https://github.com/etesync/etesync-dav I'm getting failures with 1.0.1 but not with 1.0. The error (when running the binary) is:

[Errno 2] No such file or directory: '/tmp/_MEIjeDGjU/orderedmultidict/__version__.py'

So essentially PyInstaller can't find the version.py file which usually means it was being imported in some magical way rather than explicitly. Usually just adding import version to init.py fixes such issues (not sure if it is the case here or not).

@caramelomartins
Copy link

For people coming across this issue, a workaround to this is creating a custom PyInstaller hook with the following contents:

from PyInstaller.utils.hooks import get_package_paths

datas = [(get_package_paths('orderedmultidict')[1] + "/__version__.py", 'orderedmultidict')]

This will force PyInstaller to load the __version__.py file and resolve the error.

The issue, as @tasn suggested, is that __version__.py is not explicitly imported anywhere but rather used only as a file in setup.py, without actually importing the module: https://github.com/gruns/orderedmultidict/blob/master/setup.py#L21.

@igortg
Copy link

igortg commented Aug 14, 2019

imported anywhere but rather used only as a file in setup.py

Seems that it's not the case anymore, since __init__ is importing it. Is there any reason we can't import version explicitly?

@caramelomartins
Copy link

caramelomartins commented Aug 14, 2019

@igortg Didn't notice that __init__.py was doing the same thing as setup.py but the issue still stands, PyInstaller doesn't import as it is not being imported implicitly.

Is there any reason we can't import version explicitly?

I can't answer this...I haven't tested making the change it, to be honest.

@tasn
Copy link
Author

tasn commented Aug 16, 2019

It's imported in a weird way (why not a normal import?) that's maybe why it's PyInstaller can't catch it.

@jayvdb
Copy link

jayvdb commented Nov 11, 2019

This also breaks PyOxidizer, and possibly also Nuitka.

@bryan-koroleski-fivestars

I'm also using PyInstaller and hit this issue. I worked around it with a runtime hook:

import importlib
import sys

try:
    import orderedmultidict  # NOQA
except FileNotFoundError:
    pass

sys.modules["orderedmultidict"] = importlib.import_module("orderedmultidict.orderedmultidict")

@gruns
Copy link
Owner

gruns commented Jul 20, 2021

@bryan-koroleski-fivestars thank you for posting your workaround 🙌

i want to resolve this but, sadly, i dont have the time to fully chase this down right now

requests does the same trick, exec()ing a __version__.py file full of metadata. see https://github.com/psf/requests/blob/master/setup.py#L61-L63

this begs the question: what else does requests do so it doesnt break PyOxidizer, Nuitka, and PyInstaller?

@bryan-koroleski-fivestars

It looks like the difference here is that requests imports the members of __version__.py instead of exec()ing in __init__.py: https://github.com/psf/requests/blob/master/requests/__init__.py#L129-L131

I should have time to put together a quick PR for this tomorrow if it would help.

@gruns
Copy link
Owner

gruns commented Jul 21, 2021

yep. and indeed orderedmultidict uses exec() in __init__.py:

# Import all variables in __version__.py without explicit imports.
meta = {}  # type: Dict
with open(pjoin(dirname(__file__), '__version__.py')) as f:
    exec(f.read(), meta)

https://github.com/gruns/orderedmultidict/blob/master/orderedmultidict/__init__.py#L22-L26

I should have time to put together a quick PR for this tomorrow if it would help.

thank you! 🙏

@CraftedCat
Copy link

version 1.0.1 Pyinstaller 4.10

File "orderedmultidict\__init__.py", line 19, in <module> FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\User\\AppData\\Local\\Temp\\_MEI149122\\orderedmultidict\\__version__.py' [5644] Failed to execute script 'main' due to unhandled exception!

@gruns
Copy link
Owner

gruns commented May 17, 2022

closing

this was fixed with 6d66993 and subsequent commits

thank you everyone for weighing in here! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants