I have error on Jupyter Notebook with macOS as below
ImportError Traceback (most recent call last)
in
----> 1 from mpl_toolkits.basemap import Basemap
seems have problem on installing Basemap. So I tried,
(1) !conda install -c anaconda basemap -y
: installed successfully according to message. And closed all browser and restarted but still have ImportError.
(2) Installed anaconda and tried to install basemap from "Environments" tab by select basemap from "Not Installed" list, check and apply.
But I have another error as below
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
basemap -> python[version='>=3.5,<3.6.0a0|>=3.9,<3.10.0a0']
Your python: python=3.8
If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
But my python version is 3.9.5
How can I install Basemap to avoid ImportError?
Resolved by running follow line on Jupyter
conda install -c conda-forge basemap matplotlib==3.1 -y
Related
I'm very sorry, this question has popped up quite a few times, yet I'm still struggling. I'm using Windows 11. I've installed Anaconda Navigator, created a new environment, and installed the required module (MDAnalysis, via Anaconda Navigator). I launched Juypter Notebook from the play icon of the desired environment inside Anaconda Navigator.
Then with the code:
import sys
print(sys.executable)
#!pip install mdanalysis
import mdanalysis as md
Which returns the error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In [1], line 6
1 import sys
2 print(sys.executable)
3
4 #!pip install mdanalysis
----> 6 import mdanalysis as md
ModuleNotFoundError: No module named 'mdanalysis'
As you can see, from printing out the sys.executable and checking whether mdanalysis is installed (it is; hence I commented the pip line out), I've tried attempts mentioned elsewhere in StackOverflow with no success.
The executable is:
C:\Users\yewro\anaconda3\envs\MinesMD\python.exe
Where MinesMD is the conda environment, I (a) installed MDAnalysis from Anaconda Navigator, and (b) I launched Jupyter Notebook.
I would appreciate any help/suggestions.
EDIT
I've just tried installing MDAnalysis via conda inside Jupyter Notebook. I shouldn't need to do this as I did it within Anaconda Navigator (and with the right environment), but in for a penny, in for a pound. This is the output (matching python executable location and environment):
C:\Users\yewro\anaconda3\envs\MinesMD\python.exe
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done
# All requested packages already installed.
Retrieving notices: ...working... done
Try installing the missing package directly from the Jupyter Notebook (with pip or conda) as explained here:
https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/
EDIT:
We figured out that the package was correctly installed and accessible to the Jupyter Notebook environment. (See comments for this answer)
The problem is that the modules import should be different: import MDAnalysis instead of import mdanalysis.
I installed matplotlib on Anaconda Prompt with conda install -c conda-forge matplotlib.
However, when I run import matplotlib.pyplot as plt on Spyder 4.1.5 (with Python 3.7), I got an error message:
ModuleNotFoundError: No module named 'matplotlib.pyplot'
Before getting this error message, I installed matplotlib_scalebar with conda install -c conda-forge matplotlib-scalebar. I had no issue importing matplotlib.pyplot before this, and I suspect that installing this might have caused the problem.
Under C:\ProgramData\Anaconda3\Lib\site-packages, I have folders with the following names:
matplotlib
matplotlib-3.0.2.dist-info
matplotlib-3.3.2.dist-info
I'm not sure if having different folders (3.0.2 and 3.3.2) is an issue here.
How can I fix this No module issue?
I'm using Anaconda 5.0.1 with Python 2.7.14. When I open a jupyter notebook and try to run the following:
%matplotlib inline
I get the following error:
ImportError Traceback (most recent call last)
C:\toolkits.win\anaconda2\envs\dlc\lib\site-packages\matplotlib\font_manager.py in <module>()
56
57 import matplotlib
---> 58 from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir
59 from matplotlib.compat import subprocess
60 from matplotlib.fontconfig_pattern import (
ImportError: DLL load failed: The specified procedure could not be found.
When I try to drill into the error, the problem is with ft2font:
In [1]: from matplotlib import ft2font
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-a32e7826851f> in <module>()
----> 1 from matplotlib import ft2font
ImportError: DLL load failed: The specified procedure could not be found.
I double-checked and made sure freetype is installed:
(dlc) C:\Users\Larry>conda install freetype
Fetching package metadata .............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\toolkits.win\anaconda2\envs\dlc:
#
freetype 2.8 vc9hf582001_0 [vc9]
Any ideas?
conda install freetype --force-reinstall
Improving a bit on the above suggestion:
pip install matplotlib --force-reinstall
def _check_versions():
# Quickfix to ensure Microsoft Visual C++ redistributable
# DLLs are loaded before importing kiwisolver
from . import ft2font
Try install Microsoft Visual C++ redistributable
My solution: unstall matplotlib, and re-install it with pip.
I have the same issue and on my machine the problem was that Java (openJDK) was mentioned in the PATH-variable prior to Python (Anaconda in my case).
If you open a cmd and type
echo %PATH%
you can check if that is the case on your machine as well. If it states ...\Java\openJDK<version>\bin is before the Anaconda directories, the wrong freetype.dll library is getting found and the error occurs.
All you have to do is to change PATH to state the anaconda directories before the Java directories. This may raise another set of issues with Java though...
I found that if conda doesn't activate when the terminal starts up properly, you get this error.
I found that by opening the terminal, typing a bunch of stuff and pressing enter a a lot to prevent conda from activating and then when I tried to run a matplotlib inclusive script it would give me this error, but when I let it start without interference, it would not give me this error (it would run fine, at least past this error).
Considering this, it may be useful to keep import matplotlib at the top of the file if possible, so you don't wait a while and then find out that matplotlib won't load.
I solved this problem by installing the last Microsoft Visual C++ redistributable 2019.
In my case :
python 3.8.7
matplotlib : 20.3.3
test.py
result in IDLE
Debugged into same issue. It seems another access-deny issue.
Solution: Re-install matplotlib in elevated mode.
Launch Anaconda Prompt as Administrator
Run conda install matplotlib
Finish installing any required packages.
I have recently started using Python 3.5 and Anaconda on my Windows pc. I am trying to plot a map. However, When I am in my Jupyter notebook and i type the command
import mpl_toolkits.basemap
I get an error message saying 'no module name' 'mpl_toolkits.basemap'
However, I have the module downloaded and in the same C:\Users\Geena file as my .matplotlib, .ipython, .jupyter files, etc.
Anyone know how I can fix this?
I've had this issue with anaconda on my windows 7.
I found the way to fix it with python 3.5:
You need to run with administrator rights "Anaconda Prompt" and in "Anaconda Prompt" run following command:
conda install -c conda-forge basemap-data-hires=1.0.8.dev0
, it will show new packages that you need to install and will ask you to install it - say 'Yes'.
After that new packages will be installed and the issue "import mpl_toolkits.basemap" will be fixed.
Thank you.
Currently, basemap is not compatible with python 3 for windows users. So, if you try conda install basemap and you have python 3 installed in windows, you'll see a message pointing out that a conflict was found with python 3.
I solved this by installing a python 2.7 environment. Try this:
http://conda.pydata.org/docs/py2or3.html
Then you just activate the python 2 environment. For example: activate py27 (py27 is the identifier of my python 2.7 environment).
After that, you can run conda install basemap with no conflict.
I'm using python 3.6.4 on Windows 7 Family Premium (32bit).
Because I was a bit frustrated by the message "no module named 'mpl_toolkits.basemap'", I searched for and tried a dozen of solutions without success : various versions, building from source, problems with VS version, nmake, ... You all know what I mean ;-)
I finally found a quite simple solution that works perfectly well for me :-) Here it is !
from here I downloaded basemap‑1.1.0‑cp36‑cp36m‑win32.whl
I changed the current dir to my download dir
I installed the wheel with python -m pip basemap‑1.1.0‑cp36‑cp36m‑win32.whl
I did the same for matplotlib‑2.2.3‑cp36‑cp36m‑win32.whl
You DO read the versions correctly : matplotlib 2.2.3 and basemap 1.1.0
Everything works fine for me and I finally can plot OSM POI's on a map of Belgium, without any 'trickery' at import :
import requests # to fetch OSM data
import json # to get the response
from mpl_toolkits.basemap import Basemap # ... Belgium is there !
import numpy as np # for arrays
import matplotlib.pyplot as plt # to build the populated map
Big big thanks to Christoph Gohlke (Danke Dir Christoph !) who did all the wonderful job !
When you have Anaconda, you don't download modules anywhere. In your command prompt, you type
conda install basemap
and it is installed with all its dependencies.
Anaconda requires an unusual install command for basemap 1.0.7.
https://anaconda.org/anaconda/basemap
To install this package with conda run:
conda install -c https://conda.anaconda.org/anaconda basemap
I just had this issue as well. All you need to do is update matplotlib by doing the following:
pip install --upgrade matplotlib
mpl_toolkits is part of matplotlib and just needs to be updated.
If you're using anaconda, the easiest thing to do is described here: in the conda prompt (as admin), type conda install -c anaconda basemap.
For people of the future : "Basemap is deprecated in favor of the Cartopy project."
https://matplotlib.org/basemap/users/intro.html#cartopy-new-management-and-eol-announcement
I have installed Anaconda (version 1.6.2) installed on my 64 bit machine. It comes with a great set of libraries, but I also need Basemap, part of matlibplot, but it is not included with the Anaconda install. I attempted to install Basemap and move the files in the Anacaonda\Lib\site-packages\mpl_toolkits directory since it is part of the mpl_toolkits library. However when I attempt to run a script, I keep getting the errors:
"No module named _geoslib"
"Cannot import pyproj"
I found the pyproj library. Do I need it? Where can I find geoslib? And how do I get Basemap to work?
What you nees is to change your path first, by:
$ export PATH=~/anaconda/bin:$PATH
and then,
$ conda install basemap
( I assumed you are in Linux)
source:http://docs.continuum.io/anaconda/faq.html
If your on Windows try installing Basemap from the Sourceforge executable, these should include GEOS and PROJ4 dependencies of Basemap.
I believe all that is needed is to update matplotlib, I just had this problem and doing this worked for me:
pip install --upgrade matplotlib