JupyterLab in Homebrew-installed Anaconda fails to start kernel, looks for old install - anaconda

I was hoping someone could help me understand why JupyterLab fails to spin up a kernel on my system.
Background
I'm working on macOS High Sierra. I used to have Anaconda installed via the Mac OS installer in the default location in my home folder ($HOME/anaconda). Based on this thread I uninstalled Anaconda.
I reinstalled Anaconda from the Homebrew Cask (placing export PATH=/usr/local/anaconda3/bin:"$PATH" in my .bashrc).
The Problem
Now when I
run jupyter-lab,
create a new notebook, and
select a Python 3 kernel,
the process fails with the following output:
Traceback (most recent call last):
File "/usr/local/anaconda3/lib/python3.6/site-packages/tornado/web.py", line 1543, in _execute
result = yield result
File "/usr/local/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1107, in run
yielded = self.gen.throw(*exc_info)
File "/usr/local/anaconda3/lib/python3.6/site-packages/notebook/services/sessions/handlers.py", line 73, in post
type=mtype))
File "/usr/local/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1107, in run
yielded = self.gen.throw(*exc_info)
File "/usr/local/anaconda3/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 79, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
File "/usr/local/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1107, in run
yielded = self.gen.throw(*exc_info)
File "/usr/local/anaconda3/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 92, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "/usr/local/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 315, in wrapper
yielded = next(result)
File "/usr/local/anaconda3/lib/python3.6/site-packages/notebook/services/kernels/kernelmanager.py", line 148, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "/usr/local/anaconda3/lib/python3.6/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "/usr/local/anaconda3/lib/python3.6/site-packages/jupyter_client/manager.py", line 259, in start_kernel
**kw)
File "/usr/local/anaconda3/lib/python3.6/site-packages/jupyter_client/manager.py", line 204, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "/usr/local/anaconda3/lib/python3.6/site-packages/jupyter_client/launcher.py", line 128, in launch_kernel
proc = Popen(cmd, **kwargs)
File "/usr/local/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/local/anaconda3/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '~/anaconda/bin/python': '~/anaconda/bin/python'
I'd already removed all references to $HOME/anaconda (my old install location) from my environment (.bashrc, .bash_profile), so I can't figure out where the reference is being picked up.
Any suggestions would be greatly appreciated.

This question was answered in this GitHub thread for the Jupyter project. The basic solution:
run jupyter kernelspec list to see if it points to the correct Python install
if not, remove the folder ~/Library/Jupyter
re-run jupyter kernelspec list
This should rebuild the directory and give output like
Available kernels:
python3 /usr/local/anaconda3/share/jupyter/kernels/python3
which is the proper location for the Homebrew install of Anaconda.

Related

Behave in parallel

I try to run behave tests in parallel. For this I use behave-parallel lib and demo project https://github.com/vishalm/behave_parallel_demo. But OS is Windows 10. After steps from Read_me file. I am getting next Tracebacks
(behave_parallel_demo-master) D:\Python_projects\behave_parallel_demo-master>behave --processes 5 --parallel-element feature
INFO: 0 scenario(s) and 3 feature(s) queued for consideration by 5 workers. Some may be skipped if the -t option was given...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\python27\Lib\multiprocessing\forking.py", line 381, in main
self = load(from_parent)
File "c:\python27\Lib\pickle.py", line 1384, in load
return Unpickler(file).load()
File "c:\python27\Lib\pickle.py", line 864, in load
dispatch[key](self)
File "c:\python27\Lib\pickle.py", line 1089, in load_newobj
obj = cls.__new__(cls, *args)
TypeError: __new__() takes exactly 3 arguments (2 given)
Traceback (most recent call last):
File "c:\python27\Lib\runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "c:\python27\Lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Users\Andriy_Petrenko\Envs\behave_parallel_demo-master\Scripts\behave.exe\__main__.py", line 9, in <module>
File "c:\users\andriy_petrenko\envs\behave_parallel_demo-master\lib\site-packages\behave\__main__.py", line 111, in main
failed = runner.run()
File "c:\users\andriy_petrenko\envs\behave_parallel_demo-master\lib\site-packages\behave\runner.py", line 561, in run
return self.run_with_paths()
File "c:\users\andriy_petrenko\envs\behave_parallel_demo-master\lib\site-packages\behave\runner.py", line 583, in run_with_paths
return self.run_multiproc()
File "c:\users\andriy_petrenko\envs\behave_parallel_demo-master\lib\site-packages\behave\runner.py", line 690, in run_multiproc
p.start()
File "c:\python27\Lib\multiprocessing\process.py", line 130, in start
self._popen = Popen(self)
File "c:\python27\Lib\multiprocessing\forking.py", line 280, in __init__
to_child.close()
IOError: [Errno 22] Invalid argument
What I do wrong or is this OS problem? It looks like that 5 workers were up but 1st problem is that TypeError: __new__() takes exactly 3 arguments (2 given) and 2nd IOError: [Errno 22] Invalid argument
I am not familiar with Behave so not sure whether you are passing the command line correctly but this error means that one of the method is expecting more arguments than you have provided. In this case, it's during creation of cls instance:
File "c:\python27\Lib\pickle.py", line 1089, in load_newobj
obj = cls.__new__(cls, *args)
This looks like some internal class instance so you do not control it directly so make sure you pass enough and correct arguments at command line.
Update your Behave package. it will work.
We have been trying for a long time to implement parallel test executions with behave (which is an amazing framework). Finally, we created our own wrapper on top of Behave, called BehaveX, that not only allow us to execute tests in parallel, but also comes with great reports and some additional features:
https://github.com/hrcorval/behavex
As BehaveX is implemented over the Behave framework, with this wrapper you should be able to replace the "behave" executable by "behavex", and run the tests in parallel using the following commands:
behavex -t #TAG --parallel-processes 4 --parallel-scheme scenario
behavex -t #TAG --parallel-processes 3 --parallel-scheme feature

