Wednesday, August 24, 2011

An environment variable setting issue for python os.system method (Windows)

Yesterday, I encountered an interesting problem about environment settings for Python os.system method. I tried to run a shell command "msgfmt -o file.mo file.po" in python. Msgfmt.exe locates in D:\MinGW\bin, and it's added in the environment variable PATH for Administrator. When I call the following command in the python interactive shell:
os.system("msgfmt -o file.mo file.po")
It works perfectly. When I run the python file containing this line of codes, it runs perfectly too. However, when it is loaded as a module in Mod_Python's psp file, it doesn't work anymore and fails silently. After investigation, it turns out that the msgfmt is not recognized by Mod_Python as an executable command. Because window cmd shell is default to be running as Administrator, and PATH for Administrator works for Python while Mod_Python is not running as Administrator which caused this problem. Therefore adding D:\MinGW\bin into system variables PATH solved this problem perfectly.

1 comment:

  1. William Hill Betting Locations | Mapyro
    Find William Hill ventureberg.com/ sports betting locations 출장샵 in Maryland, septcasino West Virginia, worrione Indiana, Pennsylvania, South Dakota, West Virginia 스포츠 토토 사이트 and more. BetRivers.com.

    ReplyDelete