A simple Python helper that automatically installs third-party dependencies using pip.
By Morpheus
At the top of your file, insert the following:
import pypacks
pypacks.install_requirements()Make sure you place this code before the third-party import statements.
By default, install_requirements() reads from requirements.txt in the
current working directory.
You can also point at a different file:
import pypacks
pypacks.install_requirements("deps/prod.txt")Use install() when you want to declare dependencies directly in code:
import pypacks
pypacks.install(
"requests>=2.31.0",
"rich==13.7.0",
)You can also pass a (name, specifier) pair:
import pypacks
pypacks.install(
("requests", ">=2.31.0"),
("rich", "13.7.0"),
)install() accepts any number of packages. Each package can be a string
specifier (like requests>=2.31.0) or a two-item iterable where the first
value is the package name and the second value is the version specifier.
Both install() and install_requirements() accept:
check_updates: When True (default), upgrade packages if a newer version is available and allowed by the specifier.update_pip: When True (default), upgrade pip before the first install.
Example:
import pypacks
pypacks.install_requirements(check_updates=False, update_pip=False)