csparpa / pyowm

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

v3/develop "clean" setup install always fails with geojson ModuleNotFoundError issue #318

Closed idcrook closed 3 years ago

idcrook commented 4 years ago

When trying to add pyowm (@develop) as a dependency package in setup.py or pip-installing standalone into a virtualenv, am always getting an error about missing dependency

Collecting geojson>=2.5.0 (from timetemp3==0.1.0)
  Using cached https://files.pythonhosted.org/packages/e4/8d/9e28e9af95739e6d2d2f8d4bef0b3432da40b7c3588fbad4298c1be09e48/geojson-2.5.0-py2.py3-none-any.whl
...
Collecting pyowm@ git+https://github.com/csparpa/pyowm.git@develop#egg=pyowm-3.0.0 from git+https://github.com/csparpa/pyowm.git@develop#egg=pyowm-3.0.0 (from timetemp3==0.1.0)
  Cloning https://github.com/csparpa/pyowm.git (to revision develop) to /tmp/pip-install-ku15x6fb/pyowm
Branch 'develop' set up to track remote branch 'develop' from 'origin'.
Switched to a new branch 'develop'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-ku15x6fb/pyowm/setup.py", line 4, in <module>
        from pyowm.__version__ import __author__, __author_email__, __description__, __license__, __title__,\
      File "/tmp/pip-install-ku15x6fb/pyowm/pyowm/__init__.py", line 4, in <module>
        from pyowm.owm import OWM
      File "/tmp/pip-install-ku15x6fb/pyowm/pyowm/owm.py", line 5, in <module>
        from pyowm.agroapi10 import agro_manager
      File "/tmp/pip-install-ku15x6fb/pyowm/pyowm/agroapi10/agro_manager.py", line 5, in <module>
        from pyowm.agroapi10.imagery import MetaTile, MetaGeoTiffImage, MetaPNGImage, SatelliteImage
      File "/tmp/pip-install-ku15x6fb/pyowm/pyowm/agroapi10/imagery.py", line 6, in <module>
        from pyowm.commons.tile import Tile
      File "/tmp/pip-install-ku15x6fb/pyowm/pyowm/commons/tile.py", line 6, in <module>
        from pyowm.utils.geo import Polygon
      File "/tmp/pip-install-ku15x6fb/pyowm/pyowm/utils/geo.py", line 4, in <module>
        import geojson
    ModuleNotFoundError: No module named 'geojson'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-ku15x6fb/pyowm/

As you can see, I explicitly had geojson listed as an install_requires dependency to attempt to workaround, but this did not work.

workaround

Pre-Installing the geojson package into the virtualenv (or with pip) gets rid of the error, but this work-around should not be necessary. Not sure what is going wrong.

# work-around for missing geojson dependency
pip3 install --user geojson

Python 3.7.3, pip3 18.1 on a Raspberry Pi running Raspbian.

# virtualenv - work-around for missing geojson dependency
pip install geojson

Python 3.7.3, pip 20.1 virtualenv on same machine

idcrook commented 4 years ago

Is it possible that setup.py would additionally need setup_requires=['geojson'] (or equivalent) for it to work "out of the box"?

csparpa commented 4 years ago

Hi @idcrook, all dependencies - including geojson - are stated in setup.py https://github.com/csparpa/pyowm/blob/e35446ebe081c0b14a25dca0f7f8105836745b04/setup.py#L18 therefore you should not run any pre-install command.

You've probably edited the logs you pasted here as I can't see the original install command

I've tried to reproduce the issue on my host with but I cannot, it's working fine. I'm running Ubuntu 18.04.4 LTS

That's what I do:

$ virtualenv --version
16.6.0

$ virtualenv -p python3.7 myvenv

$ source myvenv/bin/activate

(myvenv) $ python -V
Python 3.7.0

(myvenv) $ pip3 -V
pip 20.1.1 from [...] (python 3.7)

(myvenv) $ pip3 install pyowm
Collecting pyowm
  Using cached pyowm-3.0.0-py3-none-any.whl (3.3 MB)
Collecting requests<3,>=2.20.0
  Using cached requests-2.24.0-py2.py3-none-any.whl (61 kB)
Collecting PySocks<2,==1.7.1
  Using cached PySocks-1.7.1-py3-none-any.whl (16 kB)
