Jupyter Notebook: ImportError: cannot import name 'default' - ipython

When trying to start Jupyter with the command Jupyter Notebook, I am getting this below error:
File "/anaconda/bin/jupyter-notebook", line 4, in <module>
import notebook.notebookapp
File "/anaconda/lib/python3.6/site-packages/notebook/notebookapp.py",
line 63, in <module>
from .services.contents.manager import ContentsManager
File "/anaconda/lib/python3.6/site-
packages/notebook/services/contents/manager.py", line 16, in <module>
from nbformat import sign, validate, ValidationError
File "/anaconda/lib/python3.6/site-packages/nbformat/sign.py", line 24,
in <module>
from traitlets import (
ImportError: cannot import name 'default'
Any idea what is missing?

I use:
pip3 install --user --upgrade traitlets
Works fine for me.

I uninstalled traitlets package and reinstalled it. The problem went away. Not sure how it broke in the first place.

Related

I'm getting an error importerror /lib/arm-linux-gnueabihf/libm.so.6 version glibc_2.29' not found what should I do?

While I run my python code in raspberry pi 3b+ I'm getting:
importerror /lib/arm-linux-gnueabihf/libm.so.6 version glibc_2.29' not
found
error what should I do?
#beginner
pi#raspberrypi:~/Desktop/Mirror-Interface-Auth/RaspberryPi-Module $ python3 main.py
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/firestore.py", line 22, in <module>
from google.cloud import firestore # pylint: disable=import-error,no-name-in-module
File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/firestore/__init__.py", line 18, in <module>
from google.cloud.firestore_v1 import __version__
File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/firestore_v1/__init__.py", line 30, in <module>
from google.cloud.firestore_v1._helpers import GeoPoint
File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/firestore_v1/_helpers.py", line 22, in <module>
from google.api_core import gapic_v1
File "/home/pi/.local/lib/python3.7/site-packages/google/api_core/gapic_v1/__init__.py", line 16, in <module>
from google.api_core.gapic_v1 import config
File "/home/pi/.local/lib/python3.7/site-packages/google/api_
From this thread, it seems an older version must be installed to work.
sudo pip3 uninstall grpcio
sudo pip3 uninstall grpcio-status
Then
sudo pip3 install grpcio==1.44.0
sudo pip3 install grpcio-tools==1.44.0
After doing this my Raspberry Pi Zero W 2 does not fail upon importing the packages.

vtkCommonCorePython missing error in python3-paraview on Ubuntu 20

I'm trying to use paraview scripting within python3 for Ubuntu 20.04.1 LTS. If I open python3 on the command line I get the error
$> python3
Python 3.8.2 (default, Jul 16 2020, 14:00:26)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from paraview.simple import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/paraview/simple.py", line 41, in <module>
from paraview import servermanager
File "/usr/lib/python3/dist-packages/paraview/servermanager.py", line 56, in <module>
from paraview.modules.vtkPVServerImplementationCore import *
File "/usr/lib/python3/dist-packages/paraview/modules/vtkPVServerImplementationCore.py", line 2, in <module>
from . import vtkPVClientServerCoreCore
File "/usr/lib/python3/dist-packages/paraview/modules/vtkPVClientServerCoreCore.py", line 2, in <module>
from . import vtkPVCore
File "/usr/lib/python3/dist-packages/paraview/modules/vtkPVCore.py", line 2, in <module>
from . import vtkClientServer
File "/usr/lib/python3/dist-packages/paraview/modules/vtkClientServer.py", line 3, in <module>
from .vtkClientServerPython import *
ImportError: Failed to load vtkClientServerPython: No module named vtkmodules.vtkCommonCorePython
>>>
I have python3-paraview, paraview, paraview-dev, vtk7, python3-vtk7, etc installed from the synaptic installation manager. There are two files with vtkCommonCorePython inside the dist-packages directory :
/usr/lib/python3/dist-packages/vtk/vtkCommonCorePython.cpython-38-x86_64-linux-gnu.so
/usr/lib/python3/dist-packages/vtkmodules/vtkCommonCorePython.cpython-38-x86_64-linux-gnu.so
Searching the internet shows that other people have had similar problems, and solved it but including the paths to vtkCommonCorePython, but sys.path does include /usr/lib/python3/dist-packages, so vtkCommonCorePython should be found.
Can anybody see what might be missing in this case?
Many thanks! John
There are (or at least there were in previous versions) some slightly tricky conflicts between the vtk and paraview packages in python. I've found it's best to keep paraview for python in its own conda environment.
Assuming you have conda already, you should be able to get up and running with:
conda create -n paraview -c conda-forge paraview

conda pyqt import failed in a new virtual environment

I tried to run programs using pyqt.
It worked if I didn't use a virtual environment but if I activated a virtual environment, it would fail: ImportError: DLL load failed...
Traceback (most recent call last):
File "submitA2.py", line 14, in <module>
import matplotlib.pyplot as plt
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\pyplot.py", line 116, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\backends\__init__.py", line 60, in pylab_setup
[backend_name], 0)
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 16, in <module>
from .backend_qt5 import (
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\backends\backend_qt5.py", line 18, in <module>
import matplotlib.backends.qt_editor.figureoptions as figureoptions
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\backends\qt_editor\figureoptions.py", line 20, in <module>
import matplotlib.backends.qt_editor.formlayout as formlayout
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\backends\qt_editor\formlayout.py", line 56, in <module>
from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
File "C:\Users\jerem\Anaconda3\envs\deep\lib\site-packages\matplotlib\backends\qt_compat.py", line 137, in <module>
from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: DLL load failed: The specified procedure could not be found.
I can't install another pyqt package in this virtual environment because it tells me:
# All requested packages already installed.
# packages in environment at C:\Users\jerem\Anaconda3\envs\deep:
#
pyqt 5.6.0 py36_4 conda-forge
How to fix this?? Thanks.
A not perfect solution: installing a different version of PyQt5 seems to get around this issue.
activate myenv
conda install pyqt=5.9
Jeremy Chen's solution is the only solution that worked for me. i.e
conda install pyqt=5.9 within your conda environment
All other solutinos listed on internet did not work.
But this installation of pytqt=5.9 breaks matplotlib module with the following error when trying
import matplotlib
ImportError: cannot import name 'get_backend'
This was solved by using
conda uninstall matplotlib
and then reinstalling
conda install matplotlib

Spyder fails on Anaconda 2-4.3.21/2-4.4.0 - ImportError: No module named > shutil_get_terminal_size

From the Anaconda command prompt I launch Spyder. Spyder launches, even loading and issuing a warning that my previous session crashed and that I should consider resetting (which I eventually did without result). The process carries on and then hangs on forever, failing to start (i.e. open the working windows with code, console, variables etc.)
Tried to reset Spyder
Spyder --reset
Spyder resets properly but still fails to start
Spyder Version: 3.1.4
Python Version: 2.7.13
Anaconda Version: 4.3.21
Qt Version: 5.6.2
PyQt Version: 5.6.0
Operating system: Windows 10
Then I uninstalled and reinstalled Anaconda this time Version: 2.4.4.0. Spyder launched once satisfactorily only to crash ever after.
Investigating the process further, it cought up the following error:
spyder --show-console
(C:\Users\me\Anaconda2) C:\Users\me>spyder --show-console Traceback
(most recent call last): File
"C:\Users\me\Anaconda2\lib\site-packages\spyder\app\mainwindow.py",
line 3011, in main mainwindow = run_spyder(app, options, args) File
"C:\Users\me\Anaconda2\lib\site-packages\spyder\app\mainwindow.py",
line 2913, in run_spyder main.setup() File
"C:\Users\me\Anaconda2\lib\site-packages\spyder\app\mainwindow.py",
line 873, in setup from spyder.plugins.ipythonconsole import
IPythonConsole File
"C:\Users\me\Anaconda2\lib\site-packages\spyder\plugins\ipythonconsole.py",
line 60, in from spyder.widgets.ipythonconsole import ClientWidget
File
"C:\Users\me\Anaconda2\lib\site-packages\spyder\widgets\ipythonconsole_init_.py",
line 12, in from .debugging import DebuggingWidget File
"C:\Users\me\Anaconda2\lib\site-packages\spyder\widgets\ipythonconsole\debugging.py",
line 16, in from qtconsole.rich_jupyter_widget import
RichJupyterWidget File
"C:\Users\me\Anaconda2\lib\site-packages\qtconsole\rich_jupyter_widget.py",
line 14, in from .jupyter_widget import JupyterWidget File
"C:\Users\me\Anaconda2\lib\site-packages\qtconsole\jupyter_widget.py",
line 19, in from IPython.lib.lexers import IPythonLexer,
IPython3Lexer File
"C:\Users\me\Anaconda2\lib\site-packages\IPython_init_.py", line 48,
in from .core.application import Application File
"C:\Users\me\Anaconda2\lib\site-packages\IPython\core\application.py",
line 25, in from IPython.core import release, crashhandler File
"C:\Users\me\Anaconda2\lib\site-packages\IPython\core\crashhandler.py",
line 28, in from IPython.core import ultratb File
"C:\Users\me\Anaconda2\lib\site-packages\IPython\core\ultratb.py",
line 128, in from IPython.utils.terminal import get_terminal_size
File
"C:\Users\me\Anaconda2\lib\site-packages\IPython\utils\terminal.py",
line 22, in from backports.shutil_get_terminal_size import
get_terminal_size as _get_terminal_size ImportError: No module named
shutil_get_terminal_size
(C:\Users\me\Anaconda2) C:\Users\me>
So then I tried the following:
(C:\Users\me\Anaconda2) C:\Users\me>conda install
shutil_get_terminal_size Fetching package metadata ...........
PackageNotFoundError: Package missing in current win-64 channels:
shutil_get_terminal_size Close matches found; did you mean one of
these?
shutil_get_terminal_size: get_terminal_size
Btw Spyder issue or Anaconda issue?
So anway I proceeded to install get_terminal_size and have a go at it
(C:\Users\me\Anaconda2) C:\Users\me>conda install get_terminal_size
Fetching package metadata ........... Solving package specifications:
.
All requested packages already installed.
packages in environment at C:\Users\me\Anaconda2:
get_terminal_size 1.0.0 py27_0
Then tries again to launch in the command prompt
spyder
which fails including trying once again after resetting
spyder --reset
Investigating further
spyder --show-console
results in me returning straight back to square one
(C:\Users\me\Anaconda2) C:\Users\me>spyder --show console Traceback
(most recent call last): File
"C:\Users\me\Anaconda2\lib\site-packages\spyder\app\mainwindow.py",
line 3011, in main mainwindow = run_spyder(app, options, args) File
"C:\Users\me\Anaconda2\lib\site-packages\spyder\app\mainwindow.py",
line 2913, in run_spyder main.setup() File
"C:\Users\me\Anaconda2\lib\site-packages\spyder\app\mainwindow.py",
line 873, in setup from spyder.plugins.ipythonconsole import
IPythonConsole File
"C:\Users\me\Anaconda2\lib\site-packages\spyder\plugins\ipythonconsole.py",
line 60, in from spyder.widgets.ipythonconsole import ClientWidget
File
"C:\Users\me\Anaconda2\lib\site-packages\spyder\widgets\ipythonconsole_init_.py",
line 12, in from .debugging import DebuggingWidget File
"C:\Users\me\Anaconda2\lib\site-packages\spyder\widgets\ipythonconsole\debugging.py",
line 16, in from qtconsole.rich_jupyter_widget import
RichJupyterWidget File
"C:\Users\me\Anaconda2\lib\site-packages\qtconsole\rich_jupyter_widget.py",
line 14, in from .jupyter_widget import JupyterWidget File
"C:\Users\me\Anaconda2\lib\site-packages\qtconsole\jupyter_widget.py",
line 19, in from IPython.lib.lexers import IPythonLexer,
IPython3Lexer File
"C:\Users\me\Anaconda2\lib\site-packages\IPython_init_.py", line 48,
in from .core.application import Application File
"C:\Users\me\Anaconda2\lib\site-packages\IPython\core\application.py",
line 25, in from IPython.core import release, crashhandler File
"C:\Users\me\Anaconda2\lib\site-packages\IPython\core\crashhandler.py",
line 28, in from IPython.core import ultratb File
"C:\Users\me\Anaconda2\lib\site-packages\IPython\core\ultratb.py",
line 128, in from IPython.utils.terminal import get_terminal_size
File
"C:\Users\me\Anaconda2\lib\site-packages\IPython\utils\terminal.py",
line 22, in from backports.shutil_get_terminal_size import
get_terminal_size as _get_terminal_size ImportError: No module named
shutil_get_terminal_size
PS: I have used with satisfaction Anaconda and Spyder for months now without any issue, cannot understand what's wrong.
Actually I found a solution which was to conda reinstall ipython and pip reinstall backports.shutil_get_terminal_size :
conda uninstall ipython
conda install python
pip uninstall backports.shutil_get_terminal_size
pip install backports.shutil_get_terminal_size
For more info I suggest to consult the following issues:
ipython/ipython/#9656
ipython/ipython/#9815 (I cannot post more than 2 links so google it up!)
chrippa/backports.shutil_get_terminal_size/#9
For some reason however Spyder then issues a warning that nbconvert isn't installed whereas both conda and pip install nbconvert show that nbconvert is fully installed and up to date...
Spyder dependancy missing nbconvert >=4.0: None (NOK) Please install
to prevent this message displaying Fetching package metadata
........... Solving package specifications: .
conda install nbconvert
All requested packages already installed. packages in environment at
C:\Users\me\Anaconda2:
nbconvert 5.2.1 py27_0
pip install nbconvert
Requirement already satisfied: nbconvert in c:\users\me\anaconda2\lib\site-packages Requirement already satisfied: mistune!=0.6 in c:\users\me\anaconda2\lib\site-packages (from nbconvert)
Requirement already satisfied: jinja2 in c:\users\me\anaconda2\lib\site-packages (from nbconvert)
Requirement already satisfied: pygments in c:\users\me\anaconda2\lib\site-packages (from nbconvert)
Requirement already satisfied: traitlets>=4.2 in c:\users\me\anaconda2\lib\site-packages (from nbconvert)
Requirement already satisfied: jupyter_core in c:\users\me\anaconda2\lib\site-packages (from nbconvert)
Requirement already satisfied: nbformat in c:\users\me\anaconda2\lib\site-packages (from nbconvert)
Requirement already satisfied: entrypoints>=0.2.2 in c:\users\me\anaconda2\lib\site-packages (from nbconvert)
Requirement already satisfied: bleach in c:\users\me\anaconda2\lib\site-packages (from nbconvert)
Requirement already satisfied: pandocfilters>=1.4.1 in c:\users\me\anaconda2\lib\site-packages (from nbconvert)
Requirement already satisfied: testpath in c:\users\me\anaconda2\lib\site-packages (from nbconvert)
Requirement already satisfied: MarkupSafe>=0.23 in c:\users\me\anaconda2\lib\site-packages (from jinja2->nbconvert)
Requirement already satisfied: six in c:\users\me\anaconda2\lib\site-packages (from bleach->nbconvert)
Requirement already satisfied: html5lib!=0.9999,!=0.99999,<0.99999999,>=0.999 in c:\users\me\anaconda2\lib\site-packages (from bleach->nbconvert)

ImportError: No module named shutil_get_terminal_size IPython

I am having this error with my IPython version on Redhat.
$ ipython --version
Traceback (most recent call last):
File "/usr/bin/ipython", line 7, in <module>
from IPython import start_ipython
File "/usr/lib/python2.7/site-packages/IPython/__init__.py", line 48, in module
from .core.application import Application
File "/usr/lib/python2.7/site-packages/IPython/core/application.py", line 24, in <module>
from IPython.core import release, crashhandler
File "/usr/lib/python2.7/site-packages/IPython/core/crashhandler.py", line 28, in module
from IPython.core import ultratb
File "/usr/lib/python2.7/site-packages/IPython/core/ultratb.py", line 121, in module
from IPython.utils.terminal import get_terminal_size
File "/usr/lib/python2.7/site-packages/IPython/utils/terminal.py", line 27, in module
import backports.shutil_get_terminal_size
**ImportError: No module named shutil_get_terminal_size**
Could you please help me to resolve it?
According to this question, try:
conda config --add channels conda-forge
conda install backports.shutil_get_terminal_size
I got the same question as yours. I solve it by using pip install -U ipython to update IPython and it workes. Hope it helps!
If you don't want to use conda, try below.
pip install https://github.com/chrippa/backports.shutil_get_terminal_size/archive/159e269450dbf37c3a837f6ea7e628d59acbb96a.zip
None of the uninstalling/reinstalling stuff worked for me. What eventually worked for me was suggested by #ternus in a comment above: open up (on linux) /usr/local/lib/python2.7/dist-packages/IPython/utils/terminal.py and change the line
from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size
to
from shutil_backports import get_terminal_size as _get_terminal_size
Reference: https://github.com/ipython/ipython/issues/9656
Author: https://github.com/ihincks
I follow this post
IPython console can't locate "backports.shutil_get_terminal_size" and won't load
to change /usr/lib/python2.7/site-packages/IPython/utils/terminal.py and it works for me
For me this worked (on Debian):
apt-get install python-ipython