Kernel Error problem in Jupyter Notebook on PyCharm 2018 IDE - python

I am struggling with running Jupyter Notebook on PyCharm2018 Community Edition in Windows 10. I created a Virtual Environment with python version 3.6.6 and other necessary packages. I installed jupyter notebook (ipython-7.8.0v, jupyter-1.0.0v) as well following its documentation. As, I am using a specific python version for this application, I want to create a separate ipython kernel (version 5.1.2) for python 3 in a specific path and then add it to jupyter kernelspecs as follows:
ipython kernel install --prefix /tmp
jupyter kernelspec install /tmp/share/jupyter/kernels/python3
When I run an example ipython notebook after following these instructions, the notebook is returning Kernel Error problem stating Could not find a kernel matching Python 2 . I am unable to understand, why its resulting in this. There is no trace of python2 being used anywhere during my installation. I even created python3 kernels separately using above instructions and changed my notebook to kernel to that, but still the same Kernel Error. Virtual Environment I created for this application also uses python3.6 exec file from my Anaconda Installation.
I have looked around similar questions on this problem, but none of them could help me solve this so far. The back trace of this error is as follows.
Traceback (most recent call last):
File "D:\Anaconda3\envs\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "D:\Anaconda3\envs\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\***\pycharm_workspace\trail\venv\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "D:\***\pycharm_workspace\trail\venv\lib\site-packages\traitlets\config\application.py", line 663, in launch_instance
app.initialize(argv)
File "<D:\***\pycharm_workspace\trail\venv\lib\site-packages\decorator.py:decorator-gen-125>", line 2, in initialize
File "D:\***\pycharm_workspace\trail\venv\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "D:\***\pycharm_workspace\trail\venv\lib\site-packages\ipykernel\kernelapp.py", line 472, in initialize
self.write_connection_file()
File "D:\***\pycharm_workspace\trail\venv\lib\site-packages\ipykernel\kernelapp.py", line 199, in write_connection_file
iopub_port=self.iopub_port, control_port=self.control_port)
File "D:\***\pycharm_workspace\trail\venv\lib\site-packages\jupyter_client\connect.py", line 141, in write_connection_file
with secure_write(fname) as f:
File "D:\Anaconda3\envs\python36\lib\contextlib.py", line 81, in __enter__
return next(self.gen)
File "D:\**\pycharm_workspace\trail\venv\lib\site-packages\jupyter_core\paths.py", line 404, in secure_write
win32_restrict_file_to_user(fname)
File "D:\**\pycharm_workspace\trail\venv\lib\site-packages\jupyter_core\paths.py", line 359, in win32_restrict_file_to_user
import win32api
**ImportError: DLL load failed: The specified procedure could not be found.**
Thanks in advance for the help.

Related

Python Beeware Briefcase Git SHA issue