Julia Kernel Error in Jupyter Notebook (Anaconda)

When I open a Julia 0.6.0 notebook using Jupyter, the kernel tries to connect, fails and the a red button "Kernel Error" appears at the top right of the notebook. I uninstalled and reinstalled, but nothing has changed. The following is the message I got when I click on the "Kernel error":
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\base\handlers.py", line 516, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 1055, in run
value = future.result()
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "<string>", line 4, in raise_exc_info
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 1063, in run
yielded = self.gen.throw(*exc_info)
File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\sessions\handlers.py", line 75, in post
type=mtype))
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 1055, in run
value = future.result()
File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 990, in _execute_child
startupinfo)
OSError: [WinError 740] The requested operation requires elevation.
Thanks in advance for your help!
It seem like you do not have enough permissions to start the Julia Kernel.
You should not need to be administrator to use the Julia kernel, but it seem like your computer is believing you should.
Try running the julia interpreter, and kernel manually to see if you can.

virtualenv AssertionError on Mac Maverick

The virtualenv broke. I've tried updating, re-installing with pip, setuptools, virtualenv in a bunch of combinations, but nothing works. I've also used brew doctor and still no clue to the problem. Does anyone have this problem and have found a fix? Am I missing a package before installing virtualenv?
Also, if you have similar assertionError, please comment. Maybe we can find a solution together.
Thanks!
$ virtualenv test1
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.11', 'console_scripts', 'virtualenv')()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py", line 820, in main
symlink=options.symlink)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py", line 980, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py", line 1176, in install_python
copy_required_modules(home_dir, symlink)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py", line 1114, in copy_required_modules
dst_filename = change_prefix(filename, dst_prefix)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py", line 1079, in change_prefix
(filename, prefixes)
AssertionError: Filename /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/readline.so does not start with any of these prefixes: ['/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/Users/user1/Library/Python/2.7/lib/python/site-packages', '/Users/user1/.local/lib/python/2.7/site-packages', '/Library/Frameworks/Python.framework/Versions/2.7', '/Users/user1/Library/Python/2.7/site-packages', '/Library/Python/2.7/site-packages']

iPython Notebook in Windows - Error on Startup

