getpass.getpass() hangs on ipython notebook - ipython

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'

Related

Why windows commands are not working in vscode-insiders' terminal (error: <3>init: (632) ERROR: UtilConnectUnix:466: connect failed 111)

VSCode Version: 1.53.0-insider (x64)
OS Version: Microsoft Windows [Version 10.0.21292.1010]
WSL version: WSL 2
distribution: Ubuntu-20.04
Steps to Reproduce:
(in wsl.exe)Type code-insiders ~ && exit
Press ctrl+j in the VSCode window
Type explorer.exe .
Result:
It shows me this error:
<3>init: (632) ERROR: UtilConnectUnix:466: connect failed 111
Question:
How can I fix it and why it is happening ?
Extensions on WSL:
ms-vscode.cpptools
eamodio.gitlens
ms-toolsai.jupyter
ms-python.vscode-pylance
ms-python.python
I think I had a similar issue here, you have to check the environment variables of you WSL2 session.
WSL_INTEROP=/run/WSL/197_interop
if this points to a not existing socket the connection fails.
cheers
Marco

environment variable not accessible when start python script by pydev runner

My configuration:
ubuntu 16.04 eclipse 4.7 python 2.7.12 PyDev 6.2.0.2017
When running test.py which contains blow code from PyDev:
print os.environ['PATH']
Expected values got printed out,then change 'PATH' to 'LIB_ROOT'
print os.environ['LIB_ROOT']
Got error:
LIB_ROOT=os.environ['LIB_ROOT']
File "/usr/lib/python2.7/UserDict.py", line 40, in __getitem__
raise KeyError(key)
KeyError: 'LIB_ROOT'
And same variable can be accessed from ipython console
and run test.py in bash
python test.py
expected valued got printed out also,can anybody tell me why?

Can't add 1+1 in ipython notebook

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

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.