- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从官方网站上独立安装了 GRASS,
我使用 python 2.7 32b 和 windows 10。
我尝试使用 GRASS GIS 7.0.4 中的 python api。但我有导入错误。
一些导入工作我可以在 python ide 中导入,而一些导入不起作用,我无法使用。
首先我读了这篇文章grass python我试图采取 pygrass api
python 代码:
import os, sys
import subprocess as subp
gisbase = os.environ['GISBASE'] = "C:\Program Files (x86)\GRASS GIS 7.0.4"
gisdbase = os.path.join(os.environ['HOME'])
location = "test"
mapset = "PERMANENT"
sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "python","bin","extrabin","lib","driver","scripts"))
成功导入
import grass.script as grass
from grass.pygrass.modules.shortcuts import general as g
from grass.pygrass.modules import Module as run_command
from grass.pygrass.modules.shortcuts import general as g
from grass import script as g
from grass.script import setup as gsetup
from grass.pygrass.modules.shortcuts import imagery as i
from pygrass.modules import Module
没有成功导入
from pygrass.modules import Module
No module named pygrass.modules
2.
from grass.pygrass.gis import Mapset
错误信息:
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
from grass.pygrass.gis import Mapset
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\pygrass\gis\__init__.py", line 13, in <module>
import grass.lib.gis as libgis
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\lib\gis.py", line 23, in <module>
_libs["grass_gis.7.0.4"] = load_library("grass_gis.7.0.4")
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\lib\ctypes_loader.py", line 57, in load_library
raise ImportError,"%s not found." % libname
ImportError: grass_gis.7.0.4 not found.
3.
from grass.pygrass.vector import VectorTopo
错误信息 :
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
from grass.pygrass.vector import VectorTopo
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\pygrass\vector\__init__.py", line 3, in <module>
import grass.lib.gis as libgis
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\lib\gis.py", line 23, in <module>
_libs["grass_gis.7.0.4"] = load_library("grass_gis.7.0.4")
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\lib\ctypes_loader.py", line 57, in load_library
raise ImportError,"%s not found." % libname
ImportError: grass_gis.7.0.4 not found.
4.
from grass.pygrass.vector import Vector
错误信息 :
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
from grass.pygrass.vector import Vector
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\pygrass\vector\__init__.py", line 3, in <module>
import grass.lib.gis as libgis
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\lib\gis.py", line 23, in <module>
_libs["grass_gis.7.0.4"] = load_library("grass_gis.7.0.4")
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\lib\ctypes_loader.py", line 57, in load_library
raise ImportError,"%s not found." % libname
ImportError: grass_gis.7.0.4 not found.
5.
from grass.pygrass.raster import RasterRow
错误信息 :
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
from grass.pygrass.raster import RasterRow
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\pygrass\raster\__init__.py", line 14, in <module>
import grass.lib.gis as libgis
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\lib\gis.py", line 23, in <module>
_libs["grass_gis.7.0.4"] = load_library("grass_gis.7.0.4")
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\lib\ctypes_loader.py", line 57, in load_library
raise ImportError,"%s not found." % libname
ImportError: grass_gis.7.0.4 not found.
6.
from grass.pygrass.gis import Location
错误信息 :
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
from grass.pygrass.gis import Location
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\pygrass\gis\__init__.py", line 13, in <module>
import grass.lib.gis as libgis
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\lib\gis.py", line 23, in <module>
_libs["grass_gis.7.0.4"] = load_library("grass_gis.7.0.4")
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\lib\ctypes_loader.py", line 57, in load_library
raise ImportError,"%s not found." % libname
ImportError: grass_gis.7.0.4 not found.
7.
from grass.pygrass.gis.region import Region
错误信息:
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
from grass.pygrass.gis.region import Region
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\pygrass\gis\__init__.py", line 13, in <module>
import grass.lib.gis as libgis
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\lib\gis.py", line 23, in <module>
_libs["grass_gis.7.0.4"] = load_library("grass_gis.7.0.4")
File "C:\Program Files (x86)\GRASS GIS 7.0.4\etc\python\grass\lib\ctypes_loader.py", line 57, in load_library
raise ImportError,"%s not found." % libname
ImportError: grass_gis.7.0.4 not found.
8.
from grass.pygrass.modules import raster as r
错误信息:
ImportError: cannot import name raster
9.
from grass.pygrass.functions import coor2pixel
错误信息:
No module named functions
10.
import grass.scripts
错误信息:
No module named scripts
知道为什么我可以从 pygrass 导入一些导入,为什么我不能从 pygrass 导入一些其他导入?
最佳答案
import grass.scripts
是一个错字。您需要使用 import grass.script
因为这是模块的名称。
进口 from pygrass.modules import Module
原因 No module named pygrass.modules
因为没有这样的模块。该模块的名称是 grass.pygrass.modules
正如您在其他示例中使用它一样。
进口 from grass.pygrass.modules import raster as r
看来你想说from grass.pygrass.modules.shortcuts import raster as r
.您是从某些文档中使用的吗?from grass.pygrass.functions import coor2pixel
进口应该是from grass.pygrass.utils import coor2pixel
.看起来您确实使用了一些过时的(错误的?)文档。最新的文档在这里:
https://grass.osgeo.org/grass73/manuals/libpython/pygrass_index.htmlgrass73
当前表示开发版本。使用grass72
对于即将发布的 7.2 版本和 grass70
对于当前版本 7.0 (7.0.4)。
所有其他错误都说 ImportError: grass_gis.7.0.4 not found
与前几行(例如 ctypes_loader.py...load_library
)相结合,表明问题在于使用未找到的 C 类型加载 C 动态库。
您似乎正在尝试从 GRASS session 之外在 Python 中使用 GRASS GIS,即没有明确启动 GRASS GIS。首先请注意,只有在您真正需要它时才这样做是好的。您应该使用的默认解决方案是编写一个 Python 脚本,该脚本将在 GRASS session 中运行(即您启动 GRASS GIS,然后运行该脚本)。你可以从菜单 File > Run script
或从命令行。开发版本甚至包含一个简单的 Python 编辑器,它具有一些特定于 GRASS GIS 的特殊功能。编写在 GRASS session 中运行的脚本无需在脚本中设置环境,您只需专注于功能。它还将使其更容易在不同的计算机上使用,而无需更改脚本中的路径。最后,它允许您轻松使用自动生成的 GUI 之类的东西。如果您想在不使用 GRASS GIS GUI 的情况下自动/以编程方式启动脚本,您可以查看 grass
的内容。 ( grass7
, grass70
, ...) 命令帮助和选项设置 GRASS_BATCH_JOB
变量到你的脚本。开发版还有--exec
更通用的选项:
https://grass.osgeo.org/grass72/manuals/grass7.html
如果您确实需要自己设置 GRASS GIS 运行时环境,请确保您使用的是以下文档:
https://grass.osgeo.org/grass73/manuals/libpython/script.html#module-script.setup
但是,PyGRASS 依赖于通过 ctypes 使用并在导入期间加载的动态库。操作系统使用其设置和当前环境变量搜索库。对于动态库,它使用进程启动时的环境变量。所以稍后在脚本中更改它,例如 grass.script.setup.init()
确实,不会影响流程本身,而只会影响其子流程。因此,您需要为 Linux 执行以下命令:
export LD_LIBRARY_PATH=$(grass70 --config path)/lib
python a_python_script.py
PATH
变量(与可执行文件的路径混合),因此您可以使用
PATH
那里。你需要做这样的事情:
set PATH="%PATH%;C:\Program Files (x86)\GRASS GIS 7.0.4\lib"
PATH
MS Windows 注册表中的永久变量(例如,使用
xset
)。网上有很多关于这方面的资料(它对任何程序都一样)。
os.path.join
因为在 MS Windows 上处理文件路径有一些细节。有关详细信息,请参阅 Python 文档:
PATH
变量和其他包含路径的变量。通常(在命令行或 Python 中),请注意
PATH
中的空格、反斜杠、目录分隔符和分隔符。/
LD_LIBRARY_PATH
变量和环境变量的当前值。
关于python - 使用 GRASS GIS API 的 python 脚本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38062678/
我已经设置了 Azure API 管理服务,并在自定义域上配置了它。在 Azure 门户中 API 管理服务的配置部分下,我设置了以下内容: 因为这是一个客户端系统,我必须屏蔽细节,但以下是基础知识:
我是一名习惯 React Native 的新程序员。我最近开始学习 Fetch API 及其工作原理。我的问题是,我找不到人们使用 API key 在他们的获取语句中访问信息的示例(我很难清楚地表达有
这里有很多关于 API 是什么的东西,但是我找不到我需要的关于插件 API 和类库 API 之间的区别。反正我不明白。 在 Documenting APIs 一书中,我读到:插件 API 和类库 AP
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
我正在尝试找出设计以下场景的最佳方法。 假设我已经有了一个 REST API 实现,它将从不同的供应商那里获取书籍并将它们返回给我自己的客户端。 每个供应商都提供单独的 API 来向其消费者提供图书。
请有人向我解释如何使用 api key 以及它有什么用处。 我对此进行了很多搜索,但得到了不同且相互矛盾的答案。有人说 API key 是保密的,它从不作为通信的一部分发送,而其他人则将它发送给客户端
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 4年前关闭。 Improve this
谁能告诉我为什么 WSo2 API 管理器不进行身份验证?我已经设置了两个 WSo2 API Manager 1.8.0 实例并创建了一个 api。它作为原型(prototype) api 工作正常。
我在学习 DSL 的过程中遇到了 Fluent API。 我在流利的 API 上搜索了很多……我可以得出的基本结论是,流利的 API 使用方法链来使代码流利。 但我无法理解——在面向对象的语言中,我们
基本上,我感兴趣的是在多个区域设置 WSO2 API 管理器;例如亚洲、美国和欧洲。一些 API 将部署在每个区域的数据中心内,而其他 API 将仅部署在特定区域内。 理想情况下,我想要的是一个单一的
我正在构建自己的 API,供以下用户使用: 1) 安卓应用 2) 桌面应用 我的网址之一是:http://api.chatapp.info/order_api/files/getbeers.php我的
我需要向所有用户显示我的站点的分析,但使用 OAuth 它显示为登录用户配置的站点的分析。如何使用嵌入 API 实现仪表板但仅显示我的网站分析? 我能想到的最好的可能性是使用 API key 而不是客
我正在研究大公司如何管理其公共(public) API。我想到的是拥有成熟 API 的公司,例如 Google、Facebook、Twitter 和 Amazon。 这些公司向公众公开了许多不同的 A
在定义客户可访问的 API 时,以下是首选的行业惯例: a) 定义一组显式 API 方法,每个方法都有非常狭窄和特定的目的,例如: SetUserName SetUserAge Se
这在本地 deserver 和部署时都会发生。我成功地能够通过留言簿教程使用 API 资源管理器,但现在我已经创建了自己的项目并尝试访问我编写的第一个 API,它从未出现过。搜索栏旁边的黄色“正在加载
我正在尝试使用 http://ip-api.com/ api通过我的ip地址获取经度和纬度。当我访问 http://ip-api.com/json从我的浏览器或使用 curl,它以 json 格式返回
这里的典型示例是 Twitter 的 API。我从概念上理解 REST API 的工作原理,本质上它只是针对您的特定请求向他们的服务器查询,然后您会在其中收到响应(JSON、XML 等),很棒。 但是
我能想到的最好的标题,但要澄清的是,情况是这样的: 我正在开发一种类似短 url 的服务,该服务允许用户使用他们的 Twitter 帐户“登录”并发布内容。现在这项服务可以包含在 Tweetdeck
我正在设计用于管理评论和讨论线程的 API 方案。我想有一个点 /discussions/:discussionId 当您GET 时,它会返回一组评论和一些元数据。评论也许可以单独访问 /discus
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭去年。 Improve this quest
我是一名优秀的程序员,十分优秀!