Use Poetry to manage dependencies, read configuration from a YAML file using PyYAML, customize logging to generate logs, and use APScheduler and py7zr to periodically compress and archive logs.
- In the Project view, right-click the
srcdirectory and selectMark Directory as->Sources Root. This allows for direct imports of modules located undersrc. - If running as a module, set the 'Module name' to
app1.app1and the 'Working directory' to the project's root directory.
Enter the project directory.
# 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
# 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
# Start the application
poetry run app1
# Remove the virtual environment
poetry env remove pythonInitial Build:
-FSingle-file executable,-DSingle-directory executable-nSpecifies the name of the exe file--add-dataAdds resource files-pAdd the specified path to the module search path (sys.path)
pyinstaller -n app1 -D --add-data "src/app1/res;res" -p src src/app1/app1.pyBuild Using a .spec File:
--noconfirmNo need to confirm whether to overwrite the last built file
pyinstaller app1.spec --noconfirmRun the EXE:
app1.exe --config _internal\res\config.yml