I am trying desperately to get ipython notebook to work in a windows environment. I installed Continuum IO's Anaconda, a scientific distribution of python. I want to use ipython notebook, but get the following error. ipython in the terminal works fine. Any thoughts?
UPDATE: As asked for below, here is the output from sys.path on my system.
['',
'C:\\Anaconda\\scripts',
'C:\\Anaconda\\lib\\site-packages\\distribute-0.6.45-py2.7.egg',
'C:\\Anaconda',
'C:\\Users\\btibert\\ C:\\Anaconda\\Scripts',
'C:\\Anaconda\\python27.zip',
'C:\\Anaconda\\DLLs',
'C:\\Anaconda\\lib',
'C:\\Anaconda\\lib\\plat-win',
'C:\\Anaconda\\lib\\lib-tk',
'C:\\Users\\btibert\\AppData\\Roaming\\Python\\Python27\\site-packages',
'C:\\Users\\btibert\\AppData\\Roaming\\Python\\Python27\\site-packages\\Orange\\orng',
'C:\\Users\\btibert\\AppData\\Roaming\\Python\\Python27\\site-packages\\setuptools-0.6c11-py2.7.egg-info',
'C:\\Anaconda\\lib\\site-packages',
'C:\\Anaconda\\lib\\site-packages\\PIL',
'C:\\Anaconda\\lib\\site-packages\\win32',
'C:\\Anaconda\\lib\\site-packages\\win32\\lib',
'C:\\Anaconda\\lib\\site-packages\\Pythonwin',
'C:\\Users\\btibert\\AppData\\Roaming\\Python\\Python27\\site-packages\\IPython\\extensions']
And here is the error:
C:\Users\btibert>ipython notebook
Traceback (most recent call last):
File "C:\Anaconda\Scripts\ipython-script.py", line 5, in <module>
sys.exit(launch_new_instance())
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\IPython\frontend\terminal\ipapp.py", line 402, in
launch_new_instance
app.initialize()
File "<string>", line 2, in initialize
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\IPython\config\application.py", line 84, in catch
_config_error
return method(app, *args, **kwargs)
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\IPython\frontend\terminal\ipapp.py", line 302, in
initialize
super(TerminalIPythonApp, self).initialize(argv)
File "<string>", line 2, in initialize
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\IPython\config\application.py", line 84, in catch
_config_error
return method(app, *args, **kwargs)
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\IPython\core\application.py", line 325, in initia
lize
self.parse_command_line(argv)
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\IPython\frontend\terminal\ipapp.py", line 297, in
parse_command_line
return super(TerminalIPythonApp, self).parse_command_line(argv)
File "<string>", line 2, in parse_command_line
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\IPython\config\application.py", line 84, in catch
_config_error
return method(app, *args, **kwargs)
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\IPython\config\application.py", line 413, in pars
e_command_line
return self.initialize_subcommand(subc, subargv)
File "<string>", line 2, in initialize_subcommand
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\IPython\config\application.py", line 84, in catch
_config_error
return method(app, *args, **kwargs)
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\IPython\config\application.py", line 349, in init
ialize_subcommand
subapp = import_item(subapp)
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\IPython\utils\importstring.py", line 40, in impor
t_item
module = __import__(package,fromlist=[obj])
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\IPython\frontend\html\notebook\notebookapp.py", l
ine 34, in <module>
from zmq.eventloop import ioloop
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\zmq\eventloop\__init__.py", line 3, in <module>
from zmq.eventloop.ioloop import IOLoop
File "C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\zmq\eventloop\ioloop.py", line 56, in <module>
from zmq.eventloop.platform.auto import set_close_exec, Waker
ImportError: No module named platform.auto
It would be helpful to know what your sys.path is. You can find that by doing:
$ ipython
In [1]: import sys
In [2]: sys.path
And then share here the output. Next, you want to check what files you have in this directory:
C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages\zmq\eventloop\platform
Ideally, you'll see auto.py there, and if C:\Users\btibert\AppData\Roaming\Python\Python27\site-packages is in your sys.path then it is a mystery why it isn't working, but if that file isn't there, the directory doesn't exist, or the path to site-packages isn't in your sys.path, then those need to be resolved first.
Let us know and we can try to take it from there!
I figured out one way to attack this. I didn't really think I would have to get this level, but I completely uninstalled every single possible instance of python I could find. I
unisntalled Anaconda CE
removed every reference to python in PATH
edited my registry to clear out python data (but did leave Python folders)
Removed python from the App/Roaming path outlined above by #IanSR
Basically, I removed every possible reference to python I could find and then re-installed Anaconda CE. Voila, the Anaconda install (appears) to have worked as intended by the distributors.

Using windows command line to run python script with passing of url argument

I am writing this Python program which extracts some information from a webpage and I am required to run it using the windows command line. But I could not even print the original html page as a string. I am using Python 2.7
Here is my Python script:
#sys.py
import sys
import urllib
url = sys.argv[1]
f = urllib.urlopen(url)
print f.read()
When I try to run it from windows command line with: C...>sys.py "www.marinetraffic.com/ais/shipdetails.aspx?mmsi=311389000"
Errors appear as follows:
Traceback(most recent call last):
File "C:\...\sys.py", line 14 in <module>
f = urllib.urlopen(url)
File "C:\Python27\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 208, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 463, in open_file
return self.open_local_file(url)
File "C:\Python27\lib\urllib.py", line 87, in open_loca_file
raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] The system cannot find the path specified: 'www.marinetraffic.com\\ais\\shipdetails.aspx?mmsi=311389000'
There should not be any problem with the Python set up under the windows environment because I can still print out the sys.argv list as the arguments are passed in the command line.
Is it the problem with the 'urllib' library?
Is there any another way to run this using windows command line?
I think the problem is the way you specify your url, it needs to have the http:// part at the start.
It works for me when I type
python sys.py http://www.google.com/
but fails with
python sys.py www.google.com
(Note that I am using linux with python 2.7 but I think it may be the same problem for you)

Resources