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
NameError: name '_DType_co' is not defined #5631
Comments
@monocongo does it raise an error if you try importing numpy without xarray installed? |
I get the same error, but can $ pip install --upgrade pip
$ pip install xarray
$ python3
>>> import numpy
>>> import xarray
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "env/lib/python3.7/site-packages/xarray/__init__.py", line 3, in <module>
from . import testing, tutorial, ufuncs
File "env/lib/python3.7/site-packages/xarray/testing.py", line 8, in <module>
from xarray.core import duck_array_ops, formatting, utils
File "env/lib/python3.7/site-packages/xarray/core/duck_array_ops.py", line 16, in <module>
from . import dask_array_compat, dask_array_ops, dtypes, npcompat, nputils
File "env/lib/python3.7/site-packages/xarray/core/npcompat.py", line 81, in <module>
from numpy.typing import ArrayLike, DTypeLike
File "env/lib/python3.7/site-packages/numpy/typing/__init__.py", line 316, in <module>
from ._dtype_like import (
File "env/lib/python3.7/site-packages/numpy/typing/_dtype_like.py", line 95, in <module>
class _SupportsDType(Generic[_DType_co]):
NameError: name '_DType_co' is not defined |
What happens if you just write |
I get the same error, as expected: >>> import numpy.typing
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "env/lib/python3.7/site-packages/numpy/typing/__init__.py", line 316, in <module>
from ._dtype_like import (
File "env/lib/python3.7/site-packages/numpy/typing/_dtype_like.py", line 95, in <module>
class _SupportsDType(Generic[_DType_co]):
NameError: name '_DType_co' is not defined
>>> numpy.version.version
'1.21.1' numpy is aware of this issue. It looks like it is only an issue for |
OK, closing this over here since it seems to be a bug with numpy rather than xarray |
From numpy/numpy#19521: installing typing-extensions may help when running on python 3.7. |
Thanks to all for your help. Installing typing-extensions did solve the problem, thanks for the heads up @rhkleijn |
What happened: I installed a package that has xarray as a dependency. I then ran the package's console script, which resulted in the NameError shown below.
What you expected to happen: Successful import of the xarray package.
Minimal Complete Verifiable Example:
Anything else we need to know?:
This does not happen if I just install xarray, so there seems to be a conflict with another dependency package at play here. Are there methods for finding namespace conflicts like this without resorting to a "manual" method of trying all the various combinations? It seems that I've included a version of another package in my requirements that has a namespace conflict with xarray -- how can I work out which this is? Or maybe a simpler solution is to not use specific versions in the
requirements.txt
of the package and instead let conda work out the correct/latest versions?Thanks in advance for any ideas on where to look to resolve this issue (and in general for all the work that goes into xarray's care and feeding).
Environment:
Linux (Ubuntu 20.04)
Anaconda, Python 3.7
The text was updated successfully, but these errors were encountered: