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
Related
I have been using Jupyter for some time now and it has worked just fine. I have Jupyter and Python installed via Homebrew. I am running on MacOS.
Yesterday, I ran the command brew upgrade and now my Jupyter notebook is unable to find any of the installed python packages. I will use Numpy as the example.
When inside of a Jupyter notebook, I try to do
import numpy
I get the message:
ModuleNotFoundError: No module named 'numpy'
If, however, I launch python in a terminal window, then I can import Numpy without issue.
I first checked that the package was installed correctly by re-issuing the install command
brew install numpy
which outputs:
Warning: numpy 1.18.4 is already installed and up-to-date
To reinstall 1.18.4, run `brew reinstall numpy`
I also ran
pip install numpy
and got:
Requirement already satisfied: numpy in /usr/local/lib/python3.7/site-packages (1.18.4)
Now, this is where I got confused because I expected the path to point to something like /usr/local/Cellar/, so I checked the path inside of the Jupyter notebook:
import sys
sys.path
which outputs:
['/Users/kseuro/Dropbox/Dev/',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python38.zip',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/lib-dynload',
'/usr/local/opt/python#3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages/IPython/extensions',
'/Users/kseuro/.ipython']
Ok, so Homebrew wants Jupyter to use Python3.8? So I tried brew switch python 3.8 and got:
Error: python does not have a version "3.8" in the Cellar.
python's installed versions: 3.7.7
I feel like I'm out of my depth now and need help figuring out what to do next. I don't want to start by just changing paths around.
Suggestions? Thanks so much.
I figured out what to do — posting the solution for my future self and others who may stumble upon this.
Since Jupyerlab is in its own Cellar, the Python packages need to end up in the
/usr/local/Cellar/jupyterlab/x.y.z/libexec/lib/python3.x/site-packages
directory, where x, y, z are integers, so that the Jupyter kernel can find them.
You can do this by calling:
import sys
!{sys.executable} -m pip install 'package-name'
inside of the Jupyer notebook.
All is well, again.
I am new to jupyter notebooks and virtualenvironment. I think that I am incurring in a really trivial problem.
I am trying to import matplotlib in a Jupyter notebook and the import works fine. However, it uses the wrong version of the library (installed also systemwide) and I don't know how to force it to use the one in the virtualenvironment.
In my virtualenvironment I want to use a most recent version of matplotlib and therefore I did
pip install --upgrade matplotlib in my virtualenvironment. The upgrade worked fine.
Now if I do pip show matplotlib in my virtualenvironment I get:
Name: matplotlib
Version: 2.2.5
...
Instead, if I do the same command in my home, I get:
Name: matplotlib
Version: 1.5.1
However, if in my jupyter notebook I do
import matplotlib
print ("matplotlib version:",matplotlib.__version__)
I get:
('matplotlib version:', '1.5.1')
Could you please help me understanding what I do wrong?
I found a solution to my problem. First of all, I read this long post that I suggest to everyone using conda or pip.
Then I understood that the shell environment is determined when the Jupyter notebook is launched, while the Python executable is determined by the kernel, and the two do not necessarily match.
I understood this by putting at the beginning of my jupyter notebook the following:
paths = !type -a python
for path in set(paths):
path = path.split()[-1]
print(path)
!{path} -c "import sys; print(sys.path)"
print()
!type python
import sys
sys.executable
!pip show matplotlib
It showed me that I was still using an older version of the matplotlib library.
Therefore I added
!{sys.executable} -m pip install --upgrade matplotlib
Restarted my jupyter kernel and this solved my problem.
I hope this solution will help someone else in the same situation.
I'm trying to display data using a pie chart in python, so i tried to install matplotlib using pip. After doing that, I tried importing matplotlib but I get an error: ModuleNotFoundError: No module named 'matplotlib'.
In the Command Prompt I typed 'pip install matplotlib' and everything appeared to be successful. This is the last line:
Successfully installed backports.functools-lru-cache-1.5 cycler-0.10.0 kiwisolver-1.0.1 matplotlib-2.2.4 numpy-1.16.2 pyparsing-2.3.1 python-dateutil-2.8.0 pytz-2018.9 six-1.12.0
I've also tried 'python -m pip install -U matplotlib', but I still get a ModuleNotFoundError.
I've tried running the input statement in both python 3 and 2, neither worked.
I've looked at various different discussions on this, and none of them seemed to help me. How can I fix this?
There are various python installed in your OS. If you install matplotlib for somewhere the python that you are using does not search, you get importing errors. You should figure out which python you want to use and where the packages it searches.
check your python path. the matplotlib should be installed in the same path with your python environment.
I guess you use an IDE to run the python. some IDE have their own python environment.
if not solved. plz introduce some details about your system、how installed etc.
It checks the lib folder where my seaborn stuff is, but still error._.
Hi,
I have looked at other posts, but most seemed to be dealing with Jupyter notebooks, which I'm not. I was wondering how to get to use Seaborn in the basic Python IDE or in PyCharm. I read about filepath collisions stuff, but not too clear on that front.
I'm using Python 3.6 right now.
Thanks for any help!
When dealing with version ambiguity, remember that pip is a python module. Once you're confident that python is the python installation that your IDE is running, run
python --version
python -m pip install seaborn
>pip3 may be pointing to an old or different python installation.
import pip
pip.main(['install','seaborn'])
From: https://stackoverflow.com/a/49391839
If you're doing in jupyter notebook Try doing this:
!conda install -c anaconda seaborn -y
Try running it in the terminal, it will work. But while running the command your pwd should be in the virtual environment in activated form
$ sudo apt-get install -y python3-seaborn
Try running this in a command line 'pip install seaborn'
https://seaborn.pydata.org/installing.html#installing
In PyCharm IDE, we can import the downloaded libraries, and that's what I did. Still, I have no clue on how to resolve this issue on Python IDE, but as of now, it's working on PyCharm for me.
Conda install seaborn
worked in my case.
If you are using jupyter notebook following command will solve the issue
!pip install seaborn
Jupyter Code-Cell:
%%bash
pip install seaborn
Since you are using python 3, try to open with idle3 from terminal
Tried importing seaborn in Pycharm with the proper configuration thing, and it works. I still don't know why the regular Python IDE doesn't work even though one of the sys.path folder it checks contains the seaborn folder, but oh well.
Thanks for all the replies!
Maybe you should try “python —version “to check if you’re using the right version of python in cmd. Sometimes it happens that there are multiple versions installed and it sometimes picks the wrong one.
Also it can happens that python hasn’t the rights to use the module. Then you should create your file and run it with “python [path of file]”
Just found a new method to install all important libraries.
Open command prompt:
Pip install pyforest
All the most important libraries got installed.
My fix (Same import error but on Jupyter Notebook). The import sequence:
import numpy as np
import seaborn as sns
%matplotlib inline
import matplotlib.pyplot as plt
Importing Matplotlib before seaborn can lead to an import error (I have no idea why).
The Seaborn official document also shows this:
https://seaborn.pydata.org/installing.html
If you're using Jupyter notebook try to run this_ _
** pip install seaborn --user**
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