I have following folder structure for my FastAPI based backend project. I would like to do code obfuscation and ship in docker image.
├── alembic
│ ├── env.py
│ └── versions
│ ├── initial.py
├── alembic.ini
├── app
│ ├── helpers
│ │ ├── helper1.py
│ │ ├── helper2.py
│ ├── __init__.py
│ ├── routers
│ │ ├── routers1
│ ├── routera.py
│ └── __init__.py
│ │ ├── routers2
│ ├── __init__.py
│ └── startup
│ ├── start1.py
│ └── __init__.py
│ ├── main.py
When i run pyinstaller main.spec
, it creates dist and build folders. Then after i copy that to container and start application (./dist/main/main) it is giving ModuleNotFoundError: No module named 'app'
error.
Here is my main.spec file
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['app/main.py'],
pathex=['/home/user/project/'],
binaries=[],
datas=[],
hiddenimports=['tensorboard', 'asyncpg.pgproto.pgproto', 'app'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=['tkinter'],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
coll = COLLECT(
exe,
a.binaries,
a.datas,
strip=False,
upx=False,
upx_exclude=[],
name='main',
)
I don’t know what am i missing.
The app module should be resolvable for uvicorn.