Use Poetry to manage dependencies, load YAML configuration via PyYAML, generate rotating logs with logging, and compress archived logs using APScheduler and py7zr.
# Globally set the virtual environment to be created in the project's .venv directory
poetry config virtualenvs.in-project true
# Temporarily set the virtual environment to be created in the project's .venv directory
# Linux
POETRY_VIRTUALENVS_IN_PROJECT=true
# Windows CMD
set POETRY_VIRTUALENVS_IN_PROJECT=true
# Windows PowerShell
$env:POETRY_VIRTUALENVS_IN_PROJECT="true"
# Install dependencies (by default in the virtualenvs directory under "poetry config cache-dir")
poetry install
# Run app script entry
poetry run app1
# Show the command to activate the virtual environment
poetry env info -p
# Activate the virtual environment (Windows)
.venv\Scripts\activate.bat
# Deactivate the virtual environment (Windows)
.venv\Scripts\deactivate.bat
# Remove the virtual environment
poetry env remove pythonNotes:
poetry rundoes not require manually activating.venv.- If dependencies or lockfile change, run
poetry installagain.
poetry run app1Optional one-off module form:
poetry run python -m app1.app1Set once, then reuse:
- Interpreter: select project
.venv(Poetry-created environment). - Mark
srcasSources Rootin Project view. - Run Configuration:
- Type: Python
- Run:
Module name - Module name:
app1.app1 - Working directory: project root
- Save the run configuration (optionally as shared).
If you see ModuleNotFoundError: No module named 'app1' or 'common':
poetry installInitial build:
-Fsingle-file executable,-Dsingle-directory executable-nexecutable name--add-datainclude resource files-pappend search path tosys.path
pyinstaller -n app1 -D --add-data "src/app1/res;res" -p src src/app1/app1.pyBuild with .spec:
--noconfirmNo need to confirm whether to overwrite the last built file
pyinstaller app1.spec --noconfirmRun EXE:
app1.exe --config _internal\res\config.yml