Jupyter notebook cannot start with python 3.8 in Windows 10 [duplicate] - python-3.x

This question already has answers here:
Jupyter Notebook with Python 3.8 - NotImplementedError
(4 answers)
Closed 3 years ago.
Here is the detailed error when launching jupyter notebook with python version 3.8
File "c:\users\kokat\appdata\local\programs\python\python38\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\kokat\appdata\local\programs\python\python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\kokat\AppData\Local\Programs\Python\Python38\Scripts\jupyter-notebook.EXE\__main__.py", line 9, in <module>
File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\jupyter_core\application.py", line 266, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\traitlets\config\application.py", line 657, in launch_instance
app.initialize(argv)
File "<c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\decorator.py:decorator-gen-7>", line 2, in initialize
File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\notebook\notebookapp.py", line 1628, in initialize
self.init_webapp()
File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\notebook\notebookapp.py", line 1407, in init_webapp
self.http_server.listen(port, self.ip)
File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\tornado\tcpserver.py", line 144, in listen
self.add_sockets(sockets)
File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\tornado\tcpserver.py", line 157, in add_sockets
self._handlers[sock.fileno()] = add_accept_handler(
File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\tornado\netutil.py", line 268, in add_accept_handler
io_loop.add_handler(sock, accept_handler, IOLoop.READ)
File "c:\users\kokat\appdata\local\programs\python\python38\lib\site-packages\tornado\platform\asyncio.py", line 79, in add_handler
self.asyncio_loop.add_reader(
File "c:\users\kokat\appdata\local\programs\python\python38\lib\asyncio\events.py", line 498, in add_reader
raise NotImplementedError
NotImplementedError
Any helps would be appreciated.

Following one of the comments in this thread, I've solved the problem by:
Locate and open the asyncio.py file. In my case it's in C:\Users\[USERNAME]\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\tornado\platform\
After the line import asyncio add the following:
from sys import platform
if platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # python-3.8.0a4
This will force using SelectorEventLoop on Windows.

Jupyter notebook runs as a tornado web server. Your browser connect to this tornado server via a socket.
The I/O of the socket are handled by tornado's asyncio, which relies on the add_reader implementation of the native asyncio module of python runtime. As pointed out in the documentation of asyncio, this method is only supported with Windows SelectorEventLoop so make sure you are using this kind of event loop in your python installation. To find out which eventloop implementation is in usage, you can run the following commands in python shell:
import asyncio
print(asyncio.get_event_loop().__class__)
# Output: <class 'asyncio.windows_events._WindowsSelectorEventLoop'>
There is an ongoing discussion about allowing user to change the EventLoopPolicy of asyncio in jupyter's configuration file.

Related

jupyter-console "RuntimeWarning: coroutine 'ZMQSocketChannel.msg_ready' was never awaited"

By running jupyter-console any press of Enter button show this error:
In [1]: /home/player1/.pyenv/versions/3.7.9/lib/python3.7/site-packages/jupyter_console/ptshell.py:852: RuntimeWarning: coroutine 'ZMQSocketChannel.msg_ready' was never awaited
while self.client.iopub_channel.msg_ready():
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Unhandled exception in event loop:
File "/home/player1/.pyenv/versions/3.7.9/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/home/player1/.pyenv/versions/3.7.9/lib/python3.7/site-packages/prompt_toolkit/input/vt100.py", line 168, in callback_wrapper
callback()
File "/home/player1/.pyenv/versions/3.7.9/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 691, in read_from_input
self.key_processor.process_keys()
File "/home/player1/.pyenv/versions/3.7.9/lib/python3.7/site-packages/prompt_toolkit/key_binding/key_processor.py", line 274, in process_keys
self._process_coroutine.send(key_press)
File "/home/player1/.pyenv/versions/3.7.9/lib/python3.7/site-packages/prompt_toolkit/key_binding/key_processor.py", line 186, in _process
self._call_handler(matches[-1], key_sequence=buffer[:])
File "/home/player1/.pyenv/versions/3.7.9/lib/python3.7/site-packages/prompt_toolkit/key_binding/key_processor.py", line 329, in _call_handler
handler.call(event)
File "/home/player1/.pyenv/versions/3.7.9/lib/python3.7/site-packages/prompt_toolkit/key_binding/key_bindings.py", line 102, in call
result = self.handler(event)
File "/home/player1/.pyenv/versions/3.7.9/lib/python3.7/site-packages/jupyter_console/ptshell.py", line 475, in _
self.handle_iopub()
File "/home/player1/.pyenv/versions/3.7.9/lib/python3.7/site-packages/jupyter_console/ptshell.py", line 854, in handle_iopub
msg_type = sub_msg['header']['msg_type']
Exception 'coroutine' object is not subscriptable
Press ENTER to continue...
I have tried different computers with different Linux distributions (Ubuntu, Mint, Manjaro KDE, Manjaro XFCE).
I tried different python versions (>3.6), different ipython verions and even with Docker.
Interesting that jupyter-qtconsole ,jupyter-notebook and ipython are working fine.
All answers I searched were about ipython or jupyter-notebook, but I need jupyter-console.
pip install jupyter-client==6.1.12
The answer is here: https://github.com/jupyter/jupyter_console/issues/241

Restore RethinkDB backup on MacOS Big Sur

My local Rethink database disappeared after upgrading to MacOS 11 (“Big Sur”). But that's alright, as I have a backup. But I can't, for the life of me, restore it.
rethinkdb restore [file] and rethinkdb import [file] didn't work, but after some googling I found that I had to install the python tools (pip3 install rethinkdb). I did that, but now I get this error:
% rethinkdb restore rethinkdb_dump_2020-11-21T20:35:20.tar.gz > bug.log
Traceback (most recent call last):
File "/usr/local/bin/rethinkdb-restore", line 10, in <module>
sys.exit(main())
File "/Users/$USER/Library/Python/3.8/lib/python/site-packages/rethinkdb/_restore.py", line 339, in main
do_restore(options)
File "/Users/$USER/Library/Python/3.8/lib/python/site-packages/rethinkdb/_restore.py", line 315, in do_restore
_import.import_tables(options, sources)
File "/Users/$USER/Library/Python/3.8/lib/python/site-packages/rethinkdb/_import.py", line 1359, in import_tables
progress_bar.start()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/context.py", line 283, in _Popen
return Popen(process_obj)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 32, in __init__
super().__init__(process_obj)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_fork.py", line 19, in __init__
self._launch(process_obj)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 47, in _launch
reduction.dump(process_obj, fp)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
TypeError: cannot pickle '_thread._local' object
I've tried to uninstall RethinkDB and the Python tools and reinstall both. Same outcome.
I was able to downgrade to python 3.7, reinstall the rethinkdb python driver and made it further in the rethinkdb restore process

Spyder: An error ocurred while starting the kernel [duplicate]

I have a problem with the Spyder software of Python(version 4.0.1) regarding the running kernels in the IPython Console. Accordingly, I have tried many ways to resolve the issue like running some commands in Anaconda prompt or set the settings to the default mode. I even updated the version of my anaconda and the spyder. Nevertheless, nothing has been changed and the issue still exists.
This is the error I am receiving:
Traceback (most recent call last): File
"C:\ProgramData\Anaconda3\lib\runpy.py", line 193, in
_run_module_as_main "main", mod_spec) File "C:\ProgramData\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals) File
"C:\ProgramData\Anaconda3\lib\site‑packages\spyder_kernels\console__main__.py",
line 11, in start.main() File
"C:\ProgramData\Anaconda3\lib\site‑packages\spyder_kernels\console\start.py",
line 287, in main import_spydercustomize() File
"C:\ProgramData\Anaconda3\lib\site‑packages\spyder_kernels\console\start.py",
line 39, in import_spydercustomize import spydercustomize File
"C:\ProgramData\Anaconda3\lib\site‑packages\spyder_kernels\customize\spydercustomize.py",
line 24, in from IPython.core.getipython import get_ipython File
"C:\ProgramData\Anaconda3\lib\site‑packages\IPython__init__.py", line
56, in from .terminal.embed import embed File
"C:\ProgramData\Anaconda3\lib\site‑packages\IPython\terminal\embed.py",
line 14, in from IPython.core.magic import Magics, magics_class,
line_magic File
"C:\ProgramData\Anaconda3\lib\site‑packages\IPython\core\magic.py",
line 20, in from . import oinspect File
"C:\ProgramData\Anaconda3\lib\site‑packages\IPython\core\oinspect.py",
line 30, in from IPython.lib.pretty import pretty File
"C:\ProgramData\Anaconda3\lib\site‑packages\IPython\lib\pretty.py",
line 82, in import datetime File "C:\Users\mahkam\datetime.py", line
4 ^ SyntaxError: EOF while scanning triple‑quoted string literal
(Spyder maintainer here) You need to rename or remove this file
C:\Users\mahkam\datetime.py
That's because that file is using the same name of Python internal module and that confuses other modules that depend on it.
Looks like you have a quoting error
File "C:\Users\mahkam\datetime.py", line 4 ^ SyntaxError: EOF while scanning triple‑quoted string literal
Check out your datetime.py

Unable to Start Scheduler

I am new to Python and trying to install Airflow in my Mac, by following this tutorial
While these two commands work fine:
$ airflow initdb
$ airflow webserver -p 8080
The scheduler command (airflow scheduler) throws the following error:
[2020-02-18 13:18:09,012] {scheduler_job.py:1382} ERROR - Exception when executing execute_helper Traceback (most recent call last):
File "/Users/mac/Workspace/airflow/airflow_venv/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 1380, in _execute
self._execute_helper()
File "/Users/mac/Workspace/airflow/airflow_venv/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 1413, in _execute_helper
self.processor_agent.start()
File "/Users/mac/Workspace/airflow/airflow_venv/lib/python3.8/site-packages/airflow/utils/dag_processing.py", line 554, in start
self._process.start()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/context.py", line 283, in _Popen
return Popen(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 32, in __init__
super().__init__(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_fork.py", line 19, in __init__
self._launch(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 47, in _launch
reduction.dump(process_obj, fp)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'SchedulerJob._execute.<locals>.processor_factory'
[2020-02-18 13:18:09,035] {helpers.py:322} INFO - Sending Signals.SIGTERM to GPID None
Traceback (most recent call last): File "/Users/mac/Workspace/airflow/airflow_venv/bin/airflow", line 37, in <module>
args.func(args) File "/Users/mac/Workspace/airflow/airflow_venv/lib/python3.8/site-packages/airflow/utils/cli.py", line 75, in wrapper
return f(*args, **kwargs) File "/Users/mac/Workspace/airflow/airflow_venv/lib/python3.8/site-packages/airflow/bin/cli.py", line 1040, in scheduler
job.run() File "/Users/mac/Workspace/airflow/airflow_venv/lib/python3.8/site-packages/airflow/jobs/base_job.py", line 221, in run
self._execute() File "/Users/mac/Workspace/airflow/airflow_venv/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 1384, in _execute
self.processor_agent.end() File "/Users/mac/Workspace/airflow/airflow_venv/lib/python3.8/site-packages/airflow/utils/dag_processing.py", line 707, in end
reap_process_group(self._process.pid, log=self.log) File "/Users/mac/Workspace/airflow/airflow_venv/lib/python3.8/site-packages/airflow/utils/helpers.py", line 324, in reap_process_group
signal_procs(sig) File "/Users/mac/Workspace/airflow/airflow_venv/lib/python3.8/site-packages/airflow/utils/helpers.py", line 293, in signal_procs
os.killpg(pgid, sig)
TypeError: an integer is required (got type NoneType)
EDIT: Python 3.8 is supported now https://github.com/apache/airflow#requirements. So this answer might not be relevant now.
This due to the Python version you are using. Airflow doesn't support Python 3.8 yet https://github.com/apache/airflow#stable-version-1109.
Downgrade your Python to 3.7 and check.
Maybe there are some compatibility problems?
Using Python 3.6.10 and airflow v1.10.4, I can get airflow running. Maybe you could try some other versions?
This worked for me!
1- Make sure you are using the correct celery version that supports your other packages like RabbitMQ ( as V5 doesn't support AMQP in its usual format), my advice is to use V4.6.X
2-THIS HAS NOTHING TO DO WITH PYTHON VERSION IF YOU ARE USING AIRFLOW V2.0
3- simply make yourself happy with airflow db reset (command may differ if you are using airflow Version X<2.0 )
4- Avoid deleting any dag like you delete a file and use airflow dag ... commands to do so. (it makes up a mess in your environment that you wont like, trust me on this..)
Wish you luck bearing python stuff..

urllib.urlopen() gives socket error: Name or service not known on python2.7

I am just starting to use and learn Python, so this may seem vary naive to ask.
On my Linux system if i try to get a webpage using urllib.urlopen() I get an error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/urllib.py", line 86, in urlopen
return opener.open(url)
File "/usr/lib/python2.7/urllib.py", line 207, in open
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 344, in open_http
h.endheaders(data)
File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 814, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 776, in send
self.connect()
File "/usr/lib/python2.7/httplib.py", line 757, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
IOError: [Errno socket error] [Errno -2] Name or service not known
>>>
If I try to do the same in the Python 2.7 installed in my Windows 7 system, it works fine.
Since i am a novice, its difficult for me to diagnose the problem. I tried to research it but still haven't got any answers.
So my questions are:
What is different in the windows system that urlopen() works there but not on Linux.
What needs to be done to ensure that urlopen() works on the Linux system. Its necessary for me that it works since the the program I am developing has some bash command calls and the program depends extensively on the proper working of urllib.

Resources