views:

452

answers:

3

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
+2  A: 
luc
Thanks for working out a hack though I don't like to use the toolbox. I gave you an upvote.
Unknown
A: 

What should your sys.path be instead? It looks like Python is already on the path, but maybe you need other libraries there, too.

If you're missing some key directories, use sys.path.append in one of your Python modules. If you need to move the directory of the Python interpreter (which may be necessary in order to get relative pathnames to work), use os.chdir as well.

Edit: It strikes me that you probably already know about those functions and that the problem lies elsewhere.

Nikhil Chelliah
+4  A: 

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.

AKX
Ok good to know that this wasn't a "feature" and there wasn't an easy fix.
Unknown