简体   繁体   中英

How to set up hidden imports in pyinstaller

I have a large project with multiple packages. These packages use a set of modules in a common package. I am trying to create an exe on Windows using pyinstaller, but it cannot find the common package.

This cut down project exhibits the same issue. My package is organised as shown in this tree:

在此处输入图片说明

When I use

python -m my_package

in the top my_package directory it works perfectly.

The module main.py in my_package imports Bar (which is located in foo) from common. The __init__.py file in common includes:

from common.source.foo import Bar

When I build and exe file and run it in terminal, it fails with ' No module named common'

my pyintstaller spec includes:

hiddenimports=['../', '../common/', '../common/common/']

Should I try something different?

The hiddenimports are used to specify imports that can't be detected by pyinstaller, not the paths to those imports.

Try adding the necessary paths to the pathex list in the spec file instead (these are paths that will be available in sys.path during analysis).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM