Import cufflinks : cannot import name 'plot' from 'plotly.plotly' - python-3.x

I tried to import cufflinks, with this code :
from textblob import TextBlob
from wordcloud import WordCloud, STOPWORDS
import chart_studio.plotly as py
import plotly.graph_objs as go
from plotly.offline import iplot
import cufflinks
cufflinks.go_offline()
cufflinks.set_config_file(world_readable=True, theme='pearl', offline=True)
but it returns an error like this:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-7-4cccab8ca8ac> in <module>
5 import plotly.graph_objs as go
6 from plotly.offline import iplot
----> 7 import cufflinks
8 cufflinks.go_offline()
9 cufflinks.set_config_file(world_readable=True, theme='pearl', offline=True)
~\Anaconda3\lib\site-packages\cufflinks\__init__.py in <module>
17
18 from .plotlytools import *
---> 19 from plotly.plotly import plot
20 from .colors import cnames, get_colorscale
21 from .utils import pp
ImportError: cannot import name 'plot' from 'plotly.plotly' (C:\Users\asus\Anaconda3\lib\site-packages\plotly\plotly\__init__.py)
At first, it was an error at import plotly.plotly as py code that said the plotly was deprecated, and recommend me to use chart_studio.plotly.
So, I change the code and it works, but the import cufflinks is still error. Can anyone help me?

This solution is from an opened issue from cufflinks source code page. Basically, your Jupyter Notebook is throwing an error because the source code hasn't been updated even after installing chart_studio.
To fix this problem, go to the directory that contains cufflinks source code. In your case it would be \Anaconda3\lib\site-packages\cufflinks. Within that directory, locate three files, namely: _init_.py, plotlytools.py, and tools.py. In each of the respective files, change "plotly.plotly" to "chart_studio.plotly" and save the file.
Try running the import again.
This post from plotly community might be helpful as well! Do note that this post actually redirects you to the original opened issue.
If you're familiar with Github PRs, these are the proposed commits (hasn't been merged yet though..)

Related

importing chart packages in jupyter lab notebook

I'm trying to generate a chart in online jupyter lab notebook and it is not allowing by throwing errors. Is it possible to do it there?
Thanks
[Updated the code and error]
import pandas as pd
import plotly.express as px
leads to the below error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[28], line 2
1 import pandas as pd
----> 2 import plotly.express as px
ModuleNotFoundError: No module named 'plotly'
If you want to use package in jupyter notebook,
you should
install package by this line
!pip install package-name
then add new block to write code
import it in code
import package-name
(for someone if finding this question)

ModuleNotFoundError: No module named 'plotly' but it work from workspace

i have read all the posts related to this topic but i could not find the solution for my case.
In my ubuntu 20.04 I have installed plotly through the command:
pip3 install plotly
and if i launch python3 from command line and if i run:
import plotly.graph_objects as go
it works perfectly. But if i launch the same command from python script "test.py":
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import cgi
import cgitb
from datetime import date, timedelta
import datetime
import time
import numpy as np
import pandas as pd
import os
import calendar
import matplotlib
matplotlib.use('Agg')
import matplotlib.pylab as plt
import plotly.graph_objects as go
it returns the error log:
ModuleNotFoundError: No module named 'plotly'
Anyone can help me? many thanks
Ok, i resolved the issue by installing the module as a root user because in this way Python will try to search for the module’s name in the root directory and not in the usr one
thank you everyone

Is there any way to make the libraries from python to work?

I have been struggling for several hours to import keras and tensorflow, but I am unable to import them.
import os
import random
import sys
# Package
import glob
import tensorflow as tf
import keras
import IPython.display as ipd
import librosa
import librosa.display
import matplotlib.pyplot as plt
import numpy as np
Also, when I try to import something, I am unable to do that. Could someone help me out ?
Thank you !
These are the errors I got:
Original exception was:
Traceback (most recent call last):
File "/home/vlad/speech_recognition/emotionrecognition.py", line 8, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'

Python module incompatibilities

I have just installed gdal into my Python3 root environment using conda:
conda install -c conda-forge gdal
Installation went fine with the usual updates of some dependencies. Now returning to some of my scripts, both netCDF4 and mpl_toolkits.basemap have stopped working. These are the errors I get:
from netCDF4 import Dataset
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-7-09694a7f0e01> in <module>()
----> 1 from netCDF4 import Dataset
2 import numpy as np
3 import matplotlib.pyplot as plt
4 from scipy.interpolate import griddata
5 from mpl_toolkits.basemap import Basemap
/anaconda3/lib/python3.6/site-packages/netCDF4/__init__.py in <module>()
1 # init for netCDF4. package
2 # Docstring comes from extension module _netCDF4.
----> 3 from ._netCDF4 import *
4 # Need explicit imports for names beginning with underscores
5 from ._netCDF4 import __doc__, __pdoc__
ImportError: dlopen(/anaconda3/lib/python3.6/site-packages/netCDF4/_netCDF4.cpython-36m-darwin.so, 2): Library not loaded: #rpath/libhdf5.101.dylib
Referenced from: /anaconda3/lib/python3.6/site-packages/netCDF4/_netCDF4.cpython-36m-darwin.so
Reason: image not found
from mpl_toolkits.basemap import Basemap
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-8-5fb601138328> in <module>()
3 import matplotlib.pyplot as plt
4 from scipy.interpolate import griddata
----> 5 from mpl_toolkits.basemap import Basemap
6 import numpy.ma as ma
7 import glob
/anaconda3/lib/python3.6/site-packages/mpl_toolkits/basemap/__init__.py in <module>()
35 import numpy as np
36 import numpy.ma as ma
---> 37 import _geoslib
38 import functools
39
ImportError: dlopen(/anaconda3/lib/python3.6/site-packages/_geoslib.so, 2): Library not loaded: #rpath/libgeos-3.5.0.dylib
Referenced from: /anaconda3/lib/python3.6/site-packages/_geoslib.so
Reason: image not found
I have no idea what these errors mean, since those paths do exist. What is most baffling is that the netCDF4 and mpl_toolkits modules did not change (i.e. were not updated/downgraded) with the installation of gdal, so why now are they failing?
I'm at the end of my tether with problems like this. Fortunately I made a copy of my Python root directory before attempting this installation so I can now revert back to it (I've been here many times before).
I know about working in separate conda environments, but am I seriously supposed to install a new environment every time I want to use a new Python module? This not only takes up a lot of harddrive space but most inconveniently means adding new functionality to old codes is impossible (I want to use GDAL to plot some geotiffs using Basemap, which now does not work!).
I cannot imagine proficient Python users battling with these issues - so what am I doing wrong?

TensorFlow Object Detection API - error = "This call to matplotlib.use() has no effect because the backend has already been[...]"

I'm trying to get the TensorFlow Object Detection API on Windows. I use Python 3.6.5 (64bits).
After running the following program:
Here is the part of the code which generates the warning:
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
import cv2
cap = cv2.VideoCapture("video.mp4")
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
I have this warning message :
Warning (from warnings module):
File "C:\Users\leahj\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\utils\visualization_utils.py", line 25
import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements
UserWarning:
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
Can anybody help me please ?
The line import matplotlib; matplotlib.use('Agg') is hardcoded in object_detection\utils\visualization_utils. I don't know the reason for this; usually a package should allow the user to choose the backend.
Unless there is any other problem arising from the use of object_detection the easiest is probably to live with this warning.

Resources