Giter Club home page Giter Club logo

Comments (5)

Carreau avatar Carreau commented on July 20, 2024

There is no hidden import in notebook, nor in terminal. Do you have a custom config ?
What import do you have in mind ?

(the ipython/nbconvert is indeed legacy code with have for historical reasons)

from nbconvert.

InonS avatar InonS commented on July 20, 2024

Hi Matthias!

Thanks for your response.
I had to add the following, after giving up on trying to use IPython
magics from inside my python script (in particular, my notebook had
"%pylab inline"):

import cProfile import datetime from functools import reduce import itertools import math import pstats, io from subprocess import check_output, call import sys import time import warnings import cairocffi

from IPython.utils.encoding import DEFAULT_ENCODING
from scipy.optimize import curve_fit
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np

The first 10 or so are definitely core python packages (I admit that
some of these I loaded by hand, e.g. cProfile). The bottom 5 are
probably loaded by the %pylab magic.
Are none of the imports above loaded implicitly??

Thanks,

Inon Sharony
ינון שרוני
+972(3)6407634
http://www.TAU.ac.IL/~inonshar
Please consider your environmental responsibility before printing this e-mail.

Quoting Matthias Bussonnier [email protected]:

There is no hidden import in notebook, nor in terminal. Do you have
a custom config ?
What import do you have in mind ?

(the ipython/nbconvert is indeed legacy code with have for
historical reasons)


Reply to this email directly or view it on GitHub:
#54 (comment)

from nbconvert.

Carreau avatar Carreau commented on July 20, 2024

Well, no, none of the above packages are imported implicitely by default.

you import them by doing %pylab inline, and this is one of the reason %pylab is undocumented and deprecated. %pylab is not ment to do inline graph. %matplotlib inline is ment to do that. If you do not know what %pylab does, then you probably should not use it, or it will bite you in other places.

Magics are non python syntax, so no magic will ever be valid in Python script.
Though, most magics are "just" syntactic sugar for Python expression, that hist -t can show you:

In [1]: %matplotlib inline
UsageError: Invalid GUI request 'inline', valid ones are: wx, osx, qt, qt5, glut, gtk, tk, pyglet, gtk3
In [2]: hist -t
get_ipython().magic('matplotlib inline')
get_ipython().magic('hist -t')

It does not really help you though as most of the magic need access to a ipython shell to work, but can at least make the syntax valid.

Feel free to continue asking if you have more questions,
closing the bug for now.

from nbconvert.

InonS avatar InonS commented on July 20, 2024
Wow, Matthias, thanks for a wonderful explanation!
I really appreciate that you took the time. I'm sure someone will
probably benefit from it in the future (all user errors reproduce
after a while... :-)
I was just a bit thrown off by [the
  documentation explaining how to embed](https://ipython.org/ipython-doc/dev/interactive/reference.html) an instance of IPython
in a regular python script, so I thought I might do that. Since
invoking get_ipython() did not work for me after a reasonable
effort, I decided to give up on IPython for non-interactive
computations. 
As for *pylab*, I'll heed your advice and switch to *%matplotlib inline*
for my notebook plotting. Again, I just took existing tutorials and
such which almost always begin with *%pylab inline*. I'll have to
figure out which of the other imports I'll have to do explicitly in
the notebook.
IMHO all of the points you discussed are worth mentioning in some
highly visible place on the project website and/or documentation, to
save people the trouble of figuring these things out the hard way.

Thank you, again, 
and have a wonderful weekend!

from nbconvert.

Carreau avatar Carreau commented on July 20, 2024

Here is (roughly) what %pylab does

import numpy
import matplotlib
from matplotlib import pylab, mlab, pyplot
np = numpy
plt = pyplot
from IPython.core.pylabtools import figsize, getfigs
from pylab import *
from numpy import *

The problem with writing loud and clear what not to do, is that people will not remember why it's wrong and what the issues are, they will just remember they can do it.

from nbconvert.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.