Python gets the wrong value for os.environ ["ProgramFiles"] on the 64-bit version

Python 2.4.3 on a Vista64 machine.

The environment contains the following 2 variables:

ProgramFiles=C:\Program Files ProgramFiles(x86)=C:\Program Files (x86) 

But when I run the following

 import os print os.environ["ProgramFiles"] print os.environ["ProgramFiles(x86)"] 

I get:

 C:\Program Files (x86) C:\Program Files (x86) 

Any idea how I can get the correct value for "ProgramFiles"?

+4
source share
3 answers

On the Wikipedia page:

% ProgramFiles%

This variable points to the Program Files directory, which stores the entire installed Windows program and others. By default, English systems use C: \ Program Files. On 64-bit versions of Windows (XP, 2003, Vista) there are also% ProgramFiles (x86)%, which by default correspond to C: \ Program Files (x86) and% ProgramW6432%, which by default correspond to C: \ Program Files. % ProgramFiles% itself depends on whether the process requesting the environment variable is 32-bit or 64-bit itself (this is caused by 64-bit Windows-on-Windows redirection).

So, to get only C: \ Program Files, you apparently want to check %ProgramW6432% .

+11
source

You are using a 32-bit version of the Python interpreter. Using 32-bit software, WOW64 will create a new environment with its own folders and lookups.

You can see what I'm talking about simply by running the 64-bit and 32-bit versions of the command line:

64-bit cmd.exe:

 C:\Documents and Settings\Administrator>set prog ProgramFiles=C:\Program Files ProgramFiles(x86)=C:\Program Files (x86) 

32-bit cmd.exe:

 C:\WINDOWS\SysWOW64>set prog ProgramFiles=C:\Program Files (x86) ProgramFiles(x86)=C:\Program Files (x86) ProgramW6432=C:\Program Files 

As you can see from the second passage above, in order to get 64-bit program files, you must use the ProgramW6432 environment ProgramW6432 .

Another approach, however, can solve other problems that may arise in the future (especially with the registry settings!): Just use the 64-bit version of Python - even if I don't know where to download the 64-bit version 2.4.
+6
source

Can you install Python 2.5.4 and try again? UPDATE: I meant the release of x64 version 2.5.4. AFAIK 2.4 was available only for Windows x86 and IA64, and not for x64.

I am running 2.5.4 x64 on Win 7 x64 and I am not getting the same result, but I'm not sure if the problem is in Python or Vista in your case.

 Python 2.5.4 (r254:67916, Dec 23 2008, 15:19:34) [MSC v.1400 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> print os.environ["ProgramFiles"] C:\Program Files >>> print os.environ["ProgramFiles(x86)"] C:\Program Files (x86) >>> 
+5
source

All Articles