ECCODES ERROR when opening .GRIB file in Spyder - python

I have accessed Anaconda Prompt for the environment that I will be working.
Once there, I have changed the directory to the place where I have the grib files that I will be working with, in order to install cfgrib, I have used the following command:
conda install -c conda-forge cfgrib
As the Python module depends on ECMWF ecCodes binary library, in the same Anaconda Prompt, I ran the following command:
conda install -c conda-forge eccodes
Then, opened the file in Spyder, and tried to run this simple script:
import xarray as xr
ds = xr.open_dataset('download.grib', engine='cfgrib')
ds
But got the following error:
Can't read index file 'C:\Users\name\Desktop\data\download.grib.90c91.idx'
Traceback (most recent call last):
File "C:\Users\name\anaconda3\envs\Weather\lib\site-packages\cfgrib\messages.py", line 351, in from_indexpath_or_filestream
self = cls.from_indexpath(indexpath)
File "C:\Users\name\anaconda3\envs\Weather\lib\site-packages\cfgrib\messages.py", line 323, in from_indexpath
return pickle.load(file)
EOFError: Ran out of input
Then,
An error ocurred while starting the kernel
ECCODES ERROR : Unable to find boot.def. Context path=D:/bld/eccodes_1593015095851/_h_env/Library/share/eccodes/definitions
Possible causes:
‑ The software is not correctly installed
‑ The environment variable ECCODES_DEFINITION_PATH is defined but incorrect ecCodes assertion failed: `0' in D:\bld\eccodes_1593015095851\work\src\grib_context.c:226
What am I missing here?
Edit 1
The problem also happens if I use Visual Studio Code.
In the terminal, if I am inside the directory that the GRIB files are stored, and I activate the environment that I am working with:
conda activate Weather
And then:
& C:/Users/name/anaconda3/envs/Weather/python.exe c:/Users/name/Desktop/data/3_climate/2mtemp_open.py
It gives the same error as above.

As the error says, ECCODES_DEFINITION_PATH was not set.
As I am using Anaconda on Windows 10, the path is the following
C:/Users/[USER]/Anaconda3/envs/envgeo/Library/share/eccodes/definitions
In order to set the environment variable, one can simply run
setx ECCODES_DEFINITION_PATH "[ECCODES definition path/directory]"
This should solve the problem.
However, a new one may emerge. As the .grib file may take a lot to run, consider using the data in the format NetCDF.

Related

Conda environments in VScode

I have two Anaconda environments I created, say A and B, plus the base env.
I have created environments A and B specific to what I do with them (different libraries).
Now I installed VScode. When I open VScode and set first the correct interpreter (A or B) in the lower part and run some python programs specific to A and B, the program does not run and error appears.
D:\Anaconda\envs\practica-mldl\lib\site-packages\numpy\__init__.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "D:\Anaconda\envs\practica-mldl\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
from . import multiarray
File "D:\Anaconda\envs\practica-mldl\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
from . import overrides
File "D:\Anaconda\envs\practica-mldl\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\Do\Python\ML practice\iris\own-knn.py", line 15, in <module>
import numpy as np
File "D:\Anaconda\envs\practica-mldl\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import core
File "D:\Anaconda\envs\practica-mldl\lib\site-packages\numpy\core\__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from "D:\Anaconda\envs\practica-mldl\python.exe"
* The NumPy version is: "1.19.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
PS D:\Do\Python\ML practice\iris> conda activate practica-mldl
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- cmd.exe
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
But when I open VScode through anaconda prompt by first activating the environment and opening VScode by typing code and running some programs, the program runs.
So from what I understand, simply changing the interpreter in VScode is not the same as opening VScode by activating first the environment. I thought by just changing the interpreter in VScode will work.
Is there a setup in VScode where I do not have to open VScode by activating the environments first so I can run python programs specific to that environment?
Thanks a lot!
Edit 1. Added error

Import failure when calling Anaconda Python from Windows shell

I want to call my Anaconda Python from the Windows shell. The goal is to eventually call it from MATLAB using a system call, so I have to use the plain Windows shell, and not the "Anaconda prompt".
I have a simple Python script that I want to run, but it doesn't get past the import statements:
> "C:\ProgramData\Anaconda3\python.exe" lhs.py
Traceback (most recent call last):
File "lhs.py", line 8, in <module>
import numpy
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
EDIT
I made a simplified Python script (error.py) containing only one line:
import numpy
I then call it as:
"C:\ProgramData\Anaconda3\python.exe" error.py
TL;DR
C:\ProgramData\Anaconda3\condabin\activate.bat YOURENVIRONMENTNAME && python N:\Temp\lhs.py
Long Answer
There is a similar issue reported on github. I found this by searching for the last few lines of your message. It is about this:
File "C:\Users\hanna\Anaconda3\lib\site-packages\tensorflow\python_init.py",
line 47, in
import numpy as np
File "C:\Users\hanna\Anaconda3\lib\site-packages\numpy_init_.py", line 140, in
from . import _distributor_init
File "C:\Users\hanna\Anaconda3\lib\site-packages\numpy_distributor_init.py",
line 34, in
from . import _mklinit
There, they link to a conda troubleshooting page:
Error messages like
Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll
Cause
NumPy is unable to load the correct MKL or Intel OpenMP runtime
libraries. This is almost always caused by one of two things:
The environment with NumPy has not been activated.
Another software vendor has installed MKL or Intel OpenMP
(libiomp5md.dll) files into the C:\Windows\System32 folder. These
files are being loaded before Anaconda's and they're not compatible.
If you are not activating your environments, start with doing that.
So let us try this first:
C:\\ProgramData\\Anaconda3\\condabin\\activate.bat
conda run -n yourenvironment C:\\path\\to\\your\\pythonfile\\lhs.py
(Yes, from a normal cmd terminal)
If that seems to work, you should be able to chain the two commands using &&. My own example looks like this:
F:\Programme\Programme\Anaconda3\condabin\activate.bat && conda run -n textrecognition N:\Temp\temp.py
This can be simplified further to
F:\Programme\Programme\Anaconda3\condabin\activate.bat textrecognition && python N:\Temp\temp.py
In case of the problem being number two, you have the option to load conda things before system32. This is supported in anaconda starting the following versions:
Python 2.7.15 build 14
Python 3.6.8 build 7
Python 3.7.2 build 8
To activate that, you need to set some environment variables to 1:
Control environment variables:
CONDA_DLL_SEARCH_MODIFICATION_ENABLE
CONDA_DLL_SEARCH_MODIFICATION_DEBUG
CONDA_DLL_SEARCH_MODIFICATION_NEVER_ADD_WINDOWS_DIRECTORY
CONDA_DLL_SEARCH_MODIFICATION_NEVER_ADD_CWD
To set variables on Windows, you may use either the CLI (Anaconda
Prompt, for example) or a Windows GUI.
CLI:
https://superuser.com/questions/79612/setting-and-getting-windows-environment-variables-from-the-command-prompt/79614
GUI:
http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-windows-gui/
These should be set to a value of 1 to enable them. For example, in an
anaconda prompt terminal:
set CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1
you need to activate your conda base in cmd before calling the script
call <path>\anaconda\Scripts\activate base
<path>\anaconda\python.exe <path>\scriptname.py

Install SCIP solver on Python3.5 Numberjack (OSX)

I am learning Constraint Programming in Python and, for the solving of the problems, I am supposed to use the SCIP solver. I have installed the Numberjack standard package from Github witch includes Mistral, Mistral2, Toulbar2, MipWrapper, SatWrapper, MiniSat and Walksat solvers.
Running my code I got the following error:
Traceback (most recent call last):
File "/Users/angelocoelho/anaconda3/lib/python3.5/site-packages/Numberjack/__init__.py", line 910, in load
lib = __import__(solverstring, fromlist=[solverspkg])
ImportError: No module named 'Numberjack.solvers.SCIP'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "grafosdefluxos.py", line 42, in <module>
solver = model.load('SCIP')
File "/Users/angelocoelho/anaconda3/lib/python3.5/site-packages/Numberjack/__init__.py", line 915, in load
solvername)
ImportError: ERROR: Failed during import, wrong module name? (SCIP)
I already ran make in 'scipoptsuite-3.1.0' and in 'scip-3.2.1', installed Numberjack-master's 'setup.py' and tried this:
python setup.py -solver SCIP
witch returned the error
Error: the solver 'SCIP' is not known, please use one of: Mistral, SatWrapper, Toulbar2, Walksat, MipWrapper, MiniSat, Mistral2
I have the SCIP folders alongside and inside the Numberjack folders.
I read and ran all the commands in the README and INSTALL files on how I could get this solver configured but I couldn't get it right.
How can I get SCIP available to solve the problems in Numberjack?
After talking to the assistant teacher I got the answer for this problem.
The folder where Numberjack/SCIP was being installed was not the one it was supposed to be, therefore it was not really included in the solver list. After completing the python setup.py build and python setup.py install installation I ran python setup.py build -solver SCIP and the terminal feedback stated
Successfully built solver interfaces for MipWrapper, SCIP
But the jupyter notebook didn't recognize the solver.
What solution should work having Anaconda (python3.5) already installed:
Download Numberjack (file "Numberjack-master.zip") and unpack it.
Download SCIP and copy the downloaded file, scipoptsuite-3.1.0.tgz. Paste it inside Numberjack-master unpacked directory. The path of it should be ~/Downloads/Numberjack-master/scipoptsuite-3.1.0.tgz.
In terminal run cd ~/Downloads/Numberjack-master (or your Numberjack-master directory path).
Then run python3.5 setup.py install --user.
In my case Jupyter was looking for the solvers in
~/anaconda3/lib/python3.5/site-packages/Numberjack/ and they were
not being installed there so, instead of using python, I used python3.5 since my Anaconda was the Python 3.5 package.
Why is there a scip-3.2.1 directory? The SCIP Opt Suite 3.1.0 contains SCIP 3.1.0. You need to make sure to run all setup and make commands exactly as stated on the Numberjack install page.

How to install additional packages in WinPython?

I have been using WinPython 2.2.5 with Python 2.7 and it works nice. The problem that I have is when I want to install additional libraries to use from the https://pypi.python.org repository.
For example I tried to install pdfminer which is in following link: https://pypi.python.org/pypi/pdfminer/
I have read that I can use pip install which is in the following path on my computer:
C:\WinPython-32bit-2.7.6.3\python-2.7.6\Scripts
On that directory I have saved the tar.gz file of pdfminer and from the windows command prompt on the aforementioned path I have typed:
pip install pdfminer(version number).tar.gz
It seems that it works fine, because there are no error messages, but when I open the winpython and in the command shell I put:
pdf2txt
to see if it works I got the following error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'pdf2txt' is not defined
What am I doing wrong?
According to the documentation, "PDFMiner comes with two handy tools: pdf2txt.py and dumppdf.py." So, instead of trying to run pdf2txt.py by importing it, you need to run it as it shows in the example in the documentation, like this:
$ pdf2txt.py -o output.html samples/naacl06-shinyama.pdf
where output.html is the file that is created from the mined text, and samples/naac106-shinyama.pdf is the PDF you want to mine.

Importing modules with python

I'm working with python 2.7 (32-bit) on Windows Vista. I downloaded some libraries including numpy, scipy, and pygame. When I try to import these modules the output says
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import numpy
ImportError: No module named numpy
I can find these modules in my python folders but for some reason it doesn't want to recognize it or some thing. (I made sure the file were compatible before downloading.)
Each package should contain a setup.py file. Run this with the command python setup.py install
For more information:
http://www.scipy.org/Installing_SciPy/Windows
http://pygame.org/install.html
"Everytime I run the command "python setup.py install" in the python shell it says SyntaxError: invalid syntax "
Please create a folder where you unzip the "numpy.zip" file, say the folder name is "c:\numpy"
Open a MS-DOS terminal (as described here : http://en.wikipedia.org/wiki/Command-line_interface), and type :
cd c:\numpy
python setup.py config
python setup.py install
This will set up the needed files in the correct folders for your python.
Enjoy !
To properly install this module:
In the Windows search bar (START MENU) type Command Prompt
Right-click on the Command Prompt icon (DO NOT go to cmd)
Click Run as Administrator
in the COMMAND PROMPT (DO NOT open cmd) type:
pip install numpy
This will install that module.
NOTE: If you are NOT in admin mode, you will get a message saying a fatal error has been raised.

Categories

Resources