[IPython-User] Launching IPython from external "embedded" Python distribution

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[IPython-User] Launching IPython from external "embedded" Python distribution

klo uo
I use VisIt (https://wci.llnl.gov/simulation/computer-codes/visit) which includes own Python distribution, that is same version as my system Python - 2.7.5 64-bit. It also exposes it's API through own Python module, and includes PySide and vtk as additional modules.

The program includes regular Python console, which is uncomfortable compared to IPython, so I thought to look for clues. One easy way seemed using `visitrc` Python script which loads at program startup and is empty by default. I put this code inside:

========================================
import sys
sys.path = sys.path + ['C:\Python27\DLLs', 'C:\Python27\lib\site-packages']

import IPython
IPython.start_ipython(argv=[])
========================================

and I was happy to see IPython prompt when I run the program.

I tried further to load qtconsole instead terminal console:

    IPython.start_ipython(argv=['qtconsole'])

but that raised error, same as trying to pass any argument to start_ipython() function.

Not knowing what's the problem, I thought to ask for advise if there is something else I could try.

Here is output that's printed if I try to launch qtconsole as explained:

========================================
Error in sys.excepthook:
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\IPython\qt\console\qtconsoleapp.py", line
53, in gui_excepthook
    old_excepthook(exctype, value, tb)
TypeError: 'NoneType' object is not callable

Original exception was:
Traceback (most recent call last):
  File "C:\Users\klo\Documents\VisIt\visitrc", line 6, in <module>
    IPython.start_ipython(argv=['qtconsole'])
  File "C:\Python27\lib\site-packages\IPython\__init__.py", line 120, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "C:\Python27\lib\site-packages\IPython\config\application.py", line 563, in launch_instance
    app.initialize(argv)
  File "<string>", line 2, in initialize
  File "C:\Python27\lib\site-packages\IPython\config\application.py", line 92, in catch_config_error
    return method(app, *args, **kwargs)
  File "C:\Python27\lib\site-packages\IPython\terminal\ipapp.py", line 321, in initialize
    super(TerminalIPythonApp, self).initialize(argv)
  File "<string>", line 2, in initialize
  File "C:\Python27\lib\site-packages\IPython\config\application.py", line 92, in catch_config_error
    return method(app, *args, **kwargs)
  File "C:\Python27\lib\site-packages\IPython\core\application.py", line 381, in initialize
    self.parse_command_line(argv)
  File "C:\Python27\lib\site-packages\IPython\terminal\ipapp.py", line 316, in parse_command_line
    return super(TerminalIPythonApp, self).parse_command_line(argv)
  File "<string>", line 2, in parse_command_line
  File "C:\Python27\lib\site-packages\IPython\config\application.py", line 92, in catch_config_error
    return method(app, *args, **kwargs)
  File "C:\Python27\lib\site-packages\IPython\config\application.py", line 475, in parse_command_line
    return self.initialize_subcommand(subc, subargv)
  File "<string>", line 2, in initialize_subcommand
  File "C:\Python27\lib\site-packages\IPython\config\application.py", line 92, in catch_config_error
    return method(app, *args, **kwargs)
  File "C:\Python27\lib\site-packages\IPython\config\application.py", line 406, in initialize_subcommand
    subapp = import_item(subapp)
  File "C:\Python27\lib\site-packages\IPython\utils\importstring.py", line 42, in import_item
    module = __import__(package, fromlist=[obj])
  File "C:\Python27\lib\site-packages\IPython\qt\console\qtconsoleapp.py", line 67, in <module>
    from IPython.qt.client import QtKernelClient
  File "C:\Python27\lib\site-packages\IPython\qt\client.py", line 6, in <module>
    from IPython.kernel.channels import (
  File "C:\Python27\lib\site-packages\IPython\kernel\__init__.py", line 4, in <module>
    from . import zmq
  File "C:\Python27\lib\site-packages\IPython\kernel\zmq\__init__.py", line 14, in <module>
    check_for_zmq('2.1.11', 'IPython.kernel.zmq')
  File "C:\Python27\lib\site-packages\IPython\utils\zmqrelated.py", line 35, in check_for_zmq
    import zmq
  File "C:\Python27\lib\site-packages\zmq\__init__.py", line 30, in <module>
    _libzmq = ctypes.cdll.LoadLibrary(bundled[0])
  File "C:\Programs\LLNL\VisIt 2.7.3\lib\Python\lib\ctypes\__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
  File "C:\Programs\LLNL\VisIt 2.7.3\lib\Python\lib\ctypes\__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found

========================================

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|

Re: Launching IPython from external "embedded" Python distribution

Fernando Perez

On Wed, Aug 27, 2014 at 6:26 PM, klo uo <[hidden email]> wrote:
I tried further to load qtconsole instead terminal console:

    IPython.start_ipython(argv=['qtconsole'])

but that raised error, same as trying to pass any argument to start_ipython() function.

If you want to connect to IPython with the qt console, you'll need to embed a *kernel* into your process, and then connect to it from a standalone qt console.

These examples show the basics of that process:


Cheers

f


--
Fernando Perez (@fperez_org; http://fperez.org)
fperez.net-at-gmail: mailing lists only (I ignore this when swamped!)
fernando.perez-at-berkeley: contact me here for any direct mail

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|

Re: Launching IPython from external "embedded" Python distribution

klo uo
I tried that too, and get same error.
It looks like problem with anything that uses zmq.


On Thu, Aug 28, 2014 at 6:10 AM, Fernando Perez wrote:

If you want to connect to IPython with the qt console, you'll need to embed a *kernel* into your process, and then connect to it from a standalone qt console.

These examples show the basics of that process:




_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|

Re: Launching IPython from external "embedded" Python distribution

Fernando Perez

On Wed, Aug 27, 2014 at 9:44 PM, klo uo <[hidden email]> wrote:
I tried that too, and get same error.
It looks like problem with anything that uses zmq.

Ah, the issue seems to be that the Python that's bundled with Visit doesn't have pyzmq installed.  You can test that hypothesis by running, inside the embedded IPython (the plain terminal one that did run for you), 

import zmq

If that doesn't work, then indeed there's no zmq installed there. You need to install zmq in a location that Visit's python will find (or point it to where you have it installed by configuring $PYTHONPATH).

Cheers

f


--
Fernando Perez (@fperez_org; http://fperez.org)
fperez.net-at-gmail: mailing lists only (I ignore this when swamped!)
fernando.perez-at-berkeley: contact me here for any direct mail

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|

Re: Launching IPython from external "embedded" Python distribution

klo uo
On Thu, Aug 28, 2014 at 8:54 AM, Fernando Perez wrote:

Ah, the issue seems to be that the Python that's bundled with Visit doesn't have pyzmq installed.  You can test that hypothesis by running, inside the embedded IPython (the plain terminal one that did run for you), 

import zmq

If that doesn't work, then indeed there's no zmq installed there. You need to install zmq in a location that Visit's python will find (or point it to where you have it installed by configuring $PYTHONPATH).


I added my system's Python site-packages folder to sys.path, as I wrote in my initial message.

Importing zmq in IPython plain terminal fails with same error as if initiating "start_ipython(argv=['qtconsole'])" or embedding kernel.
VisIt's own ctypes tries to open zmq library (which is in sys.path) and it fails, and I don't understand why.

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|

Re: Launching IPython from external "embedded" Python distribution

Christoph Gohlke
On 8/28/2014 12:11 AM, klo uo wrote:

> On Thu, Aug 28, 2014 at 8:54 AM, Fernando Perez wrote:
>
>
>     Ah, the issue seems to be that the Python that's bundled with Visit
>     doesn't have pyzmq installed.  You can test that hypothesis by
>     running, inside the embedded IPython (the plain terminal one that
>     did run for you),
>
>     import zmq
>
>     If that doesn't work, then indeed there's no zmq installed there.
>     You need to install zmq in a location that Visit's python will find
>     (or point it to where you have it installed by configuring $PYTHONPATH).
>
>
> I added my system's Python site-packages folder to sys.path, as I wrote
> in my initial message.
>
> Importing zmq in IPython plain terminal fails with same error as if
> initiating "start_ipython(argv=['qtconsole'])" or embedding kernel.
> VisIt's own ctypes tries to open zmq library (which is in sys.path) and
> it fails, and I don't understand why.
>
>

VisIt 2.7.3 includes a custom Python 2.7.5 distribution that was
compiled with Visual Studio 2010. You can not simply load C extension
modules that were compiled with Visual Studio 2008 for the official
Python 2.7 distribution. It is best to rebuild pyzmq with msvc10 against
the Python distribution included with VisIt. VisIt ships with the
required Python C header files and libraries AFAICT.

Christoph

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|

Re: Launching IPython from external "embedded" Python distribution

klo uo
Thanks for the explanation.

I have Visual Studio 2013, but even if I had 2010, I wouldn't know how to build against VisIt Python distribution as there in no Python interpreter I can call from command line.


On Thu, Aug 28, 2014 at 10:12 AM, Christoph Gohlke wrote:

VisIt 2.7.3 includes a custom Python 2.7.5 distribution that was
compiled with Visual Studio 2010. You can not simply load C extension
modules that were compiled with Visual Studio 2008 for the official
Python 2.7 distribution. It is best to rebuild pyzmq with msvc10 against
the Python distribution included with VisIt. VisIt ships with the
required Python C header files and libraries AFAICT.


_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|

Re: Launching IPython from external "embedded" Python distribution

Fernando Perez

On Thu, Aug 28, 2014 at 6:20 AM, klo uo <[hidden email]> wrote:
I have Visual Studio 2013, but even if I had 2010, I wouldn't know how to build against VisIt Python distribution as there in no Python interpreter I can call from command line.


You may have better luck asking about this on the Visit list: this isn't really an IPython problem, it's a problem about how to use custom extensions with Visit.


--
Fernando Perez (@fperez_org; http://fperez.org)
fperez.net-at-gmail: mailing lists only (I ignore this when swamped!)
fernando.perez-at-berkeley: contact me here for any direct mail

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user