Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation Error #184

Open
gHashFlyer opened this issue Apr 27, 2021 · 9 comments
Open

Installation Error #184

gHashFlyer opened this issue Apr 27, 2021 · 9 comments

Comments

@gHashFlyer
Copy link

I tried to install on Windows 10, 64-bit via powershell and got this...

PS C:\Users\garen> pip install pygrib
Collecting pygrib
Using cached pygrib-2.1.3.tar.gz (21.7 MB)
Installing build dependencies ... done
WARNING: Missing build requirements in pyproject.toml for pygrib from https://files.pythonhosted.org/packages/96/34/f76696b84d0249e41154f3bb3345bd05aa5385bddceb04e6ccbbde5b7ab0/pygrib-2.1.3.tar.gz#sha256=a22552e2e58c9eb9b5750a2d5a8f055334ad2a6a4fb8a6d56261356196ebe651.
WARNING: The project does not specify a build backend, and pip cannot fall back to setuptools without 'wheel'.
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing wheel metadata ... done
Collecting numpy
Using cached numpy-1.20.2-cp39-cp39-win_amd64.whl (13.7 MB)
Collecting pyproj
Using cached pyproj-3.0.1-cp39-cp39-win_amd64.whl (14.5 MB)
Collecting certifi
Using cached certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
Building wheels for collected packages: pygrib
Building wheel for pygrib (PEP 517) ... error
ERROR: Command errored out with exit status 1:
command: 'c:\python39\python.exe' 'c:\python39\lib\site-packages\pip_vendor\pep517_in_process.py' build_wheel 'C:\Users\garen\AppData\Local\Temp\tmp3m4z_f6s'
cwd: C:\Users\garen\AppData\Local\Temp\pip-install-izcs_lz9\pygrib
Complete output (21 lines):
eccodes not found, build may fail...
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.9
creating build\lib.win-amd64-3.9\pygrib
copying pygrib_init_.py -> build\lib.win-amd64-3.9\pygrib
running build_ext
cythoning pygrib/_pygrib.pyx to pygrib_pygrib.c
C:\Users\garen\AppData\Local\Temp\pip-build-env-8_bbz0fk\overlay\Lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\garen\AppData\Local\Temp\pip-install-izcs_lz9\pygrib\pygrib_pygrib.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building 'pygrib._pygrib' extension
creating build\temp.win-amd64-3.9
creating build\temp.win-amd64-3.9\Release
creating build\temp.win-amd64-3.9\Release\pygrib
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29333\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\python39\include -Ic:\python39\include -IC:\Users\garen\AppData\Local\Temp\pip-build-env-8_bbz0fk\overlay\Lib\site-packages\numpy\core\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29333\include -IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt /Tcpygrib_pygrib.c /Fobuild\temp.win-amd64-3.9\Release\pygrib_pygrib.obj
_pygrib.c
C:\Users\garen\AppData\Local\Temp\pip-build-env-8_bbz0fk\overlay\Lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
pygrib_pygrib.c(622): fatal error C1083: Cannot open include file: 'grib_api.h': No such file or directory
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29333\bin\HostX86\x64\cl.exe' failed with exit code 2

ERROR: Failed building wheel for pygrib
Failed to build pygrib
ERROR: Could not build wheels for pygrib which use PEP 517 and cannot be installed directly

@jswhit
Copy link
Owner

jswhit commented Apr 27, 2021

there is no windows binary wheel, so it's trying to install from source, and the eccodes C library is not found. If you want to build from source, you have to build the eccodes library first.

@IrisiumLouis
Copy link

@jswhit, Can you explain precisely please? I have the same problem I think and even with "pip install eccodes" I can't import the module pygrib.
The result of "pip install pygrib":
Collecting pygrib
Using cached pygrib-2.1.4.tar.gz (21.8 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in c:\users\louis\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from pygrib) (1.21.5)
Requirement already satisfied: pyproj in c:\users\louis\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from pygrib) (3.3.0)
Requirement already satisfied: certifi in c:\users\louis\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from pyproj->pygrib) (2021.10.8)
Building wheels for collected packages: pygrib
Building wheel for pygrib (pyproject.toml) ... error
error: subprocess-exited-with-error