I'm trying to teach myself to use the beeware briefcase package for Python, although having issues setting it up. I've got pyenv installed, and my local python version in the root of my project is set to 3.8.9. I'm using windows and Powershell
In PowerShell, I've created the python virtual environment, and have installed briefcase via pip.
I've installed git as well, and linked the repo to github.
When I try to run "briefcase new", and go through the prompts, I receive the following traceback (for both powershell and gitbash):
(I've removed my root details in below errors)
Traceback (most recent call last):
File "C:\~\.pyenv\pyenv-win\versions\3.8.9\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\~\.pyenv\pyenv-win\versions\3.8.9\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\~\CodeProjects\beeware-tutorial\.venv\Scripts\briefcase.exe\__main__.py", line 7, in <module>
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\briefcase\__main__.py", line 14, in main
command(**options)
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\briefcase\commands\new.py", line 537, in __call__
return self.new_app(template=template, **options)
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\briefcase\commands\new.py", line 488, in new_app
cached_template = self.update_cookiecutter_cache(
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\briefcase\commands\base.py", line 569, in update_cookiecutter_cache
f"Using existing template (sha {head.commit.hexsha}, "
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\refs\symbolic.py", line 217, in _get_commit
obj = self._get_object()
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\refs\symbolic.py", line 210, in _get_object
return Object.new_from_sha(self.repo, hex_to_bin(self.dereference_recursive(self.repo, self.path)))
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\objects\base.py", line 85, in new_from_sha
oinfo = repo.odb.info(sha1)
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\db.py", line 43, in info
hexsha, typename, size = self._git.get_object_header(bin_to_hex(binsha))
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\cmd.py", line 1253, in get_object_header
return self.__get_object_header(cmd, ref)
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\cmd.py", line 1240, in __get_object_header
return self._parse_object_header(cmd.stdout.readline())
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\cmd.py", line 1198, in _parse_object_header
raise ValueError("SHA could not be resolved, git returned: %r" % (header_line.strip()))
ValueError: SHA could not be resolved, git returned: b''
Not sure how I managed to fix the issue but I uninstalled git version 2.37.1 and installed git version 2.30.2, used GitBash to create a new environment, and installed a briefcase.
Seems to have solved the issue.

Is it possible to run jupyter from nside a virtual env

For now I was only using python 2.7 (installed for all users, added to path, windows 10 machine) but I want to switch to 3.8, to be able to use both of them I first installed virtualenv in my system python 2.7.
Then installed python 3.8.1 for all user without adding it to path.
Created my virtualenv like that : virtualenv c:\virtualEnvs\p38x64_jupytertest -p C:\Python38-32\python.exe
then activated it : C:\virtualEnvs\p38x64_jupytertest\Scripts\activate.bat
checked if python 3.8.1 was selected with : python --version (it was)
then installed jupyter inside my virtualenv : pip install jupyter
Then when I ran jupyter notebook I got
Traceback (most recent call last):
File "C:\Python38-32\Lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Python38-32\Lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\virtualEnvs\p38x64_jupytertest3\Scripts\jupyter-notebook.EXE\__main__.py", line 7, in <module>
File "c:\virtualenvs\p38x64_jupytertest3\lib\site-packages\jupyter_core\application.py", line 268, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "c:\virtualenvs\p38x64_jupytertest3\lib\site-packages\traitlets\config\application.py", line 663, in launch_instance
app.initialize(argv)
File "<c:\virtualenvs\p38x64_jupytertest3\lib\site-packages\decorator.py:decorator-gen-7>", line 2, in initialize
File "c:\virtualenvs\p38x64_jupytertest3\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "c:\virtualenvs\p38x64_jupytertest3\lib\site-packages\notebook\notebookapp.py", line 1720, in initialize
self.init_webapp()
File "c:\virtualenvs\p38x64_jupytertest3\lib\site-packages\notebook\notebookapp.py", line 1482, in init_webapp
self.http_server.listen(port, self.ip)
File "c:\virtualenvs\p38x64_jupytertest3\lib\site-packages\tornado\tcpserver.py", line 152, in listen
self.add_sockets(sockets)
File "c:\virtualenvs\p38x64_jupytertest3\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
self._handlers[sock.fileno()] = add_accept_handler(
File "c:\virtualenvs\p38x64_jupytertest3\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler
io_loop.add_handler(sock, accept_handler, IOLoop.READ)
File "c:\virtualenvs\p38x64_jupytertest3\lib\site-packages\tornado\platform\asyncio.py", line 99, in add_handler
self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
File "C:\Python38-32\Lib\asyncio\events.py", line 501, in add_reader
raise NotImplementedError
NotImplementedError
After some googling I find a lot of tutorial that explain how to install jupyter in you system python then add virtualenvs to it, but not how to install it INSIDE a virtual env.
The reason I did that is because I want my python 3 project to be isolated since I have a lot of python 2.7 projects (up until now I was not using virtualenv and every package is installed in my system python 2.)
Any idea of why I have this exception?
Thanks.
PS : yes it says p38x64_jupytertest3 in the stacktrace because the venv is not p38x64_jupytertest but p38x64_jupytertest3 in fact
know issue : https://github.com/jupyter/notebook/issues/4613
Reverting to python 3.7 for the moment

Jupyter notebooks: Tornado pointing to incorrect path

I'm trying to run a Jupyter notebook. I installed Anaconda 5.3 with the Python 3.7 version. The notebook starts up, but the Kernel fails to run because it's pointing to another version of Tornado that I've installed for some of my ROS projects (output below). How do I ensure the Jupyter kernel is using Tornado installed in the Anaconda path?
[I 10:56:54.649 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
Traceback (most recent call last):
File "/dir/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/dir/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/dir/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "/dir/anaconda3/lib/python3.7/site-packages/traitlets/config/application.py", line 657, in launch_instance
app.initialize(argv)
File "<decorator-gen-123>", line 2, in initialize
File "/dir/anaconda3/lib/python3.7/site-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/dir/anaconda3/lib/python3.7/site-packages/ipykernel/kernelapp.py", line 467, in initialize
self.init_sockets()
File "/dir/anaconda3/lib/python3.7/site-packages/ipykernel/kernelapp.py", line 260, in init_sockets
self.init_iopub(context)
File "/dir/anaconda3/lib/python3.7/site-packages/ipykernel/kernelapp.py", line 268, in init_iopub
self.iopub_thread = IOPubThread(self.iopub_socket, pipe=True)
File "/dir/anaconda3/lib/python3.7/site-packages/ipykernel/iostream.py", line 66, in __init__
self.io_loop = IOLoop(make_current=False)
File "/dir/ros_projects/forked/rosbridge_suite/rosbridge_server/src/tornado/util.py", line 208, in __new__
instance.initialize(**args)
File "/dir/ros_projects/forked/rosbridge_suite/rosbridge_server/src/tornado/platform/epoll.py", line 26, in initialize
super(EPollIOLoop, self).initialize(impl=select.epoll(), **kwargs)
TypeError: initialize() got an unexpected keyword argument 'make_current'
[W 10:56:57.665 NotebookApp] KernelRestarter: restart failed
[W 10:56:57.666 NotebookApp] Kernel 2dd183ff-850d-4f79-945c-c8f56f1e695e died, removing from map.
A little late, but answering my own question. PYTHONPATH was set for a bunch of other projects. Since conda doesn't set PYTHONPATH, running
unset PYTHONPATH
did the trick.

Canopy is having difficulties updating packages, "AbortedOperationDetected"

I run Canopy version Version: 2.1.3.3542 (64 bit) on Windows 10.
Canopy cant manage to update any package, all results in the same
log output for a numpy update (for example):
Warming up...
Traceback (most recent call last):
File "build\bdist.win-amd64\egg\canopy_dashboard\packman\package_action_worker.py", line 54, in run
File "build\bdist.win-amd64\egg\canopy_dashboard\packman\package_action.py", line 196, in execute
File "build\bdist.win-amd64\egg\canopy_dashboard\packman\packman.py", line 626, in <lambda>
File "build\bdist.win-amd64\egg\canopy_dashboard\packman\packman.py", line 1051, in _install
File "build\bdist.win-amd64\egg\canopy_platform\cpython_packages_manager.py", line 152, in install_packages_prompt
File "build\bdist.win-amd64\egg\canopy_platform\cpython_packages_manager.py", line 137, in _install_packages_prompt
PackagesInstallationError: installation of packages ['numpy 1.11.3-3'] failed. Details below:
Traceback (most recent call last):
File "build\bdist.win-amd64\egg\canopy_platform\edm_api.py", line 64, in wrapper
File "build\bdist.win-amd64\egg\canopy_platform\edm_api.py", line 384, in install_command
File "build\bdist.win-amd64\egg\canopy_platform\edm_api.py", line 414, in _install_packages_command
File "build\bdist.win-amd64\egg\edm\core\packages_manager.py", line 124, in decorator
File "build\bdist.win-amd64\egg\edm\core\packages_manager.py", line 219, in install_command
File "build\bdist.win-amd64\egg\edm\core\packages_manager.py", line 223, in _install_command
File "build\bdist.win-amd64\egg\edm\core\packages_manager.py", line 549, in _compute_fix_aborted_actions
AbortedOperationDetected: Aborted operation detected in environment 'User'
There is absolutly 0 results on google for this error code, so stackexchange is my last resort
It looks like a previous update was force-aborted, possibly leaving the environment corrupted. Assuming that you are using the standard installer, then it should suffice to
reboot your computer
temporarily disable your anti-virus software if possible (or at least disable its more intrusive / slow functionality, such as online checking each of the tens of thousands of package files that Canopy provides),
from the Canopy Tools menu, select Troubleshoot => Reset Python environment

Issues in running ipython notebook on Windows Xp

I have a 32 bit WinXP system that used to run ipython notebook just fine under the Miniconda distribution (Python 3.4). But recently, when I start the ipython notebook interface in the browser I get a kernel error. The console shows a ZMQError. However, I have no issue working from the ipython console or even from inside PyCharm IDE, where python works fine. I am using a virtual environment, and the details about the error are given below:
Traceback (most recent call last):
File "F:\Miniconda3\envs\mltestbed\lib\site-packages\notebook\base\handlers.py", line 436, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File "F:\Miniconda3\envs\mltestbed\lib\site-packages\notebook\services\sessions\handlers.py", line 56, in post
model = sm.create_session(path=path, kernel_name=kernel_name)
File "F:\Miniconda3\envs\mltestbed\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 66, in create_session
kernel_name=kernel_name)
File "F:\Miniconda3\envs\mltestbed\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 84, in start_kernel
**kwargs)
File "F:\Miniconda3\envs\mltestbed\lib\site-packages\jupyter_client\multikernelmanager.py", line 109, in start_kernel
km.start_kernel(**kwargs)
File "F:\Miniconda3\envs\mltestbed\lib\site-packages\jupyter_client\manager.py", line 241, in start_kernel
self._connect_control_socket()
File "F:\Miniconda3\envs\mltestbed\lib\site-packages\jupyter_client\manager.py", line 192, in _connect_control_socket
self._control_socket = self.connect_control()
File "F:\Miniconda3\envs\mltestbed\lib\site-packages\jupyter_client\connect.py", line 445, in connect_control
return self._create_connected_socket('control', identity=identity)
File "F:\Miniconda3\envs\mltestbed\lib\site-packages\jupyter_client\connect.py", line 417, in _create_connected_socket
sock = self.context.socket(socket_type)
File "F:\Miniconda3\envs\mltestbed\lib\site-packages\zmq\sugar\context.py", line 143, in socket
s = self._socket_class(self, socket_type)
File "zmq/backend/cython/socket.pyx", line 281, in zmq.backend.cython.socket.Socket.__cinit__ (zmq\backend\cython\socket.c:3220)
zmq.error.ZMQError: Connection refused
In need of help as my system contains a lot of code that would be difficult to port.
I am not sure if this helps you, but there seems to be a similar error experienced by some spyder users. This goes back to a problem in binding to a random port for the notebook server using ZeroMQ (see here). The bug in question seems to be fixed in ZeroMQ, but I am not sure if it has made it's way to the other packages you are using.
You could try to update the version of ipython-notebook you are using:
$ conda update ipython-notebook
and if this doesn't work you could fall back to an older version. Try creating a new environment with an older version to keep your (hopefully soon repaired) environment intact:
$ conda create -n fallback ipython-notebook=3 python=3.4
I hope this helps.

Categories

Resources