首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确设置Windows上的PyQGIS环境?

如何正确设置Windows上的PyQGIS环境?
EN

Stack Overflow用户
提问于 2015-05-05 21:21:58
回答 1查看 3.1K关注 0票数 2

我遇到了一个特定错误的问题,从我所能看到的情况来看,这是相当常见的,但似乎找不到解决办法。

当我试图导入qgis模块时,会发生以下错误:

代码语言:javascript
复制
ImportError: No module named 'qgis'

到目前为止,这是我正在使用的指南,这是.cmd的设置,我假设它与此有关:

代码语言:javascript
复制
@echo off
SET OSGEO4W_ROOT=D:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass-6.4.3\etc\env.bat
@echo off
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-6.4.3\lib

set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python;
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\Python27\Lib\site-packages
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis
set PATH=C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.6\bin\pycharm.exe;%PATH%
cd %HOMEPATH%\TER\development
start "PyCharm aware of Quantum GIS" /B "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.6\bin\pycharm.exe" %*

编辑:在应用了luca76 76的建议之后

代码语言:javascript
复制
C:\Python34\python.exe D:/TER/development/test.py
Fatal Python error: Py_Initialize: unable to load the file system codec
  File "D:\OSGEO4~1\apps\Python27\lib\encodings\__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax

使用退出代码3完成的处理

我假设它必须使用调用Python3.4而不是Python2.7来做一些事情。

编辑:第3轮

这一次我的尝试包括了卢卡斯提案的一个稍微修改的版本。

然而,我所做的是删除HOMEPATH,但是,这一次当我试图导入qgis模块时,我得到了一个跟踪:

代码语言:javascript
复制
Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import qgis.core
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\OSGeo4W64\apps\qgis\python\qgis\__init__.py", line 36, in <module>
    from qgis.core import QgsFeature, QgsGeometry
  File "D:\OSGeo4W64\apps\qgis\python\qgis\core\__init__.py", line 3, in <module
>
    from qgis._core import *
ImportError: DLL load failed: The specified module could not be found.
>>>
EN

回答 1

Stack Overflow用户

发布于 2015-05-06 07:02:59

尝试在执行o4w_env.bat之前放置环境变量:(记得修复所有目录路径!)

代码语言:javascript
复制
@echo off
SET OSGEO4W_ROOT=D:\OSGeo4W64
set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python;%PYTHONPATH%
set PYTHONPATH=%OSGEO4W_ROOT%\apps\Python27\Lib\site-packages;%PYTHONPATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis
set PATH=C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.6\bin\pycharm.exe;%PATH%
path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
path %OSGEO4W_ROOT%\apps\grass\grass-6.4.3\lib;%PATH%

call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass-6.4.3\etc\env.bat

cd %HOMEPATH%\TER\development
start "PyCharm aware of Quantum GIS" /B "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.6\bin\pycharm.exe" %*
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30063439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档