[Ironpython-users] Cpython module import: ipy.exe vs. ScriptEngine semantics

Stéphane Lozier stephane.lozier at gmail.com
Wed Aug 9 17:05:09 EDT 2017


Notice that in the traceback it's listing the failing files as coming from
C:\Python27\Lib. IronPython has its own set of standard libraries and those
need to be included when using ScriptEngine. When you use ipy.exe it loads
the proper standard libraries (if you type sys.path in the interactive you
should see the ipy folders listed out). My guess is that's why your script
is failing.

Stéphane

On Thu, Aug 3, 2017 at 5:10 PM, ☯ D.Snezhkov <dsnezhkov at gmail.com> wrote:

> Hello,
>
> I am trying to work with prompt_toolkit module in my IronPython
> application, and I see different results on interactive import via ipy.exe
> vs. called from ScriptEngine.
>
> If I import the module in interactive console (ipy64.exe -X:Frames
> -X:BasicConsole) everything works. (I have to force sys,platform to read
> 'win32', otherwise the value is 'cli' )
>
> >>> sys.path.append(r"C:\Python27\Lib")
> >>> sys.path.append(r"C:\Python27\Lib\site-packages")
> >>> sys.platform="win32"
> >>> try:
> ...    from prompt_toolkit import prompt
> ... except Exception as e:
> ...    traceback.print_exc(file=sys.stdout)
> ...
> >>> sys.executable
> 'c:\\IronPython-2.7.7\\ipy64.exe'
>
>
> However if a file with same instructions is called from C# application
> with ScriptEngine with CreateScriptSourceFromFile() API, I get errors on
> import (below).
>
>
> sys.path.append(r"C:\Python27\Lib")
> sys.path.append(r"C:\Python27\Lib\site-packages")
>
> try:
>
>    sys.platform="win32" # force the use of win32 otherwise it has 'cli'
>
>    from prompt_toolkit import prompt
>
> except Exception as e:
>
>    traceback.print_exc(file=sys.stdout)
>
>
> I get the following error:
>
> Traceback (most recent call last):
>
>   File ".\pfile.py", line 39, in <module>
>
>     import prompt_toolkit
>
>   File "C:\Python27\Lib\site-packages\prompt_toolkit\__init__.py", line
> 16, in <module>
>
>     from .interface import CommandLineInterface
>
>   File "C:\Python27\Lib\site-packages\prompt_toolkit\interface.py", line
> 19, in <module>
>
>     from .application import Application, AbortAction
>
>   File "C:\Python27\Lib\site-packages\prompt_toolkit\application.py",
> line 3, in <module>
>
>     from .buffer import Buffer, AcceptAction
>
>   File "C:\Python27\Lib\site-packages\prompt_toolkit\buffer.py", line 27,
> in <module>
>
>     import tempfile
>
>   File "C:\Python27\Lib\tempfile.py", line 32, in <module>
>
>     import io as _io
>
>   File "C:\Python27\Lib\io.py", line 69, in <module>
>
>     class IOBase(_io._IOBase):
>
>   File "C:\Python27\Lib\io.py", line 71, in IOBase
>
>     __doc__ = _io._IOBase.__doc__
>
> ValueError: The path is not of a legal form.
>
>
> How is ipy.exe invocation is different than ScriptEngine, and how can I
> properly import the module?
>
> Thanks.
>
> _______________________________________________
> Ironpython-users mailing list
> Ironpython-users at python.org
> https://mail.python.org/mailman/listinfo/ironpython-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20170809/c4069116/attachment.html>


More information about the Ironpython-users mailing list