OCHA-DAP / hdx-python-api

Python API for interacting with the HDX Data Portal
http://data.humdata.org
MIT License
80 stars 16 forks source link

Can't execute code from the docs: No module named 'hdx.api'; 'hdx' is not a package #73

Closed zxqfd555-pw closed 2 months ago

zxqfd555-pw commented 2 months ago

Hello!

I am trying to get access to HDX Datasets with the Python library. I am following this tutorial. I skipped the part with the API key, in the beginning, since I only wanted to read a dataset.

To set the stage, I create a virtual environment and install hdx-python-api with pip:

virtualenv venv
. venv/bin/activate
pip install hdx-python-api

These preparations finish successfully. But then I try to run the Python code from the next sections. So I launch python and enter the very first line from item 7. in the doc:

from hdx.utilities.easy_logging import setup_logging

And it ends up with an error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sergey/IoT-Pathway/experimental/sergey/mercy-corps/hdx.py", line 1, in <module>
    from hdx.api.configuration import Configuration
ModuleNotFoundError: No module named 'hdx.api'; 'hdx' is not a package

Could you please clarify how can I avoid it and download a dataset? The Python version is 3.11.9.

mcarans commented 2 months ago

@zxqfd555-pw This may be because your filename hdx.py matches the module name in the library. Please can you try changing your filename and let me know if that helps.

zxqfd555-pw commented 2 months ago

Indeed it was connected with the files test script with the same name present in my test folder. Thank you for your fast reply and sorry for the false alert!