When writing a Python package, I know how to specify other required Python packages in the setup.py
file thanks to the field install_requires
from setuptools.setup
.
However, I do not know how to specify external system dependencies that are NOT Python packages, i.e. a commands such as git
or cmake
(examples) that my package could call via subprocess.call
or subprocess.Popen
?
Do I have to manually check the availability of the commands in my setup.py
file, or is there a fancy way to specify system requirements?
Edit: I just want to be able to check if the external tools are available, and if not invite the user to install them (by themself). I do not want to manage the installation of external tools when installing the package.
Summary of contributions: it seems that setuptools
has no support for this, and it would be safer to do the check at runtime (c.f. comments and answers).
There are two ways to specify dependencies for Cloud Functions written in Python: using the pip package manager's requirements. txt file or packaging local dependencies alongside your function. Dependency specification using the Pipfile/Pipfile.
Dependency Hell Dependency conflicts occur when different Python packages have the same dependency, but depend on different and incompatible versions of that shared package. Because only a single version of a dependency is permitted in any project's environment, finding a compatible solution can be difficult.
If your project has a dependency requirement that is not currently in the Python Package Index (PyPI), you can still include them if they can be accessed via http and are packaged as either an egg, .py file, or a VCS (Version Control System) repository, such as Git or Subversion.
When managing Python environments, one of the key concerns is dependency management. Dependencies are all of the software components required by your project in order for it to work as intended and avoid runtime errors.
You can use the pip install command with the -t DIRECTORY flag to copy private dependencies into a local directory before deploying your app, as follows: Copy your dependency into a local directory: pip install -t DIRECTORY DEPENDENCY Add an empty __init__.py file to the DIRECTORY directory to turn it into a module.
There are two ways to specify dependencies for Cloud Functions written in Python: using the pip package manager's requirements.txt file or packaging local dependencies alongside your function.
My recommendation would be to check for the presence of those external dependencies not at install-time but at run-time. Either at the start of each run, or maybe at the first run.
It's true that you could add this to your setup.py
, but the setup.py
is not always executed at install-time: for example if your project is packaged as a wheel then it doesn't even contain the setup.py
file at all. And even if you do not distribute your project as a wheel, if I am not mistaken pip tends to build a wheel locally anyway and reuse it for the subsequent installations.
So although it would be possible to do such checks as part of the setup script at install time (provided that you can guarantee the presence and execution of setup.py
), I would say run-time is a safer bet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With