ecmwf / cdsapi

Python API to access the Copernicus Climate Data Store (CDS)
Apache License 2.0
230 stars 56 forks source link

ImportError: No module named cdsapi #10

Closed mqadimi closed 1 year ago

mqadimi commented 4 years ago

Greeting wizards; I'm using code below to download ERA5 data:

===========================================

!/usr/bin/env python

import cdsapi c = cdsapi.Client()

c.retrieve( 'reanalysis-era5-single-levels', { 'product_type':'reanalysis', 'format':'grib', 'variable':[ '10m_u_component_of_wind','10m_v_component_of_wind','2m_dewpoint_temperature', '2m_temperature','land_sea_mask','mean_sea_level_pressure', 'sea_ice_cover','sea_surface_temperature','skin_temperature', 'snow_depth','soil_temperature_level_1','soil_temperature_level_2', 'soil_temperature_level_3','soil_temperature_level_4','surface_pressure', 'volumetric_soil_water_layer_1','volumetric_soil_water_layer_2','volumetric_soil_water_layer_3', 'volumetric_soil_water_layer_4' ], 'date':'20170101/20170331', 'area':'60/80/10/150', 'time':[ '00:00','01:00','02:00', '03:00','04:00','05:00', '06:00','07:00','08:00', '09:00','10:00','11:00', '12:00' ] }, 'ERA5-20170101-20170331-sl.grib')

but there is an error saying:

File "GetERA5-20170101-20170331-sl.py", line 2, in import cdsapi ImportError: No module named cdsapi

I've installed cdsapi via "pip install cdsapi" and it's installed correctly. Any idea what's my problem?

c4rt0 commented 4 years ago

That's because you're running pip for python 2.7. Instead pip go pip3 :

pip3 install cdsapi

Now try to run your test api *.py ;)

sottsiougkos commented 3 years ago

The same with pip3

ndmsc commented 3 years ago

The first line in your script should be "#!/usr/bin/env python3" instead of "#!/usr/bin/env python"

fhcampbell commented 2 years ago

I tried both ndmsc and c4rt0's solutions. The suggestions did not work.

I also tried the 3.9 and it's still suggesting no cdsapi module.

!/users/neuro python3.9

import cdsapi cds = cdsapi.Client() cds.retrieve('reanalysis-era5-pressure-levels', { "variable": "temperature", "pressure_level": "1000", "product_type": "reanalysis", "date": "2017-12-01/2017-12-31", "time": "12:00", "format": "grib" }, 'download.grib')

vladamihaesei commented 2 years ago

Hi, I had same issue. I saved the lines code into a python script(myscript.py) then I run it by using the terminal with following comand : python myscript.py (make sure in running this command in the folder your have saved the python script). This works for my PC (I have MacBook).

hulitiao commented 2 years ago

Try these steps:

  1. Open cmd in the same file by shortcuts "shift" and right click your mouse at the same time;
  2. Enter command "pip install cdsapi" , and wait until completing installation;
  3. Run your python file in cmd. It won't show the ImportError agian.
JJJ2021 commented 2 years ago

It looks like a computer setting which may cause this issue. I finally get my py script running on Command Prompt after adding the ".cdsapirc" file to the following path C:\Users\username.cdsapirc. The funny side is that the same script does not proceed on Spyder showing error "No module name 'cdsapi' ".

EddyCMWF commented 1 year ago

Hi, This looks like you have a mix up with your python environments, as opposed to any specific issue with the cdsapi package.

There are several things you could try to solve the issue:

  1. From the command line, execute the request script with your python3 executable, this is equvilent to https://github.com/ecmwf/cdsapi/issues/10#issuecomment-871326986 but more explicit: python3 cds_request.py
  2. You could do the pip install within your request script using !pip install cdsapi. This would ensure that the cdsapi was installed on the environment that is invoked. This is probably considered bad practice.

As there is no specific change to the cdsapi code required for this issue I am going to close the ticket.

I will also highlight the C3S user support channels who are generally quite good at responding to these sort of problems: https://cds.climate.copernicus.eu/cdsapp#!/usersupport

All the best, Eddy

8painkiller8 commented 11 months ago

I encountered the same issue yesterday, while trying to use pip3. Somehow the setuptools package had been deleted in my Python environment and I just needed to download it again using:

pip3 install setuptools

ditsiaou commented 7 months ago

Hello, just for reference I had this error and I followed the solution proposed by @vladamihaesei and it worked. I work in a cluster using Centos. (Description: CentOS Linux release 7.9.2009 (Core) Release: 7.9.2009 )

Talha2647 commented 6 months ago

encountered the same problem of no module "cdsapi", @8painkiller8 solution worked for me