I'm having a hidden import problem, which is not uncommon.
I have a fairly small GUI Python program.
What the program does is loading another Python script (which may be
much larger than the top-level) and creates a separate window using
the environment derived from the top-level.
Any python code can be imported as far as it meets some basic
requirements.
Now, I want use Pyinstaller with this program.
When I executed the "pyinstalled" program, I got hidden import problem
as pyinstaller cannot see the imports used in the loaded external
Python script.
I thought I could fix this problem by creating a hook-<module>.py
file. But it didn't work.
By reading a part of pyinstaller codes, I found that hook-<module>.py
scheme was only applied when a module is being imported. As my top-
level module is a small single file Python code and it doesn't import
any module except fairy common Python libraries, I don't have any
import that is appropriate for me to use.
As I know which modules are hidden imports, it is much easier if I can
explicitly specify which ones to be included (much like exclude). Is
there any way using the Pyinstaller 1.3 to do such explicit inclusion?
Meanwhile, I will try putting a 'dummy' import to my program but I
prefer to specify separately as such hidden imports may change
depending upon which external Python script to be loaded.
> I'm having a hidden import problem, which is not uncommon.
> I have a fairly small GUI Python program.
> What the program does is loading another Python script (which may be
> much larger than the top-level) and creates a separate window using
> the environment derived from the top-level.
> Any python code can be imported as far as it meets some basic
> requirements.
Thank you for your posting.
Yes, my top-level script uses __import__(file.py).
Therefore, it doesn't know what kind of modules are needed until
runtime.
I'm trying to create an executable for one common case out of many
possible cases.
ex.
top_level.py A.py (extra imports required for A.py)
top_level.py B.py (extra imports required for B.py)
I can place phoney imports into top_level.py but it will clutter
top_level.py so I would like to avoid.
I would like specify those extra imports in my PyInstaller script.
Aki Niimura
On Jun 26, 12:19 am, Simosito <simos...@gmail.com> wrote:
> You have to run a script importing it from your app, is that right?
> Have you tried with __import__('file.py') or you're using this yet?
> I hope you'll solve this problem soon,
> Simone Ramacci
> On 19 Giu, 19:01, akineko <akin...@gmail.com> wrote:
> > Hello everyone,
> > I'm having a hidden import problem, which is not uncommon.
> > I have a fairly small GUI Python program.
> > What the program does is loading another Python script (which may be
> > much larger than the top-level) and creates a separate window using
> > the environment derived from the top-level.
> > Any python code can be imported as far as it meets some basic
> > requirements.
> Thank you for your posting. > Yes, my top-level script uses __import__(file.py). > Therefore, it doesn't know what kind of modules are needed until > runtime. > I'm trying to create an executable for one common case out of many > possible cases. > ex.
> top_level.py A.py (extra imports required for A.py) > top_level.py B.py (extra imports required for B.py)
> I can place phoney imports into top_level.py but it will clutter > top_level.py so I would like to avoid. > I would like specify those extra imports in my PyInstaller script.
> Aki Niimura
> On Jun 26, 12:19 am, Simosito <simos...@gmail.com> wrote:
>> You have to run a script importing it from your app, is that right? >> Have you tried with __import__('file.py') or you're using this yet?
>> I hope you'll solve this problem soon, >> Simone Ramacci
>> On 19 Giu, 19:01, akineko <akin...@gmail.com> wrote:
>>> Hello everyone,
>>> I'm having a hidden import problem, which is not uncommon.
>>> I have a fairly small GUI Python program. >>> What the program does is loading another Python script (which may be >>> much larger than the top-level) and creates a separate window using >>> the environment derived from the top-level. >>> Any python code can be imported as far as it meets some basic >>> requirements.
>>> [...]
>>> Any suggestions will be appreciated.
>>> Thanks in advance. >>> Aki Niimura
If the thing you want to do is bundle the modules imported by those external scripts into your executable I think you can't, unless you know exactly what will import every possible script you're going to pass to your program.
If you know that, just import every module that might be necessary. (Of course the executable will be heavier) IMHO the isn't any other way to do what you're trying to realize.
I hope I'm wrong about the last sentence, Simone Ramacci
Which imports are required is determined once which script to be
executed.
hooks scheme is the way to provide such info that only user can know.
But it was not quite usable with my case as no imports except system
modules.
PyInstaller is creating a database of all collected imports. So, the
question is how to influence the database creation.
I can resolve my problem by:
(1) Create a phoney import to use hook-<module> scheme
(2) Create a separate hook directory and use hook-<module> scsheme
using system module import
(3) Tweak PyInstaller scripts to add a list of imports explicitly
(4) Put phoney imports to the top level
I don't like none of them but I may need to resort to such.
Thank you,
Aki Niimura
On Jun 26, 2:57 am, "Simone Ramacci - Simosito.it"
> > Thank you for your posting.
> > Yes, my top-level script uses __import__(file.py).
> > Therefore, it doesn't know what kind of modules are needed until
> > runtime.
> > I'm trying to create an executable for one common case out of many
> > possible cases.
> > ex.
> > top_level.py A.py (extra imports required for A.py)
> > top_level.py B.py (extra imports required for B.py)
> > I can place phoney imports into top_level.py but it will clutter
> > top_level.py so I would like to avoid.
> > I would like specify those extra imports in my PyInstaller script.
> > Aki Niimura
> > On Jun 26, 12:19 am, Simosito <simos...@gmail.com> wrote:
> >> You have to run a script importing it from your app, is that right?
> >> Have you tried with __import__('file.py') or you're using this yet?
> >> I hope you'll solve this problem soon,
> >> Simone Ramacci
> >> On 19 Giu, 19:01, akineko <akin...@gmail.com> wrote:
> >>> Hello everyone,
> >>> I'm having a hidden import problem, which is not uncommon.
> >>> I have a fairly small GUI Python program.
> >>> What the program does is loading another Python script (which may be
> >>> much larger than the top-level) and creates a separate window using
> >>> the environment derived from the top-level.
> >>> Any python code can be imported as far as it meets some basic
> >>> requirements.
> >>> [...]
> >>> Any suggestions will be appreciated.
> >>> Thanks in advance.
> >>> Aki Niimura
> If the thing you want to do is bundle the modules imported by those
> external scripts into your executable I think you can't, unless you know
> exactly what will import every possible script you're going to pass to
> your program.
> If you know that, just import every module that might be necessary.
> (Of course the executable will be heavier)
> IMHO the isn't any other way to do what you're trying to realize.
> I hope I'm wrong about the last sentence,
> Simone Ramacci
(This is to record my approach to solve the problem)
After pondering for days, I decided to use the (1) scheme I mentioned:
(1) Create a phony import to use hook-<module> scheme
I created a completely empty module (ex. A.py) and added an import to
the toplevel module.
Then I created hook file (hook-A.py) and listed all hidden imports (I
found many).
Listed modules are considered when PyInstaller tries to import A.py.
(It is a well crafted mechanism, I would say.)
Of course, this hook file may need to be changed if I try to execute a
different script.
But that is not a problem for now as I know which script to be
executed.
I resisted adding a completely empty file to my project but I
concluded that (1) is better than other alternatives.
I also found that analyzer.modules is the database that holds
collected modules. Therefore, you can manipulate it to add modules
directly.
Aki-
On Jun 26, 9:11 am, akineko <akin...@gmail.com> wrote:
> Which imports are required is determined once which script to be
> executed.
> hooks scheme is the way to provide such info that only user can know.
> But it was not quite usable with my case as no imports except system
> modules.
> PyInstaller is creating a database of all collected imports. So, the
> question is how to influence the database creation.
> I can resolve my problem by:
> (1) Create a phoney import to use hook-<module> scheme
> (2) Create a separate hook directory and use hook-<module> scsheme
> using system module import
> (3) Tweak PyInstaller scripts to add a list of imports explicitly
> (4) Put phoney imports to the top level
> I don't like none of them but I may need to resort to such.