简体   繁体   English

Python如何安装osmnx?

[英]How to install osmnx in Python?

I am trying to use osm library in Python. I found a recommended package called osmnx.我正在尝试使用 Python 中的 osm 库。我发现了一个名为 osmnx 的推荐 package。 I installed it via the command:我是通过命令安装的:

python -m pip install osmnx

when I type:当我输入:

py -m pip freeze

I receive:我收到:

click==7.1.2
cycler==0.10.0
Flask==1.1.2
Flask-Ext==0.1
Flask-SQLAlchemy==2.4.4
itsdangerous==1.1.0
Jinja2==2.11.3
kiwisolver==1.3.1
MarkupSafe==1.1.1
matplotlib==3.3.4
numpy==1.20.1
osm==1.4
overpy==0.4
Pillow==8.1.0
pyparsing==2.4.7
python-dateutil==2.8.1
six==1.15.0
SQLAlchemy==1.3.23
Werkzeug==1.0.1

but osmnx is never there.但 osmnx 永远不会存在。 Consequently when I run the code posted below, I receive the following error:因此,当我运行下面发布的代码时,我收到以下错误:

Traceback (most recent call last):
  File "m:\python lessons\flask apps\osm\osmnx\test.py", line 1, in <module>
    import osmnx as ox
ModuleNotFoundError: No module named 'osmnx'

Please let me know how to install osmnx in Python. code :请告诉我如何在 Python 中安装 osmnx。代码

import osmnx as ox
import matplotlib.pyplot as plt

place_name = "Kamppi, Helsinki, Finland"
graph = ox.graph_from_place(place_name)

Just to add to this, if you have installed osmnx using the above instructions, you will need to activate the environment each time you want to use it.补充一点,如果您已经使用上述说明安装了osmnx ,则每次要使用它时都需要激活环境。 To do this in anaconda prompt, type the following:要在 anaconda 提示符下执行此操作,请键入以下内容:

conda activate ox

This takes you from the base environment to the ox environment.这会将您从base环境带到ox环境。 You will then be able to execute the above code in anaconda prompt by typing然后,您将能够通过键入在 anaconda 提示符中执行上述代码

python myprogram.py

where myprogram.py is the name of your python program.其中myprogram.py是您的 python 程序的名称。

Older versions of osmnx installed into the base environment.旧版本的osmnx安装到基础环境中。 However, this is not the case anymore it seems.然而,这似乎不再是这种情况了。 I think there were some issues with package clashes or something.我认为 package 冲突或其他问题存在一些问题。

Try install with conda:尝试使用 conda 安装:

conda config --prepend channels conda-forge
conda create -n ox --strict-channel-priority osmnx

https://osmnx.readthedocs.io/en/stable/ https://osmnx.readthedocs.io/en/stable/

If you want to install osnmx without conda try these steps:如果您想在没有 conda 的情况下安装 osnmx,请尝试以下步骤:

  1. From Github repo get the latest requirements.txt fileGithub repo获取最新的 requirements.txt 文件

  2. Install all requirements with pip command:使用pip命令安装所有要求:
    python3 -m pip install -r requirements.txt

  3. Install osnmx with pip while all modules are satisfied:在满足所有模块的情况下,使用pip安装 osnmx:
    python3 -m pip install osnmx

You can find the answer in Installing OSMnx on Windows by Joshua Kobina Obeng article.您可以在Joshua Kobina Obeng 的文章在 Windows 上安装 OSMnx中找到答案。

I will inlude the stesps as it is easy for you to see.我将包括这些步骤,因为它很容易让你看到。

  1. Open Anaconda command prompt(base) and type the following commands.打开 Anaconda 命令提示符(基本)并键入以下命令。

 conda config --prepend channels conda-forge conda create -n ox --strict-channel-priority osmnx

  1. Then activate the enironment according to the instructions shown on the command prompt.然后根据命令提示符上显示的说明激活环境。

  2. Open Anaconda Navigator.打开 Anaconda 导航器。

  3. In the "applications on" drop down, select "ox".在“应用程序”下拉列表中,select“牛”。

  4. Instll Jupyter notebook by click on th install button given under "Jupyter Notebook".通过单击“Jupyter Notebook”下给出的安装按钮来安装 Jupyter notebook。

  5. After instllation complleted, launch Jupyter Notebook.安装完成后,启动 Jupyter Notebook。

  6. Open notebook and import osmnx.打开 notebook 并导入 osmnx。

I'm using OSMX inside of Blender which comes with its own Python distribution and Blender doesn't work well with Conda's python installs (Blender has its own python requirements).我在 Blender 内部使用 OSMX,它带有自己的 Python 发行版,Blender 不能很好地与 Conda 的 python 安装一起使用(Blender 有自己的 python 要求)。 I got OSMX installed via Conda, but then Blender starting giving me all sorts of errors when using the Conda environment even following the suggestions on how to get Conda to work with Blender.我通过 Conda 安装了 OSMX,但随后 Blender 在使用 Conda 环境时开始给我各种错误,甚至按照有关如何让 Conda 与 Blender 一起工作的建议。

What I did is install all dependencies via pip, mindful of which version is the prereq as what is already installed may not be the version OSMX needs.我所做的是通过 pip 安装所有依赖项,注意哪个版本是先决条件,因为已经安装的可能不是 OSMX 需要的版本。

Then I installed OSMX via pip using a local wheel download from https://pypi.org/project/osmnx/#files (installing direct only had an old version and gave installation errors).然后我使用从https://pypi.org/project/osmnx/#files下载的本地轮子通过 pip 安装 OSMX(直接安装只有旧版本并且出现安装错误)。

On Windows,在 Windows 上,

 .\python -m pip install osmnx-1.3.0-py3-none-any.whl

After installing the pre-reqs, the wheel installed with no errors.安装先决条件后,车轮安装没有错误。 If you have a dependency that isn't met - it will tell you and what specific version is needed.如果您有未满足的依赖项 - 它会告诉您以及需要什么特定版本。

In my case, while I had Shapely installed from another package, OSMX wanted 2.0 so I had to upgrade it using就我而言,虽然我从另一个 package 安装了 Shapely,但 OSMX 想要 2.0,所以我不得不使用

.\python -m pip install shapely --upgrade

Hope this helps,希望这可以帮助,

M

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM