<p>这是一个有点变通的方法,但是,鉴于ironpython的LIB目录安装在64位系统中的x86程序文件文件夹下,以及32位系统中的常规程序文件路径上,您可以这样做:</p>
<pre><code>import sys
import System
if System.IntPtr.Size * 8 == 32: # detect if we are running on 32bit process
sys.path.append(System.Environment.GetEnvironmentVariable("ProgramFiles") + "\IronPython 2.7\Lib")
else:
sys.path.append(System.Environment.GetEnvironmentVariable("ProgramFiles(x86)") + "\IronPython 2.7\Lib")
import os # it works !!
</code></pre>
<hr/>
<p>在这里,我们使用<code>%ProgramFiles%</code>和<code>%ProgramFiles(x86)%</code>来确定IronPython的安装路径。</p>
<p>引用维基百科关于<code>%ProgramFiles%</code>变量(<a href="http://en.wikipedia.org/wiki/Environment_variable" rel="nofollow">link</a>)的内容:</p>
<blockquote>
<p>%ProgramFiles%</p>
<p>This variable points to Program Files directory, which stores all the
installed program of Windows and others. The default on
English-language systems is C:\Program Files. In 64-bit editions of
Windows (XP, 2003, Vista), there are also %ProgramFiles(x86)% which
defaults to C:\Program Files (x86) and %ProgramW6432% which defaults
to C:\Program Files. The %ProgramFiles% itself depends on whether the
process requesting the environment variable is itself 32-bit or 64-bit
(this is caused by Windows-on-Windows 64-bit redirection).</p>
</blockquote>