6

EDIT

I'm trying to import algosec.models in a file inside the algobot package.

I've tried to add --hidden-import algosec, I've also tried to add the path before importing, using sys.path.append(./../algosec) this is the error message I get when I try to run the program:

Traceback (most recent call last):
  File "algobot_packer/algobot.py", line 2, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
  File "algobot/cli/cli.py", line 3, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
  File "algobot/microsoft_teams/mainloop.py", line 9, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
  File "algobot/framework/configuration.py", line 34, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
  File "algobot/framework/commands.py", line 22, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
  File "algobot/framework/bot.py", line 4, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
  File "algobot/framework/responses.py", line 9, in <module>
ModuleNotFoundError: No module named 'algosec'

the folder structure is:

  • algobot
    • algobot
    • algosec
    • algobot-packer
    • pyucwa

I'm using pyinstaller version 4.2 I didn't make any change in the code since the last time my executable file ran perfectly fine, but now I'm getting this error every time. the thing is - the folder 'algosec' is a subdirectory in my project, and it is noted in the pipfile and again, I didn't make any change in a while and tested it recently (last tested on July 8th)), therefore I believe that it's a dependency issue but not sure which or how to solve.

I've tried multiple changes that somehow worked on one run but when I tried to make these changes again it failed on other builds...

Daniel
  • 1,895
  • 9
  • 20
  • Here is my question maybe could help. https://stackoverflow.com/questions/57721990/modulenotfounderror-in-python – User Aug 26 '21 at 13:03

2 Answers2

3

You can use
--add-data "path_to_algobot:."
based on your system for windows use ; and for linux use :

It will explicitly add your algosec folder into the package.

Deep
  • 306
  • 1
  • 3
  • 11
  • by `path_to_algobot` you mean the path to the project folder? (the one that contains the 4 subfolders?) also, by `:.` the dot stands for destination. can you explaing what is the meaning of src/dest here? I've tried several things that didn't work. it's being built on docker inside a pipenv environment. – Daniel Aug 31 '21 at 10:04
  • also, do you have any idea why this is happening in the first place? – Daniel Aug 31 '21 at 10:21
  • `path_to_algobot` means `path_to_missing_file` . `src` here stands for the source of the missing file that means from where to copy it and `dest` is for where to put that file inside the bundle. Yes, the `.` stands for destination you can also put your path instead of `.`. As you haven't shared much of your code. But from my experience its due to pyinstaller not able to find those files while packaging the bundle. – Deep Aug 31 '21 at 12:48
  • seems like after finding the correct combination of paths, and using the `--add-data` flag, I'm getting another `ModuleNotFoundError` for `zeep` package that I'm using. It's in the setup.py and should be imported (worked before) any clue? – Daniel Sep 01 '21 at 07:51
  • 1
    @Daniel It's an quite common issue with pyinstaller. You just have to keep on adding the missing file using `--add-data` and missing imports/modules using `--hidden-imports`. I'm using pyinstaller since long all, I do is keep repeating the above steps till the bundle gets working. – Deep Sep 02 '21 at 10:07
  • how would you use `--add-data` on a remote package such as `zeep` that I'm installing from pypi? – Daniel Sep 02 '21 at 10:23
1

Apparently since I took the highest version of zeep and deprecated without giving a fixed version, it caused issues because of a newer release. I had to add them to setup.py of the algobot package which is the main package of the executable with a fixed version.

In addition I had to add a .egg file of the algosec package with --paths in order for pyinstaller to find it.

Daniel
  • 1,895
  • 9
  • 20