1

I'm new to python packaging and distributing. I have a python app which I want to pip install, so I created a setup.py for it.

Now the setup.py has install_requires which alerts if a dependency is missing, but I'm wondering if I can/should provide a way to automatically install missing dependencies. Currently the app requires one self-developed shared package, and no external packages.

EDIT:

My setup.py:

from setuptools import setup

setup(
    name="TcpMonitor",
    version="1.0",
    packages=["tcpmonitor"],
    py_modules=["tcp_monitor"],
    install_requires=[
        "CommonPyLib",
    ],
    entry_points='''
        [console_scripts]
        tcp_monitor_gui=tcpmonitor:main
    '''
)

Pip install output:

Collecting CommonPyLib (from TcpMonitor==1.0)
  Could not find a version that satisfies the requirement CommonPyLib (from TcpMonitor==1.0) (from versions: )
No matching distribution found for CommonPyLib (from TcpMonitor==1.0)
Elad Weiss
  • 3,662
  • 3
  • 22
  • 50
  • I think that how you approached it is the way to go. However, to automatically install them I think you can create a text file and call pip install on it... something like this https://stackoverflow.com/questions/7225900/how-to-pip-install-packages-according-to-requirements-txt-from-a-local-directory – David Mar 21 '18 at 09:46
  • 1
    Typically users will install your package with Pip, so dependencies listed in `install_requires` will be automatically installed. – ash Mar 21 '18 at 11:16
  • @Josh Are you sure? I'm getting an error: "Could not find a version that satisfies the requirement ". Am I missing something? (Added setup.py to question) – Elad Weiss Mar 21 '18 at 11:31
  • 1
    @EladWeiss See Simon's answer – your `CommonPyLib` package is not on PyPI, so Pip doesn't know how to install it. – ash Mar 21 '18 at 11:49

1 Answers1

3

As long as the dependency is listed in the install_requires list, it will automatically check for that module and if not present it will install it, providing that the module can be installed from PyPi. If not (where that package cannot be found on PyPi) you get a Could not find a version that satisfies the requirement error.

I could not find any packages with this name on PyPi so you need to add the dependency to be installed on PyPi to be installed via pip, if you host your package elsewhere (GitHub for example) this may provide a solution: How can I make setuptools install a package that's not on PyPI?.

Running pip install commonpylib returns

Could not find a version that satisfies the requirement commonlib (from versions: ) No matching distribution found for commonpylib

So you do not have a setup script problem but a problem with finding the package on PyPi (which does not seem to exist), or at least Python does not know where you have hosted it.

The other option is to integrate that package with what you are distributing without making it a dependency (i.e. add it to the __init__.py file ect).

Xantium
  • 11,201
  • 10
  • 62
  • 89