Shared code/configuration in .spec files #9008
-
To avoid "code" duplication, I wanted move shared configuration in Is importing local files into a Example # CommonSpec.py
datas = [
("images", "images")
] # my-test.spec
# -*- mode: python ; coding: utf-8 -*-
import CommonSpec
a = Analysis(
['my-app.py'],
pathex=[],
binaries=[],
datas=CommonSpec.datas,
Yet, the exception is as follows:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The directory that contains .spec file is not automatically added to python's search path. Technically, it never really is; it is the location of the entry-point script that ends up being added to search path, but only when Analysis is instantiated. So if you want your import sys
import os
sys.path.insert(0, os.path.dirname(SPEC)) # SPEC is defined by PyInstaller in the context in which the spec is executed
import CommonSpec
a = Analysis(
['my-app.py'],
pathex=[],
binaries=[],
datas=CommonSpec.datas,
... |
Beta Was this translation helpful? Give feedback.
The directory that contains .spec file is not automatically added to python's search path. Technically, it never really is; it is the location of the entry-point script that ends up being added to search path, but only when Analysis is instantiated.
So if you want your
CommonSpec
to be discoverable at the start of spec, you need to add the spec location to python's search path: