2

Starting with a command window started by OSGeo4W, I successfully installed the fastkml python package compatible with python 2.7 running on windows 7.

When I run python from the command window, I can import the kml module from the fastkml package.

However, if I start the IDLE user interface from the same command window and try importing the kml module from the fastkml package, I get errors as follows:

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

The following is code from the bat file used to start OSgeo4W which in turn starts 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 "%*")
Hamish Drewry
  • 65
  • 1
  • 6
  • The behavior you report is puzzling. IDLE should not, and I am tempted to say cannot, affect the creation of the regex or the result of trying to compile it. Please rerun python from the command window and see whether the initial splash line `Python 2.7.10 (default, May 23 2015, ...` is *exactly the same. After `> from fastkml import kml`, what does `> kml.__file__` return? If you add `print pattern, flags` to re.compile (before the return), what is printed when running python and IDLE? What are the command line that you use to start python and IDLE in the console? – Terry Jan Reedy Feb 09 '17 at 21:40
  • initial splash line is: Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32 – Hamish Drewry Feb 09 '17 at 22:57
  • kml.__file__ returns C:\OSGeo4W\apps\Python27\lib\site-packages\fastkml\kml.pyc – Hamish Drewry Feb 09 '17 at 23:00
  • The bat file used to start OSGeo4W and IDLE is now shown in the original posting. – Hamish Drewry Feb 09 '17 at 23:26
  • @TerryJanReedy I do not have a re.compile file. Did you not mean the following file C:\OSGeo4W\apps\Python27\lib\re.py", line 190 ? – Hamish Drewry Feb 10 '17 at 16:30
  • `re.compile` is the `compile` function within the `re` module created from `re.py`. I meant to insert the line within the body of the function. – Terry Jan Reedy Feb 11 '17 at 03:03
  • Where is the .bat file located? – Terry Jan Reedy Feb 11 '17 at 03:27

1 Answers1

1

AS I suspected, you have two python 2.7s installed. As near as I can tell from the paths and splash screens:

C:\python27 has 2.7.10, which your batch files uses to run IDLE.

C:\OSGeo4W\apps\Python27 must have 2.7.4 and this is likely the python that your are running directly, and which does the import correctly.

Running >>> import sys; sys.executable in both shells will verify or correct these conclusions. If they are correct, then a possible fix is to replace C:\python27 in the batch file with C:\OSGeo4W\apps\Python27 so that IDLE is running on the python that worked. It is, of course, possible that C:\OSGeo4W\apps\Python27\Lib does not contain \idlelib.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
  • Thanks. Yes you are correct. I will return to this later this week to correct the environment and confirm that all is well. – Hamish Drewry Feb 11 '17 at 16:43
  • The answer given by @strm_1 to the question posted : http://stackoverflow.com/questions/25836182/cant-get-python-idle-to-recognize-ogr-gdal-module got me sorted. Many thanks. – Hamish Drewry Feb 17 '17 at 15:45