csparpa / pyowm

A Python wrapper around the OpenWeatherMap web API
https://pyowm.readthedocs.io
MIT License
789 stars 171 forks source link

Installing with pip using Git URL fails #341

Closed Tobiaqs closed 3 years ago

Tobiaqs commented 3 years ago

When running pip install git+https://github.com/csparpa/pyowm.git@develop (master fails too) in a fresh virtualenv with Python 3.8.5 and pip 20.1.1, I get the following error:

Collecting git+https://github.com/csparpa/pyowm.git@develop
  Cloning https://github.com/csparpa/pyowm.git (to revision develop) to /tmp/pip-req-build-_86bl7ty
  Running command git clone -q https://github.com/csparpa/pyowm.git /tmp/pip-req-build-_86bl7ty
  Running command git checkout -b develop --track origin/develop
  Switched to a new branch 'develop'
  Branch 'develop' set up to track remote branch 'develop' from 'origin'.
  Running command git submodule update --init --recursive -q
    ERROR: Command errored out with exit status 1:
     command: /home/me/.local/share/virtualenvs/backend-nPPHZqlJ/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-_86bl7ty/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-_86bl7ty/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-ww_gs9y3
         cwd: /tmp/pip-req-build-_86bl7ty/
    Complete output (17 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-req-build-_86bl7ty/setup.py", line 4, in <module>
        from pyowm.__version__ import __author__, __author_email__, __description__, __license__, __title__,\
      File "/tmp/pip-req-build-_86bl7ty/pyowm/__init__.py", line 4, in <module>
        from pyowm.owm import OWM
      File "/tmp/pip-req-build-_86bl7ty/pyowm/owm.py", line 5, in <module>
        from pyowm.agroapi10 import agro_manager
      File "/tmp/pip-req-build-_86bl7ty/pyowm/agroapi10/agro_manager.py", line 5, in <module>
        from pyowm.agroapi10.imagery import MetaTile, MetaGeoTiffImage, MetaPNGImage, SatelliteImage
      File "/tmp/pip-req-build-_86bl7ty/pyowm/agroapi10/imagery.py", line 6, in <module>
        from pyowm.commons.tile import Tile
      File "/tmp/pip-req-build-_86bl7ty/pyowm/commons/tile.py", line 6, in <module>
        from pyowm.utils.geo import Polygon
      File "/tmp/pip-req-build-_86bl7ty/pyowm/utils/geo.py", line 4, in <module>
        import geojson
    ModuleNotFoundError: No module named 'geojson'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

When I install pyowm's requirements.txt (from the root directory) first, the error disappears.

It seems like pip is ignoring the requirements.

csparpa commented 3 years ago

Hi @Tobiaqs this looks very similar to #318

It seems that installing pyowm with pip via Github cloning is failing because pyowm dependencies (including `geojson') are not processed and installed contextually.

My 2 cents (spoiler: I'm not a real expert on Python packaging). I've googled a lot and I found this answer: https://stackoverflow.com/a/58883371 where a guy says that when a you install a package from a wheel dynamic dependencies are not processed and therefore not installed (think of the wheel as a "snapshot" of the filesystem for a successful pyowm installation).

I suppose this is exactly what happens when you run pip with Github cloning:

pip install git+https://github.com/csparpa/pyowm.git@develop

So I'd say one way to fix this is something like this:

git clone ttps://github.com/csparpa/pyowm.git
cd pyowm && git checkou develop
pip install -r requirements.txt  # install dependencies
python setup.py install  # install develop branch code

Not very nice, but... I've tested out, it seems to work

csparpa commented 3 years ago

The workaround will be documented soon