Jupyter Notebook launch fail from terminal - python

I am getting the following error message on launching Jupyter Notebook. I did conda update all already, but to no avail.
Traceback (most recent call last):
File "/Users/sparshbohra/opt/anaconda3/bin/jupyter-Notebook", line 7, in <module>
from notebook.notebookapp import main
File "/Users/sparshbohra/opt/anaconda3/lib/python3.7/site-packages/notebook/notebookapp.py", line 81, in <module>
from .services.kernels.kernelmanager import MappingKernelManager, AsyncMappingKernelManager
File "/Users/sparshbohra/opt/anaconda3/lib/python3.7/site-packages/notebook/services/kernels/kernelmanager.py", line 18, in <module>
from jupyter_client.session import Session
File "/Users/sparshbohra/opt/anaconda3/lib/python3.7/site-packages/jupyter_client/session.py", line 41, in <module>
from jupyter_client.jsonutil import extract_dates, squash_dates, date_default
File "/Users/sparshbohra/opt/anaconda3/lib/python3.7/site-packages/jupyter_client/jsonutil.py", line 10, in <module>
from dateutil.parser import parse as _dateutil_parse
File "/Users/sparshbohra/opt/anaconda3/lib/python3.7/site-packages/dateutil/parser.py", line 158
l.append("%s=%s" % (attr, `value`))
^
SyntaxError: invalid syntax

Would probably need a little mote information on how you're trying to launch it, on what system and what program etc. But assuming you have conda installed and the environment activated via conda activate my_env_path_name, you should be able to launch jupyter notebooks by typing jupyter notebook

Related

Create a virtualenv to run jupyter

