Mobileread
Using an interactive Python interpreter
#1  The_book 03-16-2020, 04:01 AM
After reading and searching, I find that
from calibre import ipython
ipython(locals())
code will not be useful, because now calibre do not conclude ipython.
So I think the https://manual.calibre-ebook.com/develop.html#id14 need to change. And now what can I do to Using an interactive Python interpreter
Reply 

#2  kovidgoyal 03-16-2020, 04:28 AM
In the absence of ipython it will run a simple python REPL.
Reply 

#3  The_book 03-16-2020, 06:37 AM
Quote kovidgoyal
In the absence of ipython it will run a simple python REPL.
I run this in windows, it just raise error, with:
Python function terminated unexpectedly
cannot import name ipython(Error Code: 1)
in directly open calibre.
And in cmd

calibredb

Hello world
Python function terminated unexpectedly
cannot import name ipython (Error Code: 1)
Traceback (most recent call last):
File "site.py", line 114, in main
File "site.py", line 87, in run_entry_point
File "D:\workplace\program\open-sourse\calibre-src\src\calibre\__init__.py", line 7, in <module>
from calibre import ipython
ImportError: cannot import name ipython

My code is

from __future__ import unicode_literals, print_function
''' E-book management software'''
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
print("Hello world")
from calibre import ipython
ipython(locals())

And I am working with the 4.12.0 with the source code of 4.12.0
Reply 

#4  kovidgoyal 03-16-2020, 07:46 AM
Works for me with

calibre-debug -c "from calibre import ipython; ipython()"


have you edited the source code of calibre/__init__.py??
Reply 

#5  The_book 03-16-2020, 08:34 AM
Quote kovidgoyal
Works for me with

calibre-debug -c "from calibre import ipython; ipython()"


have you edited the source code of calibre/__init__.py??
Yes, and I find why.
I add print ("Hello, world!") near the top of __init__.py. It works.
Then I continue to read and simply add code after print ("Hello, world!") , which cause error.
Then I find that calibre-debug -c "from calibre import ipython; ipython()" works with the unchange __init__.py.

Then I add
from calibre import ipython
ipython(locals())
to the end of __init__.py

It works.

After some checking, I find I should use those codes after defining of ipython function.
Reply 

#6  The_book 03-17-2020, 08:53 AM
After further testing, I find ipython somehow not working? is usefull.
And if someone like me want to use the ipython, here is the way:
open src\calibre\utils\ipython.py, add sys.path.extend([the path you got]) neer the top of this file, but after import os, re, sys , then we can use

from calibre import ipython
ipython(locals())

to open ipython again.
Reply 

Today's Posts | Search this Thread | Login | Register