Basemap with Python 3.5 Anaconda on Windows
Asked Answered
L

6

28

I use Python 3.5 with latest version of Anaconda on Windows (64 bit). I wanted to install Basemap using conda install basemap. Apparently there is a conflict between Python 3 and basemap. After some googling indeed I found that basemap is not supported on Python 3 for Windows users (ex: https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/TjAwi3ilQaU).

For obvious reasons I do not want to downgrade to Python 2. What would then be the simplest alternative solution?

  • Is there an alternative package similar to basemap for ploting maps, etc.?
  • Should I use a second environment which uses Python 2 and basemap? I have never done that but it seems possible (http://conda.pydata.org/docs/py2or3.html). Is it "safe"? Should I install again all the other packages (matplotlib, numpy, etc.) on the second environment?

Thanks in advance for the help and advice.

Lilliamlillian answered 1/3, 2016 at 7:16 Comment(0)
T
21

I have solved this several times (last time just now) by downloading it from http://www.lfd.uci.edu/~gohlke/pythonlibs and follow the instructions to install. From the anaconda command prompt

pip install full_path_to_package

For example, if you downloaded basemap-1.1.0-cp36-cp36m-win_amd64.whl, you would run

pip install C:\path\to\file\basemap-1.1.0-cp36-cp36m-win_amd64.whl

Note that the python version of the .whl file must match your python version. For example, ...-cp36-.... indicates Python 3.6. You can find your python version by running the command python --version.

Tours answered 16/5, 2016 at 17:52 Comment(3)
For clarity, I mean downloading basemap and installing it on top of the already installed anaconda distributionTours
After doing this, how would you go about importing the basemap package? I tried doing as one would do using python 2.7: from mpl_toolkits.basemap import Basemap but I just get "No module named mpl_toolkits.basemap"Antalkali
I import it like that and it should work. If you have several Python installations maybe pip installed the 2.7 version of basemap?Tours
F
33

Referring to the answer of Solly, I have Windows 10, python 3.5.3, Anaconda 64bit, in the Anaconda prompt I entered:

conda install -c conda-forge basemap=1.0.8.dev0
conda install -c conda-forge basemap-data-hires

then the code, taken from Python for Data Science for Dummies, page 193 (Plotting geographical data worked just fine. I wanted to add just a comment to the Solly's answer, but I don't have enough credits to do so. The code is:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

austin = (-97.75, 30.25)
hawaii = (-157.8, 21.3)
washington = (-77.01, 38.90)
chicago = (-87.68, 41.83)
losangeles = (-118.25, 34.05)

m = Basemap(projection = 'merc', llcrnrlat=10, urcrnrlat=50,
        llcrnrlon=-160, urcrnrlon=-60)

m.drawcoastlines()
m.fillcontinents (color='lightgray', lake_color='lightblue')
m.drawparallels(np.arange(-90.,91.,30.))
m.drawmeridians(np.arange(-180.,181.,60.))
m.drawmapboundary(fill_color='aqua')

m.drawcounties()

x, y = m(*zip(*[hawaii, austin, washington, chicago, losangeles]))
m.plot(x,y, marker ='o', markersize=6, markerfacecolor='red', linewidth=0)

plt.title('Mercator Projection')
plt.show()
Fuddyduddy answered 3/3, 2017 at 20:12 Comment(5)
great ! Works for meAnhydride
I've tried your suggestion but the installer indicated that it needs to downgrade 16 packages. Did you accept the suggestion? Using conda 4.5.4.Tolliver
@Tolliver I've downgraded a lot of packages, but still not working. Any hint on this?Heligoland
@kalinfirst I would suggest you update your answer to exclude the specific version which requires other packages to be downgraded. I've found installing the latest version with install -c conda-forge basemap works well.Ogawa
This command is taking very long time:conda install -c conda-forge basemap=1.0.8.dev0. How long did it take in your case?Yoke
T
21

I have solved this several times (last time just now) by downloading it from http://www.lfd.uci.edu/~gohlke/pythonlibs and follow the instructions to install. From the anaconda command prompt

pip install full_path_to_package

For example, if you downloaded basemap-1.1.0-cp36-cp36m-win_amd64.whl, you would run

pip install C:\path\to\file\basemap-1.1.0-cp36-cp36m-win_amd64.whl

Note that the python version of the .whl file must match your python version. For example, ...-cp36-.... indicates Python 3.6. You can find your python version by running the command python --version.

Tours answered 16/5, 2016 at 17:52 Comment(3)
For clarity, I mean downloading basemap and installing it on top of the already installed anaconda distributionTours
After doing this, how would you go about importing the basemap package? I tried doing as one would do using python 2.7: from mpl_toolkits.basemap import Basemap but I just get "No module named mpl_toolkits.basemap"Antalkali
I import it like that and it should work. If you have several Python installations maybe pip installed the 2.7 version of basemap?Tours
E
5

I was running in the same problem (Python 3.5 and Anaconda) and eventually downloaded Basemap 1.0.8dev0 from here and installed it using conda (as described by the link).

Emmyemmye answered 26/1, 2017 at 11:55 Comment(1)
This worked for me today (conda install -c conda-forge basemap), it installed version 1.1.0. Thanks!Drivein
C
2

Cartopy is an alternative to Basemap, and it is being actively developed.

There is a nice gallery here: http://scitools.org.uk/cartopy/docs/latest/gallery.html

Cavalla answered 19/2, 2018 at 1:8 Comment(0)
J
1

The below information is for Mac OS:

  1. Downloaded from here!
  2. Run conda install -c conda-forge basemap-1.2.0-py37h9622e30_3.tar.bz2
  3. enter image description here
  4. Done
Jam answered 3/6, 2019 at 0:57 Comment(0)
A
0

Truth be told I had the same problem and tried to fix it for waaay to long and even tried a python 2 environment with no luck.

Personally just using a python 2 install was way easier and less time consuming. Sorry for the non answer.

Assimilative answered 2/5, 2016 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.