2

Closed

sys.version is incomplete in user created engine, creating problems in platform.py

description

I've hit a bug where I can't use the platform.python_implementation() function in code running under a user created Python engine, because sys.version is "2.7.1 ()" instead of "2.7.1 (IronPython 2.7.1 (2.7.0.40) on .NET 4.0.30319.239)", and the platform module can't parse that.

 

import clr
clr.AddReference("IronPython")
 
from IronPython.Hosting import Python
 
CODE = """
import sys
import platform
 
print "Version:", sys.version
print "Implementation:", platform.python_implementation()
"""
 
engine = Python.CreateEngine()
engine.Execute(CODE)
Closed Dec 6 at 9:16 PM by jdhardy

comments

MarkusSchaber wrote Nov 17, 2011 at 7:43 AM

Does "Python.SetHostVariables(this ScriptEngine engine, string prefix, string executable, string version)" help?

jdhardy wrote Dec 21, 2011 at 8:25 AM

Fixed in baf43f6/a093f70.

adal wrote Mar 12, 2012 at 6:37 PM

This still fails in IronPython 2.7.2. Try running the code sample from above in it.

jdhardy wrote Mar 12, 2012 at 6:38 PM

Released in IronPython 2.7.2



** Closed by jdhardy 3/9/2012 11:51 PM

adal wrote Mar 12, 2012 at 6:38 PM

This still fails in IronPython 2.7.2. Try running the code sample from above in it.

jdhardy wrote Jun 24, 2012 at 6:16 PM

As a workaround, you can do:
Python.SetHostVariables(engine, sys.prefix, sys.executable, '')
to properly initialize it. I'll make sure a proper fix gets into 2.7.4.

jdhardy wrote Jul 13, 2012 at 7:33 PM

If you can't change the engine hosting code (if you use pyc.py, for example), you can also do
sys.version = '2.7.2 (IronPython 2.7.2.1 (2.7.0.40) on .NET 4.0.30319.239 (32-bit))'
before importing the platform module.

JoelLinn wrote Aug 1, 2012 at 11:01 PM

It does. sys.prefix and sys.executable are not set correctly. They point to the IPy assembly in the GAC directory.
Setting them to the current executable works, but sucks.

jdhardy wrote May 26, 2013 at 7:25 PM

Fixed (for real) in cb8abd3.