zewelor / bt-mqtt-gateway

A simple Python script which provides a Bluetooth to MQTT gateway, easily extensible via custom workers. See https://github.com/zewelor/bt-mqtt-gateway/wiki for more information.
MIT License
550 stars 117 forks source link

Dependency installation via pip internal API at runtime #184

Closed cybe closed 3 years ago

cybe commented 4 years ago

Hey,

I think we should solve the issue of using pips internal API:

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.

The official solution is to not import pip at all, but to run pip in a subprocess. Any other way is not supported and might break at any time.

However, I myself am really not a fan of installing dependencies at runtime anyway. I strictly separate installation from runtime. So I would advocate for a solution that eliminates runtime dependency installation all together. Not sure how that should be approached in a usable way yet, just want to hear your thoughts on this first.

zewelor commented 4 years ago

Hi

Some time ago I've added option to print all or configured only requirements. https://github.com/zewelor/bt-mqtt-gateway/blob/master/gateway.py#L49. Its used in docker now: https://github.com/zewelor/bt-mqtt-gateway/blob/master/Dockerfile#L17 . Maybe we should check for missing dependencies, on start, to give nice error to use, that there is missing dep and install it via

 pip install `./gateway.py -r configured` 
cybe commented 4 years ago

Sounds good to me! I'll prepare a PR based on pkg_resources.