在 Windows 上使用 Python 3.5 Anaconda 的底图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35716830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 16:51:52  来源:igfitidea点击:

Basemap with Python 3.5 Anaconda on Windows

pythonmatplotlibanacondamatplotlib-basemap

提问by Prikers

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).

我在 Windows(64 位)上使用 Python 3.5 和最新版本的 Anaconda。我想使用conda install basemap. 显然 Python 3 和底图之间存在冲突。经过一番谷歌搜索后,我发现 Windows 用户的 Python 3 不支持底图(例如: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?

出于显而易见的原因,我不想降级到 Python 2。那么最简单的替代解决方案是什么?

  • 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?
  • 是否有类似于用于绘制地图等的底图的替代包?
  • 我应该使用使用 Python 2 和底图的第二个环境吗?我从未这样做过,但似乎有可能(http://conda.pydata.org/docs/py2or3.html)。它“安全”吗?我是否应该在第二个环境中再次安装所有其他包(matplotlib、numpy 等)?

Thanks in advance for the help and advice.

在此先感谢您的帮助和建议。

采纳答案by Paco Lopez Dekker

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

我已经通过从http://www.lfd.uci.edu/~gohlke/pythonlibs下载 并按照说明进行安装解决了这个问题好几次(上次刚刚) 。从 anaconda 命令提示符

pip install full_path_to_package

pip install full_path_to_package

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

例如,如果您下载了 basemap-1.1.0-cp36-cp36m-win_amd64.whl,您将运行

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

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.

请注意,.whl 文件的 python 版本必须与您的 python 版本匹配。例如,...-cp36-....表示 Python 3.6。您可以通过运行命令找到您的 python 版本python --version

回答by kalinfirst

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

参考Solly的回答,我有Windows 10,python 3.5.3,Anaconda 64bit,在我输入的Anaconda提示中:

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:

然后是代码,取自Python for Data Science for Dummies,第 193 页(绘制地理数据工作得很好。我只想在 Solly 的答案中添加一条评论,但我没有足够的学分来这样做。代码是:

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()

回答by Solly

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

我遇到了同样的问题(Python 3.5 和 Anaconda),最终从这里下载了 Basemap 1.0.8dev0并使用conda安装它(如链接所述)。

回答by onewhaleid

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

Cartopy 是 Basemap 的替代品,并且正在积极开发中。

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

这里有一个不错的画廊:http: //scitools.org.uk/cartopy/docs/latest/gallery.html

回答by Madhu Mohan Kommu

The below information is for Mac OS:

以下信息适用于 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
  1. 这里下载!
  2. conda install -c conda-forge basemap-1.2.0-py37h9622e30_3.tar.bz2
  3. 在此处输入图片说明
  4. 完毕

回答by Mat Moon

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.

说实话,我遇到了同样的问题,并试图修复它很长时间,甚至尝试了一个没有运气的 python 2 环境。

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

就个人而言,仅使用 python 2 安装更容易且耗时更少。抱歉没有回答。