Can't add 1+1 in ipython notebook - ipython

Since some updates of ipython and efforts to install R in jupyter I just can't even add 1 and 1:
1+1 just yields no output in a python notebook (jupyter).
The console from where the notebook is launched indicates some problem with IPKernel App ...
$ jupyter notebook
[I 16:15:44.792 NotebookApp] Serving notebooks from local directory: /home/jeanpat
[I 16:15:44.792 NotebookApp] 0 active kernels
[I 16:15:44.792 NotebookApp] The IPython Notebook is running at: http://localhost:8888/
[I 16:15:44.792 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
(process:11705): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
[I 16:15:50.325 NotebookApp] Kernel started: 50c937a7-9ab6-456f-8e65-6d7de55301a6
[IPKernelApp] ERROR | No such comm target registered: ipython.widget
[I 16:17:50.327 NotebookApp] Saving file at /Untitled.ipynb
However 1+1 yields 2 if executed in an ipython console:
~$ ipython
Python 2.7.9 (default, Apr 2 2015, 15:33:21)
Type "copyright", "credits" or "license" for more information.
IPython 4.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: 1+1
Out[1]: 2

Removing ~/.local/share/jupyter fixed the problem. Running with the debug mode (jupyter notebook --debug) showed where jupyter was looking for its kernels. – Jean-Pat 2 hours ago

Related

why jupyterlab show duplicated kernels?how to delete?

Duplicated kernels
(base) PS C:\Users\Administrator> jupyter kernelspec list
[ListKernelSpecs] WARNING | Config option kernel_spec_manager_class not recognized by ListKernelSpecs.
Available kernels:
python36 C:\Users\Administrator\AppData\Roaming\jupyter\kernels\python36
python3 d:\ProgramData\Anaconda3\share\jupyter\kernels\python3
xpython d:\ProgramData\Anaconda3\share\jupyter\kernels\xpython
xpython-raw d:\ProgramData\Anaconda3\share\jupyter\kernels\xpython-raw
why jupyterlab show duplicated kernels?
how to delete?
thanks.

getpass.getpass() hangs on ipython notebook

I am using very simple code on ipython notebook for user to input password. Command hangs after user inputs the password. Here is my code sample -
import getpass
try:
p = getpass.getpass()
except Exception as error:
print('ERROR', error)
else:
print('Password entered:', p)
I tried raw_input() as well, it hangs exactly the same way.
try:
p = raw_input()
except Exception as error:
print('ERROR', error)
else:
print('Password entered:', p)
Any idea what's the solution for this.
I am running jupyter notebook on AWS server. Here are the version details -
Python 2.7.13 |
Anaconda 2.5.0 (64-bit)| (default, Dec 20 2016, 23:09:15)
GCC 4.4.7 20120313
Red Hat 4.4.7-1
IPython.__version__ '4.0.3'

ipython style tab complete with ipdb for imported modules

I'm trying to get ipython style table complete with pdb by using ipdb.
On a clean ubuntu 14.04 install (new aws instance) I run.
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install python-setuptools
sudo easy_install pip
sudo pip install ipython
sudo pip install ipdb
sudo pip install boto
Then boot up ipython, and try.
ubuntu#ip-10-0-0-244:~$ ipython
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
Type "copyright", "credits" or "license" for more information.
IPython 2.3.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import ipdb
In [2]: import boto
In [3]: ipdb.set_trace()
--Call--
> /usr/local/lib/python2.7/dist-packages/IPython/core/displayhook.py(234)__call__()
233
--> 234 def __call__(self, result=None):
235 """Printing with history cache management.
ipdb> str.
str.capitalize str.encode str.format str.isdigit str.isupper str.lstrip str.rfind str.rsplit str.startswith str.translate
str.center str.endswith str.index str.islower str.join str.mro str.rindex str.rstrip str.strip str.upper
str.count str.expandtabs str.isalnum str.isspace str.ljust str.partition str.rjust str.split str.swapcase str.zfill
str.decode str.find str.isalpha str.istitle str.lower str.replace str.rpartition str.splitlines str.title
ipdb> boto.
boto.[tab] just sits there. If I'm reading the docs right this should work, but maybe I have miss-understood something.
If I define a simple script test.py
import boto
print(boto.__version__)
Then call:
ubuntu#ip-10-0-0-244:~$ python -m ipdb test.py
> /home/ubuntu/test.py(1)<module>()
----> 1 import boto
2
3 print(boto.__version__)
ipdb> n
> /home/ubuntu/test.py(3)<module>()
1 import boto
2
----> 3 print(boto.__version__)
ipdb> boto.
boto.BUCKET_NAME_RE boto.connect_autoscale boto.connect_emr boto.connect_s3 boto.os
boto.BotoConfigLocations boto.connect_beanstalk boto.connect_euca boto.connect_sdb boto.perflog
boto.BucketStorageUri boto.connect_cloudformation boto.connect_fps boto.connect_ses boto.platform
boto.Config boto.connect_cloudfront boto.connect_glacier boto.connect_sns boto.plugin
boto.ENDPOINTS_PATH boto.connect_cloudsearch boto.connect_gs boto.connect_sqs boto.pyami
boto.FileStorageUri boto.connect_cloudsearch2 boto.connect_ia boto.connect_sts boto.re
boto.GENERATION_RE boto.connect_cloudtrail boto.connect_iam boto.connect_support boto.regioninfo
boto.InvalidUriError boto.connect_cloudwatch boto.connect_kinesis boto.connect_swf boto.resultset
boto.NullHandler boto.connect_cognito_identity boto.connect_logs boto.connect_vpc boto.s3
boto.TOO_LONG_DNS_NAME_COMP boto.connect_cognito_sync boto.connect_mturk boto.connect_walrus boto.set_file_logger
boto.UserAgent boto.connect_directconnect boto.connect_opsworks boto.datetime boto.set_stream_logger
boto.VERSION_RE boto.connect_dynamodb boto.connect_rds boto.exception boto.storage_uri
boto.Version boto.connect_ec2 boto.connect_rds2 boto.handler boto.storage_uri_for_key
boto.boto boto.connect_ec2_endpoint boto.connect_redshift boto.init_logging boto.sys
boto.compat boto.connect_elastictranscoder boto.connect_route53 boto.log boto.urlparse
boto.config boto.connect_elb boto.connect_route53domains boto.logging boto.vendored
I get the behavior I'd like.
Does anyone know how to make the tab complete functionality work for the set_trace() work case?
-Thanks

Getting started with SciPy and first example doesn't run

Environment is Ubuntu 12.x LTS 64 bit. I ran the install as follows :
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
Everything installed great, and I tried out the 'getting started' example only to come upon this error as if my env. is't set correctly..
See orig # http://www.scipy.org/getting-started.html
usernamep#ubuntudev:~$ ipython --pylab
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
Type "copyright", "credits" or "license" for more information.
IPython 0.12.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
Welcome to pylab, a matplotlib-based Python environment [backend: TkAgg].
For more information, type 'help(pylab)'.
In [1]: from scipy import special, optimize
In [2]: f = lambda x: -special.jv(3,x)
In [3]: sol = optimize.minimize(f, 1.0)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/user/<ipython-input-3-ea43eb308d3c> in <module>()
----> 1 sol = optimize.minimize(f, 1.0)
AttributeError: 'module' object has no attribute 'minimize'
In [4]:
Do I need to reform their example's import? Checking their docs now...
optimize.minimize was introduced in Scipy v.0.11 (see http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html ).
On Debian, that would mean that you need Jessie or better. On Ubuntu, you appear to need raring or better.
Almost certainly the scipy you installed using apt-get is simply too old to have minimize: (0.10, I'd guess). The code works for me:
>>> from scipy import special, optimize
>>> def f(x): return -special.jv(3,x)
>>> sol = optimize.minimize(f, 1.0)
>>> sol
status: 0
success: True
njev: 17
nfev: 51
hess_inv: array([[ 4.70024446]])
fun: -0.43439442684052476
x: array([ 4.20118891])
message: 'Optimization terminated successfully.'
jac: array([ -3.72529030e-09])
I think you'll be better off using pip to install the stack.
python-scipy package in the Ubuntu 12 is a bit old. I think it is ver 0.9.0. The optimize.minimize function was added to scipy ver 0.11.0.

Cannot run magic functions in ipython terminal

I am using Enthought's Canopy environment on a 64 bit Linux OS. Everything works fine in the Ipython console which is attached with the editor. But when I ipython in the terminal and try to use magic functions, I get the following error.
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-3-29a4050aa687> in <module>()
----> 1 get_ipython().show_usage()
/home/shahensha/Development/Canopy/appdata/canopy-1.0.3.1262.rh5-x86_64/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in show_usage(self)
2931 def show_usage(self):
2932 """Show a usage message"""
-> 2933 page.page(IPython.core.usage.interactive_usage)
2934
2935 def extract_input_lines(self, range_str, raw=False):
/home/shahensha/Development/Canopy/appdata/canopy-1.0.3.1262.rh5-x86_64/lib/python2.7/site-packages/IPython/core/page.pyc in page(strng, start, screen_lines, pager_cmd)
188 if screen_lines <= 0:
189 try:
--> 190 screen_lines += _detect_screen_size(screen_lines_def)
191 except (TypeError, UnsupportedOperation):
192 print(str_toprint, file=io.stdout)
/home/shahensha/Development/Canopy/appdata/canopy-1.0.3.1262.rh5-x86_64/lib/python2.7/site-packages/IPython/core/page.pyc in _detect_screen_size(screen_lines_def)
112 # Proceed with curses initialization
113 try:
--> 114 scr = curses.initscr()
115 except AttributeError:
116 # Curses on Solaris may not be complete, so we can't use it there
/home/shahensha/Development/Canopy/appdata/canopy-1.0.3.1262.rh5-x86_64/lib/python2.7/curses/__init__.pyc in initscr()
31 # instead of calling exit() in error cases.
32 setupterm(term=_os.environ.get("TERM", "unknown"),
---> 33 fd=_sys.__stdout__.fileno())
34 stdscr = _curses.initscr()
35 for key, value in _curses.__dict__.items():
error: setupterm: could not find terminfo database
So, I installed a bare bones iPython shell which is not the one provided by Canopy and tried the same magic functions in there and it works fine.
Have I done something wrong with the installation? Please help
Thanks a lot
shahensha
This is not a solution, but just an observation. My desktop is MacOS-X and I connect to a Centos machine to run Enthought Canopy both 64 bit. I get the same error message as OP if I ssh from iterm2, but not if I use the Terminal app.
I am not sure what the underlying reason is, but may be someone can verify if a similar situation is true for linux. Interestingly I can use either iterm2 or Terminal on the local canopy without any issues.
Update:
I just noticed that the TERM environment variable in iterm2 was set to "xterm" while the Terminal app was showing "xterm-256color". Issuing the command export TERM="xterm-256color" before running the Canopy ipython in terminal solves the issue for me in iterm2.
Problem reproduction:
$ python -c 'import curses; curses.setupterm()'
Traceback (most recent call last):
File "<string>", line 1, in <module>
_curses.error: setupterm: could not find terminfo database
This irc log gave me the idea that this error was to do with libncursesw.
My Canopy version is 1.0.3.1262.rh5-x86_64. I have installed it to ~/src/canopy.
In ~/src/canopy/appdata/canopy-1.0.3.1262.rh5-x86_64/lib we can see that my canopy install has libncursesw.so.5.7.
My machine (Debian Wheezy 64bit) has libncursesw.so.5.9 (in /lib/x86_64-linux-gnu/libncursesw.so.5.9). I made canopy use this. You can toggle the problem on / off by using LD_PRELOAD and pointing at the .so file.
Solution
Replace libncurses.so.5.7 with libncurses.so.5.9:
CANOPYDIR=$HOME/src/canopy
CANOPYLIBS=$CANOPYDIR/appdata/canopy-1.0.3.1262.rh5-x86_64/lib/
SYSTEMLIBS=/lib/x86_64-linux-gnu
cp $SYSTEMLIBS/libncurses.so.5.9 $CANOPYLIBS
ln -sf $CANOPYLIBS/libncurses.so.5.9 $CANOPYLIBS/libncurses.so.5
It appears that Canopy User Python is not your default. See this article:
https://support.enthought.com/entries/23646538-Make-Canopy-s-Python-be-your-default-Python-i-e-on-the-PATH-
Update: Not true here -- instead, see batu's workaround answer.