I'm not being able to use the read_file method of geopandas. below is the code and the stack trace
import geopandas as gpd
path_to_data = gpd.datasets.get_path("nybb")
gdf = gpd.read_file(path_to_data)
error trace:
ImportError Traceback (most recent call last)
Input In [5], in <module>
1 path_to_data = gpd.datasets.get_path("nybb")
----> 2 gdf = gpd.read_file(path_to_data)
4 gdf
File ~/Desktop/Udemy_projects/multiple/lib/python3.9/site-packages/geopandas/io/file.py:166, in _read_file(filename, bbox, mask, rows, **kwargs)
104 def _read_file(filename, bbox=None, mask=None, rows=None, **kwargs):
105 """
106 Returns a GeoDataFrame from a file or URL.
107
(...)
164 by using the encoding keyword parameter, e.g. ``encoding='utf-8'``.
165 """
--> 166 _check_fiona("'read_file' function")
167 filename = _expand_user(filename)
169 if _is_url(filename):
File ~/Desktop/Udemy_projects/multiple/lib/python3.9/site-packages/geopandas/io/file.py:80, in _check_fiona(func)
78 def _check_fiona(func):
79 if fiona is None:
---> 80 raise ImportError(
81 f"the {func} requires the 'fiona' package, but it is not installed or does "
82 f"not import correctly.\nImporting fiona resulted in: {fiona_import_error}"
83 )
ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly.
Importing fiona resulted in: dlopen(/Users/junaid/Desktop/Udemy_projects/multiple/lib/python3.9/site-packages/fiona/ogrext.cpython-39-darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/proj#7/lib/libproj.19.dylib
Referenced from: /opt/homebrew/Cellar/gdal/3.4.1_1/lib/libgdal.30.dylib
Reason: tried: '/opt/homebrew/opt/proj#7/lib/libproj.19.dylib' (no such file), '/usr/local/lib/libproj.19.dylib' (no such file), '/usr/lib/libproj.19.dylib' (no such file)
It looks like geopandas is referening an older version of PROJ. I used to have proj 7.2 but now have 8.2.1 installed.
Also I have the following versions of fiona and gdal
fiona 1.8.19
GDAL 3.3.3
any help would be much appreciated
Have you tried to install the Fiona package? Because it requires this package from your error.
Related
I am starting with a ML model and importing libraries. Every library is working fine except MGLEARN which throws error:
ModuleNotFoundError: No module named 'MGLEARN'.
I didn't pip install anything.
import sys
print("Python version: {}".format(sys.version))
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
print("pandas version: {}".format(pd.__version__))
import matplotlib
print("matplotlib version: {}".format(matplotlib.__version__))
import numpy as np
print("NumPy version: {}".format(np.__version__))
import scipy as sp
print("SciPy version: {}".format(sp.__version__))
import IPython
print("IPython version: {}".format(IPython.__version__))
import sklearn
print("scikit-learn version: {}".format(sklearn.__version__))
import mglearn
The output I get
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 17
15 import sklearn
16 print("scikit-learn version: {}".format(sklearn.__version__))
---> 17 import MGLEARN
ModuleNotFoundError: No module named 'MGLEARN'
Pip install anything gives error
!pip install mglearn
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[7], line 1
----> 1 get_ipython().system('pip install mglearn')
File /lib/python3.10/site-packages/IPython/core/interactiveshell.py:2542, in InteractiveShell.system_piped(self, cmd)
2537 raise OSError("Background processes not supported.")
2539 # we explicitly do NOT return the subprocess status code, because
2540 # a non-None value would trigger :func:`sys.displayhook` calls.
2541 # Instead, we store the exit_code in user_ns.
-> 2542 self.user_ns['_exit_code'] = system(self.var_expand(cmd, depth=1))
File /lib/python3.10/site-packages/IPython/utils/_process_posix.py:129, in ProcessHandler.system(self, cmd)
125 enc = DEFAULT_ENCODING
127 # Patterns to match on the output, for pexpect. We read input and
128 # allow either a short timeout or EOF
--> 129 patterns = [pexpect.TIMEOUT, pexpect.EOF]
130 # the index of the EOF pattern in the list.
131 # even though we know it's 1, this call means we don't have to worry if
132 # we change the above list, and forget to change this value:
133 EOF_index = patterns.index(pexpect.EOF)
AttributeError: module 'pexpect' has no attribute 'TIMEOUT'
I am trying to read a .sav file. For this, I have installed pyreadstat using
conda install -c conda-forge pyreadstat
but when I run the following line of code (before even getting to reading the file):
import pyreadstat
I get this error: "AttributeError: module 'pandas' has no attribute 'Float64Dtype' ".
Any ideas on how to solve it?
Complete error is as follows
AttributeError Traceback (most recent call last)
Input In [3], in <cell line: 2>()
1 import pandas
----> 2 import pyreadstat
File ~\anaconda3\envs\dhdsblend2021\lib\site-packages\pyreadstat\__init__.py:17, in <module>
1 # #############################################################################
2 # Copyright 2018 Hoffmann-La Roche
3 #
(...)
14 # limitations under the License.
15 # #############################################################################
---> 17 from .pyreadstat import read_sas7bdat, read_xport, read_dta, read_sav, read_por, read_sas7bcat
18 from .pyreadstat import write_sav, write_dta, write_xport, write_por
19 from .pyreadstat import set_value_labels, set_catalog_to_sas
File pyreadstat\pyreadstat.pyx:1, in init pyreadstat.pyreadstat()
File pyreadstat\_readstat_writer.pyx:42, in init pyreadstat._readstat_writer()
File ~\anaconda3\envs\dhdsblend2021\lib\site-packages\pandas\__init__.py:258, in __getattr__(name)
254 from pandas.core.arrays.sparse import SparseArray as _SparseArray
256 return _SparseArray
--> 258 raise AttributeError(f"module 'pandas' has no attribute '{name}'")
Pyreadstat requires Pandas 1.2.0 at the very minimum. Please try updating pandas to a newer version.
I get this long error when i try importing pyplot in ipython. Everything works fine when i try the same in jupyter notebook.
I think I've tried all the suggestions I found about pyplot import errors. I tried reinstalling matplotlib, ipykernel, zmq etc etc., I tried rolling back to old versions. I've tried matching sys.path from notebook and my ipython kernel, but no success.
I'm using python 3.7, windows 10, ConEmu for ipython kernel.
from matplotlib import pyplot
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-02aaac1810fb> in <module>
----> 1 from matplotlib import pyplot
C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in <module>
2347 dict.__setitem__(rcParams, "backend", rcsetup._auto_backend_sentinel)
2348 # Set up the backend.
-> 2349 switch_backend(rcParams["backend"])
2350
2351 # Just to be safe. Interactive mode can be turned on without
C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in switch_backend(newbackend)
219 else "matplotlib.backends.backend_{}".format(newbackend.lower()))
220
--> 221 backend_mod = importlib.import_module(backend_name)
222 Backend = type(
223 "Backend", (matplotlib.backends._Backend,), vars(backend_mod))
C:\ProgramData\Python3\Continuum\anaconda3\lib\importlib\__init__.py in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
129
C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_tkagg.py in <module>
1 from . import _backend_tk
----> 2 from .backend_agg import FigureCanvasAgg
3 from ._backend_tk import (
4 _BackendTk, FigureCanvasTk, FigureManagerTk, NavigationToolbar2Tk)
5
C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in <module>
43
44 if _has_pil:
---> 45 from PIL import Image
46
47 backend_version = 'v2.2'
C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\PIL\Image.py in <module>
93 # Also note that Image.core is not a publicly documented interface,
94 # and should be considered private and subject to change.
---> 95 from . import _imaging as core
96
97 if __version__ != getattr(core, "PILLOW_VERSION", None):
ImportError: DLL load failed: The specified module could not be found.
After I installed the package Iris with conda install -c scitools iris,
Whether using Ipython console or Jupyter notebook, the iris was always failed to import. The error subroutine shows like:
---------------------------------------------------------------------------
CalledProcessError Traceback (most recent call last)
<ipython-input-1-005053b25f37> in <module>()
----> 1 import iris
/Users/TEST/anaconda/lib/python2.7/site-packages/iris/__init__.pyc in <module>()
110 import iris.cube
111 import iris._constraints
--> 112 import iris.fileformats
113 import iris.io
114
/Users/TEST/anaconda/lib/python2.7/site-packages/iris/fileformats/__init__.py in <module>()
23 from six.moves import (filter, input, map, range, zip) # noqa
24
---> 25 from iris.io.format_picker import (FileExtension, FormatAgent,
26 FormatSpecification, MagicNumber,
27 UriProtocol, LeadingLine)
/Users/TEST/anaconda/lib/python2.7/site-packages/iris/io/__init__.py in <module>()
31
32 import iris.fileformats
---> 33 import iris.fileformats.dot
34 import iris.cube
35 import iris.exceptions
/Users/TEST/anaconda/lib/python2.7/site-packages/iris/fileformats/dot.py in <module>()
41 # Check PATH
42 subprocess.check_output([_DOT_EXECUTABLE_PATH, '-V'],
---> 43 stderr=subprocess.STDOUT)
44 except OSError:
45 _DOT_EXECUTABLE_PATH = None
/Users/TEST/anaconda/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs)
571 if cmd is None:
572 cmd = popenargs[0]
--> 573 raise CalledProcessError(retcode, cmd, output=output)
574 return output
575
CalledProcessError: Command '['dot', '-V']' returned non-zero exit status -5
I raised a similar issue on the iris GitHub tracker (https://github.com/SciTools/iris/issues/1899). Essentially, as much as I believe it was intended to be optional, the way it has been implemented I think Iris actually requires a dot installation. With conda, that should look like:
conda install graphviz
HTH
In my particular case, this error was resolved by installing GraphViz.
I believe the root case of this issue is that the graphiz python bindings cannot find the command line utilities required to render the output into some form, e.g. .pdf, .svg or .png.
I have the Enthought Canopy installed on my Ubuntu 14.04. I'm trying to run sample matplotlib programs (from the library's website). Every attempt of running the program makes the Canopy's command prompt display following message:
TypeError Traceback (most recent call last)
/home/guras/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/site-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
202 else:
203 filename = fname
--> 204 __builtin__.execfile(filename, *where)
/home/guras/Python programy/pierwszy.py in <module>()
4 This example uses the Fahrenheit and Celsius scales.
5 """
----> 6 import matplotlib.pyplot as plt
7 import numpy as np
8
/home/guras/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
26 import matplotlib
27 import matplotlib.colorbar
---> 28 from matplotlib import style
29 from matplotlib import _pylab_helpers, interactive
30 from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike
/home/guras/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/style/__init__.py in <module>()
1 from __future__ import absolute_import
2
----> 3 from .core import use, context, available, library, reload_library
/home/guras/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/style/core.py in <module>()
147 # Load style library
148 # ==================
--> 149 _base_library = load_base_library()
150
151 library = None
/home/guras/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/style/core.py in load_base_library()
92 """Load style library defined in this package."""
93 library = dict()
---> 94 library.update(read_style_directory(BASE_LIBRARY_PATH))
95 return library
96
/home/guras/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/style/core.py in read_style_directory(style_dir)
125 styles = dict()
126 for path, name in iter_style_files(style_dir):
--> 127 styles[name] = rc_params_from_file(path, use_default_template=False)
128 return styles
129
TypeError: **rc_params_from_file() got an unexpected keyword argument 'use_default_template'**
Any ideas how to fix it?
The use_default_template keyword parameter was added to the rc_params_from_file function in matplotlib version 1.4.0rc1.
Most likely, your version of matplotlib is older than 1.4.0rc1 and needs to be upgraded.
If you have more than one installation of matplotlib installed, you'll need to make sure the directory containing the newer version is listed earlier than the older version in sys.path, or perhaps, simply delete the older version of matplotlib.
Use the Canopy Package Manager to update matplotlib to the latest version.