× Building wheel for pygrib (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [10 lines of output]
eccodes not found, build may fail...
running bdist_wheel
running build
running build_py
running build_ext
cythoning src/pygrib/_pygrib.pyx to src/pygrib_pygrib.c
C:\Users\louis\AppData\Local\Temp\pip-build-env-2g1cnr4w\overlay\Lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\louis\AppData\Local\Temp\pip-install-j7iyugex\pygrib_b22aff928f924a139cb8275e547e4c66\src\pygrib_pygrib.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building 'pygrib._pygrib' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pygrib
Failed to build pygrib
ERROR: Could not build wheels for pygrib, which is required to install pyproject.toml-based projects

@damarvin
Copy link

For "you have to build the eccodes library first": so why is eccodes missing in pyproject.toml dependencies?
When I call pip install eccodes pygrib eccodes gets through, still MS compiler complaints about missing C header file:

src/pygrib\_pygrib.c(697): fatal error C1083: Cannot open include file: 'grib_api.h': No such file or directory
error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.30.30705\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2

There is no grib_api.h in your project, is it?
May I suggest to be more verbose in installation hints?
conda is not really an option for me, and it also struggles.

@h-sharif
Copy link

I think this problem probably happens because ecCodes was not installed properly on windows as the developer site mentioned: "Windows is not a native platform for technical work at ECMWF. Therefore, ECMWF will need the help of the external user community to support these versions of ecCodes and Magics in the future". I had the same issue before, but when I migrated to Linux, everything works well.

@BrieucD
Copy link

BrieucD commented Nov 22, 2022

I had the same problem with pip. On windows, it may not be possible to install with pip. But you can get it through anaconda (conda install pygrib) with an initial full upgrade of packages (conda update --all --yes). Or you can get a Linux emulator.

@mackenzie-grimes-noaa
Copy link

mackenzie-grimes-noaa commented Jun 30, 2023

Doesn't seem to be a Windows-specific issue: I encountered this error on macos as well, where the eccodes python package is installed, but pygrib fails to locate it. My environment:

  • OS: macos
  • Python version: 3.11.4
  • Virtualenv: venv

Possible cause

The README.md section about manually building pygrib mentions that pygrib will

  • first look at the env var $ECCODES_DIR before attempting to discover the location of eccodes auto-magically in common directories.
  • If it fails to find eccodes in any of those places, that's when the "grib_api.h": No such file or directory error is thrown which is causing problems for me and everyone above.

    pygrib/setup.py

    Lines 51 to 62 in 40558bf

    if os.environ.get("GRIBAPI_DIR"):
    searchdirs.append(os.environ["GRIBAPI_DIR"])
    if os.environ.get("ECCODES_DIR"):
    searchdirs.append(os.environ["ECCODES_DIR"])
    if os.environ.get("CONDA_PREFIX"):
    searchdirs.append(os.environ["CONDA_PREFIX"])
    searchdirs.append(os.path.join(os.environ["CONDA_PREFIX"],'Library')) # windows
    searchdirs += [
    os.path.expanduser("~"),
    "/usr",
    "/usr/local",
    "/opt/local",

I think in my case it's because I'm using a python virtualenv and not installing dependencies in the typical machine-wide directories.

Workaround

Here's a workaround that explicitly sets the environment variable so pygrib has no problem finding and making use of eccodes:

# install dependency manually before attempting to install pygrib
pip install eccodes;

# lookup location of installed eccodes package and set $ECCODES_DIR to it
export ECCODES_DIR="$( pip show eccodes | grep "Location" | cut -d ' ' -f 2 )/eccodes"

# now pygrib will easily find the eccodes location and succeed install
pip install pygrib;

I was able to install and use pygrib with this approach, without needing to mix pip with conda, brew, apt, or other package managers like a lot of other workarounds suggest (115, 180, 184, 211 and 19)

Ideally pip install pygrib would install and link to its dependencies without any of these workarounds, but I couldn't find the root cause of the issue internal to pygrib.

@arisliang
Copy link

Doesn't seem to be a Windows-specific issue: I encountered this error on macos as well, where the eccodes python package is installed, but pygrib fails to locate it. My environment:

  • OS: macos
  • Python version: 3.11.4
  • Virtualenv: venv

Possible cause

The README.md section about manually building pygrib mentions that pygrib will

  • first look at the env var $ECCODES_DIR before attempting to discover the location of eccodes auto-magically in common directories.
  • If it fails to find eccodes in any of those places, that's when the "grib_api.h": No such file or directory error is thrown which is causing problems for me and everyone above.

    pygrib/setup.py

    Lines 51 to 62 in 40558bf

    if os.environ.get("GRIBAPI_DIR"):
    searchdirs.append(os.environ["GRIBAPI_DIR"])
    if os.environ.get("ECCODES_DIR"):
    searchdirs.append(os.environ["ECCODES_DIR"])
    if os.environ.get("CONDA_PREFIX"):
    searchdirs.append(os.environ["CONDA_PREFIX"])
    searchdirs.append(os.path.join(os.environ["CONDA_PREFIX"],'Library')) # windows
    searchdirs += [
    os.path.expanduser("~"),
    "/usr",
    "/usr/local",
    "/opt/local",

I think in my case it's because I'm using a python virtualenv and not installing dependencies in the typical machine-wide directories.

Workaround

Here's a workaround that explicitly sets the environment variable so pygrib has no problem finding and making use of eccodes:

# install dependency manually before attempting to install pygrib
pip install eccodes;

# lookup location of installed eccodes package and set $ECCODES_DIR to it
export ECCODES_DIR="$( pip show eccodes | grep "Location" | cut -d ' ' -f 2 )/eccodes"

# now pygrib will easily find the eccodes location and succeed install
pip install pygrib;

I was able to install and use pygrib with this approach, without needing to mix pip with conda, brew, apt, or other package managers like a lot of other workarounds suggest (115, 180, 184, 211 and 19)

Ideally pip install pygrib would install and link to its dependencies without any of these workarounds, but I couldn't find the root cause of the issue internal to pygrib.

Any workarounds for windows? Would be good to install it without conda.

@mackenzie-grimes-noaa
Copy link

Any workarounds for windows? Would be good to install it without conda.

I don't have a tidy Windows cmd script that does the whole install automatically like the above Bash script, but you should be able to follow the same steps on Windows one at a time.

The main differences are that you set environment variables with SET instead of export, and the path separator in Windows is \ instead of /.

  1. pip install eccodes
  2. pip show eccodes
    1. Find the line that starts with Location: , copy that path, and append the string \eccodes to the end
  3. SET ECCODES_DIR=your\path\from\previous\step
    1. For example, if pip showed the Location of your eccodes package is C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python311\Scripts, then your command would be:
    2. SET ECCODES_DIR=C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python311\Scripts\eccodes
  4. pip install pygrib
    1. This install should now succeed without error.

@mackenzie-grimes-noaa
Copy link

Doesn't seem to be a Windows-specific issue: I encountered this error on macos as well, where the eccodes python package is installed, but pygrib fails to locate it. My environment:

  • OS: macos
  • Python version: 3.11.4
  • Virtualenv: venv

UPDATE: as of pygrib version 2.1.6 (released July 2024), I am no longer encountering this problem. 🎉 🎉 No install workaround was needed now.

I just created a brand new virtual environment:

python3 -m venv .venv && source .venv/bin/activate

Then ran:

pip install pygrib==2.1.6

Which eventually printed out:

Successfully installed certifi-2025.1.31 numpy-2.2.2 packaging-24.2 pygrib-2.1.6 pyproj-3.7.0

My environment:

  • OS: macos
  • Python version: 3.12.8
  • Virtualenv: venv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants