Problem with matplotlib - python 3.11: ImportError: DLL load failed while importing _path: - python-3.x

I have the same case which is mentioned in:
Problem with matplotlib when imported with python 3.9: ImportError: DLL load failed while importing _path:
but i have one version of python installed (version 3.11) and the path is correct. I do not know how to solving this problem. Could you help me?
I checked if the library is installed in the correct directory. It's correct. The numpy module works and is in the same directory as matplotlib. I have one version installed - python 3.11. I work with Python's IDLE.
Whole bug is:
"
Traceback (most recent call last):
File "C:/Users/Admin/AppData/Local/Programs/Python/Python311/simple-plot.py", line 1, in <module>
import matplotlib
File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\__init__.py", line 113, in <module>
from . import _api, _version, cbook, _docstring, rcsetup
File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\rcsetup.py", line 27, in <module>
from matplotlib.colors import Colormap, is_color_like
File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\colors.py", line 56, in <module>
from matplotlib import _api, _cm, cbook, scale
File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\scale.py", line 22, in <module>
from matplotlib.ticker import (
File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\ticker.py", line 138, in <module>
from matplotlib import transforms as mtransforms
File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\transforms.py", line 49, in <module>
from matplotlib._path import (
ImportError: DLL load failed while importing _path: Nie można odnaleźć określonego modułu.
"

I had a similar issue.
Official Author's Recommendation
https://github.com/matplotlib/matplotlib/issues/24704
The issue can be worked around by using an additional dependency:
pip install msvc-runtime
You can specify this in your requirements like so:
msvc-runtime; sys_platform == 'win32'
Therefore it will only install for Window's users.
Further options
The above didn't work in my case. My context is that I am using a Docker container based on the windowsservercore-ltsc2022 image.
Instead I installed the vcredist manually (I've included a more verbose set of steps as I use chocolatey. Do refer to the latest chocolatey website for any updated install instructions):
# Use powershell
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Install chocolatey
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# Install matplotlib workaround
# https://github.com/matplotlib/matplotlib/issues/24704 # Remove after matplotlib 3.7
RUN choco install -y --limit-output vcredist-all

Related

AttributeError: dlsym(RTLD_DEFAULT, Error_GetLastErrorNum): symbol not found

I recently downloaded the OSMnx package to work with street networks. However, it always gives me back the error below whenever I try to import the package. I've followed several steps that people from other posts suggested, but nothing changes. If anyone has had this problem or knows a way to solve it, please share it with me. Thank you!
Traceback (most recent call last):
File "/Users/qle/Documents/OSMnx/test.py", line 1, in <module>
import osmnx as ox
File "/Users/qle/Library/Python/3.8/lib/python/site-packages/osmnx/__init__.py", line 3, in <module>
from ._api import *
File "/Users/qle/Library/Python/3.8/lib/python/site-packages/osmnx/_api.py", line 3, in <module>
from .bearing import add_edge_bearings
File "/Users/qle/Library/Python/3.8/lib/python/site-packages/osmnx/bearing.py", line 9, in <module>
from . import projection
File "/Users/qle/Library/Python/3.8/lib/python/site-packages/osmnx/projection.py", line 3, in <module>
import geopandas as gpd
File "/Users/qle/Library/Python/3.8/lib/python/site-packages/geopandas/__init__.py", line 1, in <module>
from geopandas._config import options # noqa
File "/Users/qle/Library/Python/3.8/lib/python/site-packages/geopandas/_config.py", line 126, in <module>
default_value=_default_use_pygeos(),
File "/Users/qle/Library/Python/3.8/lib/python/site-packages/geopandas/_config.py", line 112, in _default_use_pygeos
import geopandas._compat as compat
File "/Users/qle/Library/Python/3.8/lib/python/site-packages/geopandas/_compat.py", line 202, in <module>
import rtree # noqa
File "/Users/qle/Library/Python/3.8/lib/python/site-packages/rtree/__init__.py", line 9, in <module>
from .index import Rtree, Index # noqa
File "/Users/qle/Library/Python/3.8/lib/python/site-packages/rtree/index.py", line 6, in <module>
from . import core
File "/Users/qle/Library/Python/3.8/lib/python/site-packages/rtree/core.py", line 77, in <module>
rt.Error_GetLastErrorNum.restype = ctypes.c_int
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 386, in __getattr__
func = self.__getitem__(name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 391, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, Error_GetLastErrorNum): symbol not found
Your error means, that rtree, a dependency of osmnx, cannot find spatialindex.
First, make sure that spatialindex is installed:
brew install spatialindex
The next problem is that rtree only checks in very specific locations for spatialindex but brew installs to /opt/homebrew/Cellar.
You set the ENV variable and check if that's the issue with
export SPATIALINDEX_C_LIBRARY='/opt/homebrew/Cellar/spatialindex/1.9.3/lib'
python -c 'import geopandas'
and it should work.
However, depending on your spatialindex and brew version, this path might change.
The problem has been solved, and I want to share in case anyone later could try if encountering the same problem.
After I installed the latest version for rtree, which you can see below, it still gave me back the same problem
conda install -c ioos rtree=0.9.7
I had to install brew package for my Mac.
https://brew.sh
Then I ran these 2 lines of code that my friend Philippe found from another page
Installing Rtree from libspacialindex to use .clip() in geopandas
https://github.com/gboeing/osmnx/issues/3
brew install spatialindex
pip install rtree
The problem has been solved completely.
This isn't an OSMnx issue - it's an rtree issue. You might want to open an issue directly with the rtree GitHub repo. That said, you're on OS X so you may want to try to install with rtree
conda install -c ioos rtree=0.8.2
Some of my students that have macs struggled to install rtree with pip, but succeeded with that conda command if you're on windows, you can follow these instructions to install geopandas and rtree.
reference

Import Seaborn Error - Numpy_MKL (Python Script)

I coded in jupyter-notebook, fetching data from mysqlserver and then downloaded it as a python script because I want to implement it in my website using cronjob. So when I run the Python script, I'm getting this error:
import seaborn as sns
File "C:\Users\Debadri\AppData\Local\Programs\Python\Python36\lib\site-packages\seaborn\__init__.py", line 6, in <module>
from .rcmod import *
File "C:\Users\Debadri\AppData\Local\Programs\Python\Python36\lib\site-packages\seaborn\rcmod.py", line 5, in <module>
from . import palettes, _orig_rc_params
File "C:\Users\Debadri\AppData\Local\Programs\Python\Python36\lib\site-packages\seaborn\palettes.py", line 12, in <module>
from .utils import desaturate, set_hls_values, get_color_cycle
File "C:\Users\Debadri\AppData\Local\Programs\Python\Python36\lib\site-packages\seaborn\utils.py", line 7, in <module>
from scipy import stats
File "C:\Users\Debadri\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\__init__.py", line 61, in <module>
from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
ImportError: cannot import name 'NUMPY_MKL'
I tried to install numpy+mkl .whl file from this link: Numpy+MKL, this (numpy‑1.15.1+mkl‑cp37‑cp37m‑win_amd64.whl) package, but it showed, not supported when I tried to install it.
The following solution worked out:
Solution:
If you are using windows make sure you install numpy+mkl instead of just numpy.
If you have already installed scipy and numpy, uninstall then using "pip uninstall scipy" and "pip uninstall numpy"
Now download scipy from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy (appropriate version for your python and system)
and install using "pip install scipy‑1.1.0‑cp36‑cp36m‑win_amd64.whl" (Please install from the list according to your system config)
Your numpy and Scipy both should work now.
These binaries by Christoph Gohlke makes it very easy to install python packages on windows. But make sure you download all the dependent packages from there.
Reference: 4th answer of this question ImportError: cannot import name NUMPY_MKL

I am getting an error when I load Pandas and Numpy in

I am getting below error when execute below:
import numpy as np
The full stack trace:
File "C:\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 14, in <module>
from . import multiarray
ImportError: DLL load failed: The specified module could not be found.
Process finished with exit code 1
This looks like some of the dependencies are missing for the package numpy. The DLL load failed error points towards either incorrectly installed and/or missing files for package numpy. You should just try installing numpy again through Anaconda CLI using the following command:
conda install numpy
This works most of the times, if your python environments are sorted correctly. Do make sure that the python installation you're using for Anaconda, is the same one as your coding environment. Conflicting versions can sometimes lead to corrupted packages.
You could also try the following command to update the Anaconda Environment just to make sure that the installations are up to date, and not conflicting with older versions..
conda update -y -all

Error importing sklearn in python [duplicate]

I'm trying to call a function from the cluster module, like so:
import sklearn
db = sklearn.cluster.DBSCAN()
and I get the following error:
AttributeError: 'module' object has no attribute 'cluster'
Tab-completing in IPython, I seem to have access to the base, clone, externals, re, setup_module, sys, and warning modules. Nothing else, though others (including cluster) are in the sklearn directory.
Following pbu's advice below and using
from sklearn import cluster
I get:
Traceback (most recent call last):
File "test.py", line 2, in <module>
from sklearn import cluster
File "C:\Python34\lib\site-packages\sklearn\cluster\__init__.py", line 6, in <module>
from .spectral import spectral_clustering, SpectralClustering
File "C:\Python34\lib\site-packages\sklearn\cluster\spectral.py", line 13, in <module>
from ..utils import check_random_state, as_float_array
File "C:\Python34\lib\site-packages\sklearn\utils\__init__.py", line 16, in <module>
from .class_weight import compute_class_weight, compute_sample_weight
File "C:\Python34\lib\site-packages\sklearn\utils\class_weight.py", line 7, in <module>
from ..utils.fixes import in1d
File "C:\Python34\lib\site-packages\sklearn\utils\fixes.py", line 318, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\__init__.py", line 109, in <module>
from .isolve import *
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
from .iterative import *
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 7, in <module>
from . import _iterative
ImportError: DLL load failed: The specified module could not be found.
I'm using Python 3.4 on Windows, scikit-learn 0.16.1.
You probably don't use Numpy+MKL, but only Numpy.
I had the same problem and reinstalling Numpy with MKL
pip install --upgrade --force-reinstall "numpy‑1.16.3+mkl‑cp37‑cp37m‑win32.whl"
fixed it.
Note: update the file to the latest version, possibly 64bit - see the list of available Windows binaries
Problem was with scipy/numpy install. I'd been using the (normally excellent!) unofficial installers from http://www.lfd.uci.edu/~gohlke/pythonlibs/. Uninstall/re-install from there made no difference, but installing with the official installers (linked from http://www.scipy.org/install.html) did the trick.
I am using anaconda got the same error as the OP, when loading Orange, or PlotNine.
I can't recall when this start to happen.
Tracing the dependency of Anaconda3\Lib\site-packages\scipy\special\_ufuncs.cp36-win32.pyd, libifcoremd.dll and libmmd.dll are missing in DependencyWalk. Searching them in anaconda root directry, they are located in both ICC_RT and one version of MKL package.
Adding Anaconda3\pkgs\mkl-2017.0.3-0\Library\bin to PATH, seems to fix SciPy and NumPy related DLL load failure, the above package starts to work again.
I still don't know how to fix this properly. Apparently the downside is that the MKL package could be updated and versions may change so does the path. In this aspect Its equally inconvenient as adding a non-managed package.
Reinstalling ICC_RT fixed the issue for me, libmmd.dll and the related dlls are automatically copied into anaconda3/library/bin afterwards, which is automatically added into PATH by activate command. All previous numpy/scipy related cant load DLL errors are gone now.
From the error log, it shows that scipy module is the most recent module fails to import
File "C:\Python34\lib\site-packages\sklearn\utils\fixes.py", line 318, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\__init__.py", line 109, in <module>
from .isolve import *
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
from .iterative import *
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 7, in <module>
from . import _iterative
ImportError: DLL load failed: The specified module could not be found.
I have the same error that show the same log, the problem'd gone when I uninstall/install scipy:
pip uninstall scipy
pip install scipy
Place this line on top of the python file
from sklearn import cluster
That should do it :))
For me what fixed it were these commands:
pip uninstall sklearn
pip uninstall scikit-learn
pip uninstall scipy
pip install scipy
pip install scikit-learnhere
I had the same issue and solved it by installing/updating the mkl package:
conda install mkl
or
pip install mkl
Just for full information, this also downgraded the following packages:
The following packages will be UPDATED:
mkl: 2017.0.4-h6d528fc_0 defaults --> 2018.0.3-1 defaults
The following packages will be DOWNGRADED:
numpy: 1.11.3-py34_0 defaults --> 1.10.1-py34_0 defaults
pandas: 0.19.2-np111py34_1 defaults --> 0.18.1-np110py34_0 defaults
scikit-learn: 0.18.1-np111py34_1 defaults --> 0.17-np110py34_1 defaults
scipy: 0.19.1-np111py34_0 defaults --> 0.16.0-np110py34_0 defaults
I struggled trying to figure this one out; tried to download and install the (unofficial) Numpy+MKL library from the website (risky/tedious?).
Ultimately found success by:
Login to command prompt using admin rights; how to here: https://superuser.com/questions/968214/open-cmd-as-admin-with-windowsr-shortcut
Uninstall existing/tangled version of Scipy & Numpy
pip uninstall scipy
pip uninstall numpy
Fresh install Scipy & Numpy
pip install scipy
pip install numpy
Run Jupyter notebook; it worked for me.
The message ImportError: DLL load failed: The specified module could not be found
informs that there is failure to identify and source the required DLL(s) to use the scikit-learn library; a fresh install of scipy/numpy probably enables a better routing of DLL connections called from Jupyter notebook code(s).
download microsoft visual c++ distribution
link : https://www.microsoft.com/en-in/download/details.aspx?id=53840
vc_redist.x64.exe
install and run this .exe file in your computer.. the DLL import module error will not appear after this
now it will work fine enjoy :)

Install PyQt4 via conda for caffe model

When I try to run the SEC caffe model on from here: https://github.com/kolesman/SEC
I geht the error: ImportError: No module named PyQt4
python demo.py --model SEC.caffemodel --image /data/out/dataset/center/1475186965759787059.jpg --smooth --output result.png
Traceback (most recent call last):
File "demo.py", line 2, in <module>
import pylab
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/pylab.py", line 274, in <module>
from matplotlib.pyplot import *
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.py", line 16, in <module>
from .backend_qt5 import QtCore
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 31, in <module>
from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, __version__
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/backends/qt_compat.py", line 137, in <module>
from PyQt4 import QtCore, QtGui
ImportError: No module named PyQt4
In this stackoverflow thread they just mention that you can run
conda install pyqt
which results in the following output:
conda install pyqt
Fetching package metadata .......
Solving package specifications: ..........
# All requested packages already installed.
# packages in environment at /home/ec2-user/anaconda2:
#
pyqt 5.6.0 py27_0
Which indicates that I have version 5.6 and not version 4. But I could not find any solution how to downgrade to pyqt4.
so you can Uninstall pyqt5 and download PyQt4 and installed manually
The second option is to modify the code and replace PyQt4 by pyqt5 just pay attention to one thing that the classes in pyqt5 are the same but the irritation is bit different so you may get that specific model doesn't exist in this case check on manual of pyqt5 and fix it
I hope my answer is clear
It looks like the latest version of anaconda forces install of pyqt5.6 over any pyqt build, which will be fatal for your applications. In a terminal, Try:
conda install --channel https://conda.anaconda.org/conda-forge pyqt
conda install -c anaconda pyqt=4.11.4
It will prompt to downgrade conda client. After that, it should be good.

Resources