I am trying to learn Python and following along some modules. I am using Anaconda Powershell Prompt and using Python 3.7 from there. I am trying to follow along via the code below.
Everything works until I get to the line
from wrf import getvar
When I do that line I receive this
>>> from wrf import getvar
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Paul\anaconda3\lib\site-packages\wrf\__init__.py", line 6, in <module>
from . import api
File "C:\Users\Paul\anaconda3\lib\site-packages\wrf\api.py", line 1, in <module>
from .config import (xarray_enabled, disable_xarray, enable_xarray,
File "C:\Users\Paul\anaconda3\lib\site-packages\wrf\config.py", line 62, in <module>
_init_local()
File "C:\Users\Paul\anaconda3\lib\site-packages\wrf\config.py", line 52, in _init_local
_try_enable_xarray()
File "C:\Users\Paul\anaconda3\lib\site-packages\wrf\config.py", line 17, in _try_enable_xarray
from xarray import DataArray
File "C:\Users\Paul\anaconda3\lib\site-packages\xarray\__init__.py", line 1, in <module>
from . import testing, tutorial
File "C:\Users\Paul\anaconda3\lib\site-packages\xarray\testing.py", line 9, in <module>
from xarray.core import duck_array_ops, formatting, utils
File "C:\Users\Paul\anaconda3\lib\site-packages\xarray\core\duck_array_ops.py", line 26, in <module>
from . import dask_array_compat, dask_array_ops, dtypes, npcompat, nputils
File "C:\Users\Paul\anaconda3\lib\site-packages\xarray\core\npcompat.py", line 72, in <module>
_SupportsDType[np.dtype],
File "C:\Users\Paul\anaconda3\lib\typing.py", line 275, in inner
return func(*args, **kwds)
File "C:\Users\Paul\anaconda3\lib\typing.py", line 999, in __class_getitem__
_check_generic(cls, params, len(cls.__parameters__))
File "C:\Users\Paul\anaconda3\lib\typing.py", line 209, in _check_generic
raise TypeError(f"{cls} is not a generic class")
TypeError: <class 'numpy.typing._dtype_like._SupportsDType'> is not a generic class
Looks like the last few lines return an error but as a beginner I have zero clue what this means.
This looks like a similar error to <class 'numpy.typing._dtype_like._SupportsDType'> is not a generic class when importing the plotly.express library - an incompatibility between wrf-python and numpy.
Try upgrading those libraries to the latest versions.
Related
I'm having some issues running checkov, I'm not familiar with python libraries, anyone can give me some hints?
This is working fine in some machines but not in this one in particular...
Running in CentOS:
$ checkov --directory cdk.out
Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in <module>
from checkov.main import run
File "/usr/local/lib/python3.6/site-packages/checkov/main.py", line 22, in <module>
from checkov.terraform.plan_runner import Runner as tf_plan_runner
File "/usr/local/lib/python3.6/site-packages/checkov/terraform/plan_runner.py", line 11, in <module>
from checkov.terraform.context_parsers.registry import parser_registry
File "/usr/local/lib/python3.6/site-packages/checkov/terraform/context_parsers/__init__.py", line 1, in <module>
from checkov.terraform.context_parsers.parsers import *
File "/usr/local/lib/python3.6/site-packages/checkov/terraform/context_parsers/parsers/provider_context_parser.py", line 1, in <module>
import hcl2
File "/usr/local/lib/python3.6/site-packages/hcl2/__init__.py", line 5, in <module>
from .api import load, loads
File "/usr/local/lib/python3.6/site-packages/hcl2/api.py", line 4, in <module>
from hcl2.parser import hcl2
File "/usr/local/lib/python3.6/site-packages/hcl2/parser.py", line 53, in <module>
hcl2 = Lark_StandAlone(transformer=DictTransformer())
File "/usr/local/lib/python3.6/site-packages/hcl2/lark_parser.py", line 8, in Lark_StandAlone
return Lark._load_from_dict(DATA, MEMO, **kwargs)
AttributeError: type object 'Lark' has no attribute '_load_from_dict'
After upgrading python from 3.6 to 3.8 and reinstalling checkov it worked just fine.
I'm trying to import geopandas in my script but I keep getting the following error:
Traceback (most recent call last):
File "C:/Users/USERNAME/Desktop/Scripts/Project1/folium_map/89. geographical chart 4.py", line 1, in <module>
import geopandas
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37\lib\site-packages\geopandas\__init__.py", line 1, in <module>
from geopandas.geoseries import GeoSeries
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37\lib\site-packages\geopandas\geoseries.py", line 12, in <module>
from geopandas.base import GeoPandasBase, _series_unary_op, _CoordinateIndexer
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37\lib\site-packages\geopandas\base.py", line 14, in <module>
from rtree.core import RTreeError
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37\lib\site-packages\rtree\__init__.py", line 1, in <module>
from .index import Rtree
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37\lib\site-packages\rtree\index.py", line 5, in <module>
from . import core
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37\lib\site-packages\rtree\core.py", line 133, in <module>
rt.Error_GetLastErrorNum.restype = ctypes.c_int
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 369, in __getattr__
func = self.__getitem__(name)
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 374, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'Error_GetLastErrorNum' not found
My code looks just like this:
import geopandas
Has anyone else received this error before? And if so, how did they fix it? Thanks in advance.
EDIT 05/02/19:
Also I have GDAL 2.3.3 amd64 installed.
I am getting an exception from scipy whenever I try to import the nltk package. The command and the error looks like this:
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 114, in <module>
from nltk.collocations import *
File "/usr/local/lib/python2.7/dist-packages/nltk/collocations.py", line 39, in <module>
from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/__init__.py", line 16, in <module>
from nltk.metrics.scores import (accuracy, precision, recall, f_measure,
File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/scores.py", line 16, in <module>
from scipy.stats.stats import betai
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/__init__.py", line 344, in <module>
from .stats import *
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py", line 176, in <module>
from . import distributions
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/_distn_infrastructure.py", line 43, in <module>
from new import instancemethod
File "new.py", line 107
return copy.deepcopy(self)
^
IndentationError: expected an indented block
I executed this command in a terminal (ubuntu 16.04 LTS system). I did not find anything about this error and the indentation doesn't look wrong.
The SyntaxError is in your file new.py (I guess it's in your current working directory). Try to switch to a directory where no new.py file is present (or move the new.py file in another directory), then the internal scipy import should work without problems.
On the other hand you can just upgrade to scipy 0.19.x. They removed the import there and it should work without problems.
Note that it's always a bad idea to name python files like builtin-modules! That's a common source for exceptions or unexpected behaviour.
I have following file structure:
/usr/share/pyshared/orca/scripts/toolkits/Gecko/script.py
In this file def getExtents is function that I have to access in following file i.e:
/usr/share/pyshared/orca/scripts/default.py
so I am trying to import function from script.py to the following file:
/usr/share/pyshared/orca/scripts/default.py
following line is added in /usr/share/pyshared/orca/scripts/default.py:
from orca.scripts.toolkits.Gecko.script import getExtents
But I get following errors:
File "<string>", line 1, in <module>
File "/usr/lib/pymodules/python2.7/orca/orca.py", line 1498, in main
init(pyatspi.Registry)
File "/usr/lib/pymodules/python2.7/orca/orca.py", line 1215, in init
loadUserSettings()
File "/usr/lib/pymodules/python2.7/orca/orca.py", line 837, in loadUserSettings
_scriptManager.activate()
File "/usr/lib/pymodules/python2.7/orca/script_manager.py", line 80, in activate
self.setActiveScript(self.getScript(None), "activate")
File "/usr/lib/pymodules/python2.7/orca/script_manager.py", line 247, in getScript
appScript = self.getDefaultScript()
File "/usr/lib/pymodules/python2.7/orca/script_manager.py", line 214, in getDefaultScript
import scripts.default as default
File "/usr/lib/pymodules/python2.7/orca/scripts/default.py", line 57, in <module>
from orca.scripts.toolkits.Gecko.script import getExtents
File "/usr/lib/pymodules/python2.7/orca/scripts/toolkits/Gecko/__init__.py", line 1, in <module>
from script import Script
File "/usr/lib/pymodules/python2.7/orca/scripts/toolkits/Gecko/script.py", line 52, in <module>
import orca.scripts.default as default
AttributeError: 'module' object has no attribute 'default'
I think you probably need
from orca.scripts import default
Also, as mentioned in the comments, check you've got the relevant __init__.py
edit: re-reading the stacktrace, looks like you've got a circular import too, you're trying to import orca.scripts.default in line 52 of "/usr/lib/pymodules/python2.7/orca/scripts/toolkits/Gecko/script.py"
Has anyone else encountered the situation where they have written unit tests for their code into a file named unittest.py, and found it to conflict with NumPy's unittest.py module? In other words, if I write this to unittest.py in a local directory:
if __name__ == "__main__":
print "pre-import"
#import numpy
print "post-import"
Then (no surprises here):
% python unittest.py
pre-import
post-import
But if I do:
if __name__ == "__main__":
print "pre-import"
import numpy
print "post-import"
I get:
% python unittest.py
pre-import
Traceback (most recent call last):
File "unittest.py", line 3, in <module>
import numpy
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/core/__init__.py", line 40, in <module>
from numpy.testing import Tester
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/testing/__init__.py", line 8, in <module>
from unittest import TestCase
ImportError: cannot import name TestCase
Subsequently, iPython fails to load:
% ipython
WARNING: IPython History requires SQLite, your history will not be saved
Traceback (most recent call last):
File "/home/jbbrown/local_bin/python/bin/ipython", line 7, in <module>
launch_new_instance()
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 402, in launch_new_instance
app.initialize()
File "<string>", line 2, in initialize
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/config/application.py", line 84, in catch_config_error
return method(app, *args, **kwargs)
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 312, in initialize
self.init_shell()
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 332, in init_shell
ipython_dir=self.ipython_dir)
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/config/configurable.py", line 318, in instance
inst = cls(*args, **kwargs)
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/frontend/terminal/interactiveshell.py", line 183, in __init__
user_module=user_module, custom_exceptions=custom_exceptions
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 478, in __init__
self.init_reload_doctest()
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 662, in init_reload_doctest
doctest_reload()
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/utils/doctestreload.py", line 72, in doctest_reload
import doctest
File "/home/jbbrown/local_bin/python/lib/python2.7/doctest.py", line 2118, in <module>
class DocTestCase(unittest.TestCase):
AttributeError: 'module' object has no attribute 'TestCase'
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev#scipy.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
c.Application.verbose_crash=True
Interestingly, if I move the import statement outside of the "if __name__" suite, e.g.,
print "pre-import"
import numpy
print "post-import"
if __name__ == "__main__":
pass
I get:
% python unittest.py
pre-import
pre-import
post-import
Traceback (most recent call last):
File "unittest.py", line 2, in <module>
import numpy
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/core/__init__.py", line 40, in <module>
from numpy.testing import Tester
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/testing/__init__.py", line 8, in <module>
from unittest import TestCase
ImportError: cannot import name TestCase
Of course it is trivial to change the name of the file containing my unit tests and avoid this, but I wonder if anyone else encountered this and thought of an elegant workaround that doesn't include renaming their unit test file?
You can switch to absolute imports by default on Python versions newer than 2.7:
from __future__ import absolute_import
if __name__ == "__main__":
print "pre-import"
import numpy
print "post-import"