Search code examples
pythonbashimportimporterror

ImportError: No module named ecmwfapi


I am having a hard time using the ecmwf-api-client.

I have successfully installed the interface.

I have also created a ~/.ecmwfapirc file with my credentials.

I have saved the test script in a file: myMac ~ % ./test.sh

When I run the script I get the following error:

Traceback (most recent call last):
  File "./test.sh", line 2, in <module>
    from ecmwfapi import ECMWFDataServer
ImportError: No module named ecmwfapi

I am not sure what I am doing wrong, as I have followed the instructions provided.

Edit:

I thought this might be caused by a conflict between pip and python, so I made sure to have compatible versions:

  • pip 22.0.3 (python 3.9)
  • Python 3.9.10

Also, I created an alias in my ~/.bashrc for Python 3:

alias py3=python3

so as to do something like: $py3 -m pip install ecmwf-api-client

(I have uninstalled the api version I had previously installed before continuing)

However, it's still not working. The plot thickens.


Solution

  • There, I fixed it.

    I came across this, and although the accepted answer seemed plausible, it didn't do the trick for me. Even though the default version of python I am using is 3.9.10, when trying to install pip from scratch I got a 'ERROR: This script does not work on Python 2.7 The minimum supported Python version is 3.7'.

    While looking into this, I found this other issue, and if you read through the comments you'll soon find out that the relationship between Homebrew and Python <3 is troublesome.

    So, assuming that for some reason pip was targeting Python 2.7, which is indeed installed but to my knowledge not used, I ran pip2 install ecmwf-api-client, which gave me a deprecation warning, but did its job.

    I can now connect to the API, everything seems to be working correctly.