Collecting geojson<3,>=2.3.0
  Using cached geojson-2.5.0-py2.py3-none-any.whl (14 kB)
Collecting idna<3,>=2.5
  Using cached idna-2.9-py2.py3-none-any.whl (58 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2020.6.20-py2.py3-none-any.whl (156 kB)
Collecting chardet<4,>=3.0.2
  Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
  Using cached urllib3-1.25.9-py2.py3-none-any.whl (126 kB)
Installing collected packages: idna, certifi, chardet, urllib3, requests, PySocks, geojson, pyowm
Successfully installed PySocks-1.7.1 certifi-2020.6.20 chardet-3.0.4 geojson-2.5.0 idna-2.9 pyowm-3.0.0 requests-2.24.0 urllib3-1.25.9

(myvenv) $ echo $?
0

(myvenv) $ python -c 'import pyowm; print("hello")'
hello

You said this is your setup

Python 3.7.3, pip3 18.1 on a Raspberry Pi running Raspbian.

At this point, I would ask you to provide me with:

Thanks, let me know

idcrook commented 4 years ago

yeah, the "..." was meant to show truncation. I intended to show even if geojson dependency was specified and installed "earlier" the error still appears.

I saw that geojson is in setup. I think the error might arise at the nested setup of pyowm itself; the depended-upon module is not yet available to the pyowm/setup.py?

This is reproducible on "clean" Raspbian Buster on "bare metal". I've seen the same error on two Pis. I've observed same error mode with a venv and without a venv (using whatever the pip out-of-the-box defaults are on Raspberry Pi OS)

steps to reproduce

# python and build system dependencies
sudo apt install -y git build-essential python3-setuptools python3-dev \
    python3-pip python3-venv python3-wheel

# for extra systemd functionality
sudo apt install python3-systemd

# additional system dependencies for Adafruit-LED-Backpack
sudo apt install python3-smbus python3-pil

# work-around for missing geojson dependency in current pyowm development
## pip3 install --user geojson
## pip3 install geojson # is also possible (implicit `--user` if sudo is not used) with same results

mkdir ~/projects
cd ~/projects
git clone https://github.com/idcrook/timetemp3.git
cd timetemp3

# perform the python setup, which also includes dependencies 
pip3 install .

contents of setup.py - https://github.com/idcrook/timetemp3/blob/master/setup.py

salient part reproduced here (note the develop branch referenced for pyowm):

    install_requires=[
        # 'geojson>=2.5.0',  # missing implicit dependency in pyowm develop/v3 branch
        'python-nest>=4.1.0',
        'Adafruit_BMP @ git+https://github.com/adafruit/Adafruit_Python_BMP.git@master#egg=Adafruit_BMP-1.5.2',
        'Adafruit_LED_Backpack @ git+https://github.com/adafruit/Adafruit_Python_LED_Backpack.git@master#egg=Adafruit_LED_Backpack-1.8.1',
        'phant3 @ https://github.com/idcrook/python3-phant.git@master#egg=phant3-0.1.0',
        'pyowm @ git+https://github.com/csparpa/pyowm.git@develop#egg=pyowm-3.0.0',
    ],

The same error occurs with or without the geojson entry in install_requires= list.

If the pip3 install --user geojson is performed ahead of the pip3 install . it now completes successfully without the error.

csparpa commented 3 years ago

@idcrook sorry for the long wait Take a look here: https://github.com/csparpa/pyowm/issues/341#issuecomment-701585822

idcrook commented 3 years ago

I haven't tested with a "clean system" recently, but in a recent re-install, I pre-installed pip3 install --user geojson and things worked. I am OK with this documented work-around for my purposes..

I would expect the install_requires in my setup.py should work the same as https://github.com/csparpa/pyowm/issues/341#issuecomment-701585822 but as you mentioned for yourself, I , too, am not a python packaging expert.

install_requires=[
        # 'geojson>=2.5.0',  # missing implicit dependency in pyowm develop/v3 branch
#...
        'pyowm @ git+https://github.com/csparpa/pyowm.git@develop#egg=pyowm-3.0.0',
    ],
csparpa commented 3 years ago

Ok cool, I will update the project documentation so the workaround is well-known

Thanks for supporting on this!