I have created a new virtualenv and named it python with command virtualenv python.
output:
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/dema/python/bin/python3.7
Also creating executable in /Users/dema/python/bin/python
Installing setuptools, pip, wheel...
done.
Then I activate it with commande source python/bin/activate
Then I installed jupyter notebook with commande pip3 install notebook
Then I try running the notebook with command jupyter notebook
The error:
Traceback (most recent call last):
File "/anaconda2/bin/jupyter-notebook", line 7, in <module>
from notebook.notebookapp import main
File "/anaconda2/lib/python2.7/site-packages/notebook/notebookapp.py", line 60, in <module>
from tornado import httpserver
File "/anaconda2/lib/python2.7/site-packages/tornado/httpserver.py", line 33, in <module>
from tornado.http1connection import HTTP1ServerConnection, HTTP1ConnectionParameters
File "/anaconda2/lib/python2.7/site-packages/tornado/http1connection.py", line 30, in <module>
from tornado import iostream
File "/anaconda2/lib/python2.7/site-packages/tornado/iostream.py", line 40, in <module>
from tornado.netutil import ssl_wrap_socket, _client_ssl_defaults, _server_ssl_defaults
File "/anaconda2/lib/python2.7/site-packages/tornado/netutil.py", line 44, in <module>
_client_ssl_defaults = ssl.create_default_context(
AttributeError: 'module' object has no attribute 'create_default_context'
Why do Anaconda and python2.7 come into this when I am using an active env with python3.7? I am totally unable to understand.

Problem launching Jupyter Notebook from Anaconda

I am having issues launching Jupyter Notebook. I have tried to do it two ways and seem to get errors.
1 - Launching from the Anaconda Prompt using the command jupyter notebook or directly choosing from the Anaconda menu
I get the following:
(base) C:\Users\metni>jupyter notebook
Traceback (most recent call last):
File "C:\Users\metni\anaconda3\lib\site-packages\jsonschema\__init__.py", line 31, in <module>
from importlib import metadata
ImportError: cannot import name 'metadata' from 'importlib' (C:\Users\metni\anaconda3\lib\importlib\__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\metni\anaconda3\lib\site-packages\nbformat\validator.py", line 12, in <module>
from jsonschema import ValidationError
File "C:\Users\metni\anaconda3\lib\site-packages\jsonschema\__init__.py", line 33, in <module>
import importlib_metadata as metadata
ModuleNotFoundError: No module named 'importlib_metadata'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\metni\anaconda3\Scripts\jupyter-notebook-script.py", line 6, in <module>
from notebook.notebookapp import main
File "C:\Users\metni\anaconda3\lib\site-packages\notebook\notebookapp.py", line 80, in <module>
from .services.contents.manager import ContentsManager
File "C:\Users\metni\anaconda3\lib\site-packages\notebook\services\contents\manager.py", line 17, in <module>
from nbformat import sign, validate as validate_nb, ValidationError
File "C:\Users\metni\anaconda3\lib\site-packages\nbformat\__init__.py", line 32, in <module>
from .validator import validate, ValidationError
File "C:\Users\metni\anaconda3\lib\site-packages\nbformat\validator.py", line 23, in <module>
raise ImportError(str(e) + verbose_msg)
ImportError: No module named 'importlib_metadata'
Jupyter notebook format depends on the jsonschema package:
https://pypi.python.org/pypi/jsonschema
Please install it first.
2 - Launching from the command line with the same command
I get the following:
C:\Users\metni>jupyter notebook
Traceback (most recent call last):
File "C:\Users\metni\anaconda3\Scripts\jupyter-notebook-script.py", line 6, in <module>
from notebook.notebookapp import main
File "C:\Users\metni\anaconda3\lib\site-packages\notebook\notebookapp.py", line 64, in <module>
from tornado import httpserver
File "C:\Users\metni\anaconda3\lib\site-packages\tornado\httpserver.py", line 29, in <module>
import ssl
File "C:\Users\metni\anaconda3\lib\ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified module could not be found.
It seems like this is referring to a package called jsonschema which is not installed apparently, but running a pip install jsonschema does not solve the problem for me...
In the answer above I also have two two commands but they are a bit different
source /opt/anaconda/bin/activate root
and then
jupyter notebook
It seems like you have to go into your anaconda directory then bin, then you can
"activate root"
It also looks like you need to install some other dependencies for jupyter to run. Where is says
Jupyter notebook format depends on the jsonschema package:
https://pypi.python.org/pypi/jsonschema
Please install it first.
So if the above doesn't work try installing the other dependency and try again
Based on this answer from a similar question, I managed to solve the problem by running these two commands:
conda update -n root conda
conda update --all
I thus updated all packages, and the notebook is now launching.

VS Code: Can't run Python Interactive Window

When I try running a Python Interactive Window in VS Code i get the error message:
Jupyter notebook failed to launch.
Error: Traceback (most recent call last):
File "C:\Users\Parker\AppData\Local\Programs\Python\Python37\lib\site-packages\nbformat\validator.py", line 12, in <module>
from jsonschema import ValidationError
File "C:\Users\Parker\AppData\Roaming\Python\Python37\site-packages\jsonschema\__init__.py", line 11, in <module>
from jsonschema.exceptions import (
File "C:\Users\Parker\AppData\Roaming\Python\Python37\site-packages\jsonschema\exceptions.py", line 9, in <module>
import attr
ModuleNotFoundError: No module named 'attr'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\Parker\.vscode\extensions\ms-python.python-2020.5.80290\pythonFiles\vscode_datascience_helpers\daemon\daemon_python.py", line 54, in _decorator
return func(self, *args, **kwargs)
File "c:\Users\Parker\.vscode\extensions\ms-python.python-2020.5.80290\pythonFiles\vscode_datascience_helpers\jupyter_daemon.py", line 105, in m_exec_module_observable
self._start_notebook(args, cwd, env)
File "c:\Users\Parker\.vscode\extensions\ms-python.python-2020.5.80290\pythonFiles\vscode_datascience_helpers\jupyter_daemon.py", line 147, in _start_notebook
from notebook import notebookapp as app
File "C:\Users\Parker\AppData\Local\Programs\Python\Python37\lib\site-packages\notebook\notebookapp.py", line 83, in <module>
from .services.contents.manager import ContentsManager
File "C:\Users\Parker\AppData\Local\Programs\Python\Python37\lib\site-packages\notebook\services\contents\manager.py", line 17, in <module>
from nbformat import sign, validate as validate_nb, ValidationError
File "C:\Users\Parker\AppData\Local\Programs\Python\Python37\lib\site-packages\nbformat\__init__.py", line 33, in <module>
from .validator import validate, ValidationError
File "C:\Users\Parker\AppData\Local\Programs\Python\Python37\lib\site-packages\nbformat\validator.py", line 23, in <module>
raise ImportError(str(e) + verbose_msg)
ImportError: No module named 'attr'
Jupyter notebook format depends on the jsonschema package:
https://pypi.python.org/pypi/jsonschema
Please install it first.
Failed to run jupyter as observable with args notebook --no-browser --notebook-dir=C:\Users\Parker\AppData\Local\Temp\e74520b3-6a8d-4e0a-8f80-8ddf2a64bf70 --config=C:\Users\Parker\AppData\Local\Temp\e74520b3-6a8d-4e0a-8f80-8ddf2a64bf70\jupyter_notebook_config.py --NotebookApp.iopub_data_rate_limit=10000000000.0
There was another thread about this same problem here: Can't use Jupyter Notebook: jsonschema apparently missing, however, after following all the steps in the solution the error persist. If anyone might be able to provide a possible solution, I'd greatly appreciate it.
You need to install jupyter notebook seperately in code.
description is given: Jupyter notebook
So I ended up uninstalling and reinstalling Anaconda and VS Code and it fixed the problem.
EDIT: Akshat Zala helped me find the underlying problem. I was trying to run the Interactive Window in a brand new Anaconda environment. This means I did not have Jupyter Notebook installed on it yet, therefore, the interactive window would not work. I fixed this issue by activating the conda environment then running the command 'conda install -c conda-forge notebook'.

Import error while trying to run jupyter notebook

An import error occurs when trying to run jupyter notebook
I'm trying to run jupyter notebook using anaconda (git bash platform), and as I type in jupyter notebook, an import error occurs every time. I tried to lauch it inside an environment, but the same error occured.
$ jupyter notebook
Traceback (most recent call last):
File "C:\Users\User\Anaconda3\Scripts\jupyter-notebook-script.py", line 6, in
<module>
from notebook.notebookapp import main
File "C:\Users\User\Anaconda3\lib\site-packages\notebook\notebookapp.py", line 47, in <module>
from zmq.eventloop import ioloop
File "C:\Users\User\Anaconda3\lib\site-packages\zmq\__init__.py", line 47, in <module>
from zmq import backend
File "C:\Users\User\Anaconda3\lib\site-packages\zmq\backend\__init__.py", line 40, in <module>
reraise(*exc_info)
File "C:\Users\User\Anaconda3\lib\site-packages\zmq\utils\sixcerpt.py", line 34, in reraise
raise value
File "C:\Users\User\Anaconda3\lib\site-packages\zmq\backend\__init__.py", line 27, in <module>
_ns = select_backend(first)
File "C:\Users\User\Anaconda3\lib\site-packages\zmq\backend\select.py", line 27, in select_backend
mod = __import__(name, fromlist=public_api)
File "C:\Users\User\Anaconda3\lib\site-packages\zmq\backend\cython\__init__.py", line 6, in <module>
from . import (constants, error, message, context,
ImportError: DLL load failed: The specified module could not be found.
EDITED
After reinstalling pyzmq (and I tried reinstalling conda too), the following error occurs:
$ jupyter notebook
Traceback (most recent call last): File
"C:\Users\User\Anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py",
line 10, in
import sqlite3
File "C:\Users\User\Anaconda3\lib\sqlite3__init__.py", line 23, in
from sqlite3.dbapi2 import *
File "C:\Users\User\Anaconda3\lib\sqlite3\dbapi2.py", line 27, in
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\User\Anaconda3\Scripts\jupyter-notebook-script.py", line 6,
in
from notebook.notebookapp import main
File
"C:\Users\User\Anaconda3\lib\site-packages\notebook\notebookapp.py",
line 86, in
from .services.sessions.sessionmanager import SessionManager
File
"C:\Users\User\Anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py",
line 13, in
from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'
I found a similar issue open on GitHub for zmq. The recommendation by GitHub user harsh23tyagi that seems to work for most is to run the following:
pip uninstall pyzmq
pip install pyzmq
Working with conda env, jupyter notebook worked in (base) env but gave the .libzmq error in (my_env).
To be able to run notebooks from my_env, this worked for me :
pip uninstall pyzmq
pip install pyzmq==20 (no version for pyzmq didn't fix the issue for me)
It seems that updating pyzmq to the latest version fixes this problem for me.
conda install pyzmq=22

No module named prompt_toolkit.enums

I am trying to launch Jupyter notebook through my command line and run a python script. At first I was able to launch it via the terminal and run the script, but now the kernel does not launch and it gives me this error - "No module named prompt_toolkit.enums"
This is teh whole message from the terminal -
[I 20:33:38.256 NotebookApp] KernelRestarter: restarting kernel (4/5)
WARNING:root:kernel 151cba82-fb9a-4cfc-ba38-3df3f6f5bb61 restarted
Traceback (most recent call last):
File "/Users/aparihar/anaconda2/lib/python2.7/runpy.py", line 163, in _run_module_as_main
mod_name, _Error)
File "/Users/aparihar/anaconda2/lib/python2.7/runpy.py", line 111, in _get_module_details
__import__(mod_name) # Do not catch exceptions initializing package
File "/Users/aparihar/anaconda2/lib/python2.7/site-packages/ipykernel/__init__.py", line 2, in <module>
from .connect import *
File "/Users/aparihar/anaconda2/lib/python2.7/site-packages/ipykernel/connect.py", line 13, in <module>
from IPython.core.profiledir import ProfileDir
File "/Users/aparihar/anaconda2/lib/python2.7/site-packages/IPython/__init__.py", line 49, in <module>
from .terminal.embed import embed
File "/Users/aparihar/anaconda2/lib/python2.7/site-packages/IPython/terminal/embed.py", line 17, in <module>
from IPython.terminal.interactiveshell import TerminalInteractiveShell
File "/Users/aparihar/anaconda2/lib/python2.7/site-packages/IPython/terminal/interactiveshell.py", line 16, in <module>
from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode
ImportError: No module named prompt_toolkit.enums
I read a lot of questions posted here and on github but i am just not able to resolve this. I even shutdown all the sessions, used pip to install enums and relaunched the Chrome and terminal. Can someone please help?
Thanks!

Categories