prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.3k stars 715 forks source link

IronPython: Windows: No module named fcntl #526

Open dsnezhkov opened 7 years ago

dsnezhkov commented 7 years ago

Hello,

I am not sure if this is supported but trying to import prompt-toolkit (1.0.15) on Windows w/IronPython, and get Unhandled Exception: IronPython.Runtime.Exceptions.ImportException: No module named fcntl


sys.path.append(r"C:\Python27\Lib")
sys.path.append(r"C:\Python27\Lib\site-packages")

from prompt_toolkit import prompt

How does such import pick up fcntl on Windows, and is there a way to override/explicitly force the module to be aware of Windows platform so it can load appropriate dependencies?

Thank you.

jonathanslenders commented 7 years ago

Hi @dsnezhkov, fcntl is a module which is only available on Unix. Normally this shouldn't be imported on Windows. Could you share the full traceback?

In any case, I don't know of anyone using prompt_toolkit on IronPython actually. I'd be very interested to know whether that will work, but it's not tested.

dsnezhkov commented 7 years ago

Hi Jonathan,

Thanks for your response. I was trying to figure out how to get pure Python stack trace from the script,, and not the .Net DLR stack traces from the IronPython wrapper to show up. But here is what I have:

try:
   from prompt_toolkit import prompt
except Exception as e:
   traceback.print_exc(file=sys.stdout)
Traceback (most recent call last):
  File ".\pfile.py", line 20, in <module>
    from prompt_toolkit import prompt
  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 17, in <module>
    from subprocess import Popen
  File "C:\Python27\Lib\subprocess.py", line 429, in <module>
    import fcntl
ImportError: No module named fcntl
asmeurer commented 7 years ago

Can you import subprocess from within your script? This looks like an issue with your IronPython installation, not prompt-toolkit, and the fcntl import is inside the standard library subprocess module. Is it possible that C:\Python27 is a regular cpython installation and IronPython is picking up it (perhaps through the setting of some environment variables like PYTHONHOME)?

asmeurer commented 7 years ago

Oh I just saw your OP that you are manually adding C:\Python27 to your sys.path. That's evidently a bad idea, as apparently IronPython needs to use its own standard library.

dsnezhkov commented 7 years ago

Thank you @asmeurer.

I was going by http://www.ironpython.info/index.php?title=Using_the_Python_Standard_Library It looks like it's a standard way to add support for CPython libraries which on a limited basis has worked for pip installed modules in my tests. Also, listed in file:///C:/IronPython-2.7.7/Tutorial/Tutorial.htm#T1.4.1 tutorial that came with IronPython distribution. Is there a a better way?

I also went ahead and launched interactive IronPython shell to try the import. What I discovered is that

>>> sys.platform
'cli'

According to https://docs.python.org/2/library/sys.html#sys.platform is not a standard platfrom (DLR). I am wondering if prompt_toolkit defaults to *unix when the platform is not specifically win32? Could the platform be forced?

I get past fcntl in interactive console but stop at termios which is definitely not supported on Windows

λ ipy64.exe -X:Frames
IronPython 2.7.7 (2.7.7.0) on .NET 4.0.30319.42000 (64-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append(r"C:\Python27\Lib")
>>> sys.path.append(r"C:\Python27\Lib\site-packages")
>>> from prompt_toolkit import prompt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\Lib\site-packages\prompt_toolkit\__init__.py", line 16, in <module>
  File "C:\Python27\Lib\site-packages\prompt_toolkit\interface.py", line 27, in <module>
  File "C:\Python27\Lib\site-packages\prompt_toolkit\input.py", line 17, in <module>
  File "C:\Python27\Lib\site-packages\prompt_toolkit\terminal\vt100_input.py", line 9, in <module>
ImportError: No module named termios