2

I'm currently trying to create an executable for my application with Pyinstaller. I already could fix some general import errors by including the respective libraries in the hiddenimports section in my .spec file.

However I'm now getting the following error when executing my .exe:

ImportError: attempted relative import with no known parent package

Looking at the Traceback it seems like my used package (sklearn) is using relative imports. Reading through similar questions, I only found solutions for this problem in case relative imports are needed in the own package. But how to solve the problem when it occurs in a package which I'm not able to adapt?

I tried to add sklearn and the respective subpackages (e.g.sklearn.utils.fixes) explicitely in hiddenimports but this didn't work.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
user2550641
  • 317
  • 4
  • 18
  • You can check [this post](https://stackoverflow.com/questions/57108026/pyinstaller-modulenotfounderror-no-module-named-sklearn-utils-cython-blas). Also try to simply import the desired packages at the top of your .spec file (e.g. `import sklearn`, `import sklearn.tree` etc.) – mnikley Jul 12 '21 at 08:59
  • Thanks for answering. I tried all of the mentioned solutions but this didn't work. This only works for me for the "module not found" errors, not for the mentioned one. – user2550641 Jul 12 '21 at 12:14
  • Thanks for the link. But as far as I understood this doesn't really help me with the problem of third party relative imports right? As I cannot change the project structure of sklearn... – user2550641 Jul 13 '21 at 09:10
  • What are your Python and sklearn versions ? – Maurice Meyer Jul 13 '21 at 09:50
  • Python 3.6 and sklearn 0.24.1 (skopt 0.9) – user2550641 Jul 13 '21 at 10:02
  • Not enough info. Post an example project with this problem. – Nizam Mohamed Jul 17 '21 at 18:49

0 Answers0