guessit-io / guessit

GuessIt is a python library that extracts as much information as possible from a video filename.
https://guessit-io.github.io/guessit
GNU Lesser General Public License v3.0
814 stars 92 forks source link

TypeError from nuitka created executable #704

Open 0-MegaMind-0 opened 3 years ago

0-MegaMind-0 commented 3 years ago

I'm trying to create a onefile executable with nuitka. It achieves the similar result to pyinstaller onefile.

but the generated executable gives me a executable error at the file where guessit is imported

File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "/tmp/.mount_guessil6D1BW/guessit/__init__.py", line 8, in <module guessit>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "/tmp/.mount_guessil6D1BW/guessit/api.py", line 17, in <module guessit.api>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "/tmp/.mount_guessil6D1BW/guessit/rules/__init__.py", line 11, in <module guessit.rules>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "/tmp/.mount_guessil6D1BW/guessit/rules/properties/episodes.py", line 15, in <module guessit.rules.properties.episodes>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "/tmp/.mount_guessil6D1BW/guessit/rules/common/numeral.py", line 51, in <module guessit.rules.common.numeral>
  File "/tmp/.mount_guessil6D1BW/guessit/rules/common/numeral.py", line 47, in __build_word_numeral
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'

This is the log generated and it points to:

https://github.com/guessit-io/guessit/blob/develop/guessit/rules/common/numeral.py#L28-#L51

I'm guessing when it does it it never gets any wordlists for some reason and tries to add None to '|'

For now i've simply managed to solved this by adding

if not re_:
    re_ = ''
re_ += ')'

not the most elegant solution but its working for now.

Did couple of tests on both nuitka generated executable and my python module for now both produce identical result so i'm guessing that change didn't effect much. But since I don't really know what that part of code is used in guessit for I'm not really sure if I'd encounter issues in future.

0-MegaMind-0 commented 3 years ago
from guessit import guessit
import sys

def main():
    filename = sys.argv[1]
    print(guessit(filename))

if __name__ == "__main__":
    main()

It can be replicated by making this simple program a executable onefile using nuitka

 python -m nuitka --follow-imports --onefile --linux-onefile-icon __main__.png  __main__.py
Pfuenzle commented 2 years ago

Did you manage to get it working? I also got your error, but your fix worked, so thanks for that. But now I get another error: ModuleNotFoundError: No module named 'babelfish.converters.alpha2'

The only thing importing babelfish is guessit, so did you also get this error? If yes, could you please tell me how you fixed it?

0-MegaMind-0 commented 2 years ago

@Pfuenzle you'll need to use follow-imports and use the include package-dir and data-dir more more info read their entire documentation

--follow-imports

--include-plugin-directory=~/venv_path/lib/python3.8/site-packages/babelfish/ 
--include-data-dir=~/venv_path/lib/python3.8/site-packages/babelfish/data=babelfish/data 
--include-data-dir=~/venv_path/lib/python3.8/site-packages/guessit/data=guessit/data  
--include-data-dir=~/venv_path/lib/python3.8/site-packages/guessit/config=guessit/config 
--include-plugin-directory=~/venv_path/lib/python3.8/site-packages/guessit
Toilal commented 2 years ago

Why not using official binaries available in release page ?

0-MegaMind-0 commented 2 years ago

Why not using official binaries available in release page ?

Hey, this is for a package I built, which uses guessit to get the Title from file names. Since I had to send these to my friends who have never installed python in their life sending it as pip installable or whl package was out of the question. So had to create a simple EXE. That's when I encountered this issue. I'm not exactly sure why we get a TypeError but didn't have the time to debug and see what part actually triggers the issue, So never made a pull request for this and left this as a issue for others who might be having the same issue.

Toilal commented 2 years ago

I understand, but there's also binary builds inside Github Release page, for Linux, MacOS and Windows.

Le lun. 29 nov. 2021, 23:06, MegaMind @.***> a écrit :

Why not using official binaries available in release page ?

Hey, this is for a package I built, which uses guessit to get the Title from file names. Since I had to send these to my friends who have never installed python in their life sending it as pip installable or whl package was out of the question. So had to create a simple EXE. That's when I encountered this issue. I'm not exactly sure why we get a TypeError but didn't have the time to debug and see what part actually triggers the issue, So never made a pull request for this and left this as a issue for others who might be having the same issue.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/guessit-io/guessit/issues/704#issuecomment-982066595, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI4TPRWGILBPVIW4ATC5PDUOP2M7ANCNFSM46XRORMA .

0-MegaMind-0 commented 2 years ago

Oh yeah for many that would be the best solution but since I'm using the python guessit api that wouldn't work for me.

Toilal commented 2 years ago

I see ... I don't see how it's possible. It seems args is empty, or wordlist are empty too and we don't get into loop that initialize the string.

When you apply your fix, are the roman numbers guessed properly ? For example, "Dummy.Season.III" should give season: 3 in output ? I assume it's more likely an issue related to nuitka, maybe it has some kind of "tree shaking" and it drops some global variables inside this module ?

Toilal commented 2 years ago

Have you tried with latest release ? https://nuitka.net/posts/nuitka-release-0617.html

0-MegaMind-0 commented 1 year ago

I see ... I don't see how it's possible. It seems args is empty, or wordlist are empty too and we don't get into loop that initialize the string.

When you apply your fix, are the roman numbers guessed properly ? For example, "Dummy.Season.III" should give season: 3 in output ? I assume it's more likely an issue related to nuitka, maybe it has some kind of "tree shaking" and it drops some global variables inside this module ?

I revisited this recently and got the same error (using the latest version of nuitka)

So I decided to give this and try with the sample code posted above

$ ./test.bin Dummy.Season.III
MatchesDict([('title', 'Dummy'), ('season', 3), ('mimetype', 'application/x-iphone'), ('type', 'episode')])

even after applying my temp fix it does parse the info correctly.

I'm still not sure why after compiling with nuitka it has this error. It likely has something to do with nuitka's C compilation and the way it initializes each module import