pythonpathmodulekomodokomodoedit

Komodo Edit Changes Python sys.path If you "Show in Explorer"


I am using Komodo Edit, a code editor.

When I right click on projects and click "Show in Explorer", it will pop up a box just like Windows Explorer at the directory my project is. This is very convenient.

However, I noticed an insidious side effect. When you try to run a python file with this window that looks exactly like Windows Explorer, you will find out that it completely messes up sys.path in Python to use its own directory.

Is there any way to avoid this?

import sys
sys.path

C:\Windows\system32\python26.zip
C:\Program Files\ActiveState Komodo Edit 5\lib\python\DLLs
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\plat-win
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\lib-tk
C:\Python26
C:\Program Files\ActiveState Komodo Edit 5\lib\python
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\site-packages
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\site-packages\win32
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\site-packages\win32\lib
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\site-packages\Pythonwin

Solution

  • This is indeed a problem in Komodo. It actually stems from the Explorer window spawned by Komodo having the PYTHONHOME environment variable set to include Komodo's path, since the child process inherits the parent's environment. I noticed this by opening a Command Prompt window through an Explorer spawned by Komodo. If you look at the output from set, it contains (among other things) the following:

    PYTHONHOME=C:\Program Files\ActiveState Komodo Edit 5\lib\python
    _KOMODO_HOSTUSERDATADIR=C:\Users\Dev\AppData\Roaming\ActiveState\KomodoEdit\5.1\host-host\
    _KOMODO_VERUSERDATADIR=C:\Users\Dev\AppData\Roaming\ActiveState\KomodoEdit\5.1\
    _XRE_USERAPPDATADIR=C:\Users\Dev\AppData\Roaming\ActiveState\KomodoEdit\5.1\host-host\XRE
    

    I reported this bug here at the ActiveState bug tracker.