无法从fastkml包导入kml模块

时间:2017-02-09 18:02:29

标签: python python-2.7 python-idle osgeo

从OSGeo4W启动的命令窗口开始,我成功安装了与在Windows 7上运行的python 2.7兼容的fastkml python包。

当我从命令窗口运行python时,我可以从fastkml包中导入kml模块。

但是,如果我从同一个命令窗口启动IDLE用户界面并尝试从fastkml包导入kml模块,我会收到如下错误:

Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
> from fastkml import kml

>Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    from fastkml import kml
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\fastkml\__init__.py", line 28, in <module>
    from pkg_resources import get_distribution, DistributionNotFound
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\pkg_resources\__init__.py", line 77, in <module>
    __import__('pkg_resources.extern.packaging.specifiers')
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\pkg_resources\extern\__init__.py", line 42, in load_module
    __import__(extant)
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\pkg_resources\_vendor\packaging\specifiers.py", line 275, in <module>
    class Specifier(_IndividualSpecifier):
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\pkg_resources\_vendor\packaging\specifiers.py", line 373, in Specifier
    r"^\s*" + _regex_str + r"\s*$", re.VERBOSE | re.IGNORECASE)
  File "C:\OSGeo4W\apps\Python27\lib\re.py", line 190, in compile
    return _compile(pattern, flags)
  File "C:\OSGeo4W\apps\Python27\lib\re.py", line 242, in _compile
    raise error, v # invalid expression
error: nothing to repeat

以下是用于启动OSgeo4W的bat文件中的代码,后者又启动了IDLE

@echo off
set OSGEO4W_ROOT=%~dp0
rem Convert double backslashes to single
set OSGEO4W_ROOT=%OSGEO4W_ROOT:\\=\%
echo. & echo OSGEO4W home is %OSGEO4W_ROOT% & echo.
set PATH=%OSGEO4W_ROOT%\bin;%PATH%
rem Add application-specific environment settings
for %%f in ("%OSGEO4W_ROOT%\etc\ini\*.bat") do call "%%f"
CALL C:\Python27\Lib\idlelib\idle.bat
@echo on
@if [%1]==[] (echo run o-help for a list of available commands & cmd.exe /k)    else (cmd /c "%*")

1 个答案:

答案 0 :(得分:1)

我怀疑,你安装了两个python 2.7。我可以从路径和启动画面中看到:

C:\ python27有2.7.10,您的批处理文件用它来运行IDLE。

C:\ OSGeo4W \ apps \ Python27必须有2.7.4,这可能是您直接运行的python,并且可以正确导入。

在两个shell中运行>>> import sys; sys.executable将验证或更正这些结论。如果它们是正确的,那么可能的解决方法是使用C:\python27替换批处理文件中的C:\OSGeo4W\apps\Python27,以便在运行的python上运行IDLE。当然,C:\OSGeo4W\apps\Python27\Lib可能不包含\idlelib