Plotly is not working module 'tenacity' has no attribute 'retry' - python-3.x

I am trying to produce a simple scatter plot using Plotly
And all the time I am getting this error:
module 'tenacity' has no attribute 'retry'
I searched for solutions but nothing worked.
In particular, I have tried the following:
Uninstall and install again plotly
Upgrade pip and then upgrade plotly
install tenacity into my environment
Can someone help?
Here is the python script I am using:
import plotly.express as px
fig = px.scatter(df_performance, x="ytd", y="cagr",
size ='Market Cap', template='plotly_dark',
color_continuous_scale=px.colors.sequential.Viridis, title = 'S&P 500 Companies Perfomance the Last 4 months')
fig.show()
where df_performance is just a pandas dataframe with three columns (ytd,cagr, Market Cap)
My python version is: 3.8.12
Update: Here is the full trace
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/var/folders/7g/gr9fl0cx43g5f42xf78n_str0000gn/T/ipykernel_28716/3796243394.py in <module>
2 size ='Market Cap', template='plotly_dark',
3 color_continuous_scale=px.colors.sequential.Viridis, title = 'S&P 500 Companies Perfomance the Last 4 months')
----> 4 fig.show()
~/opt/anaconda3/envs/Spyder_env/lib/python3.8/site-packages/plotly/basedatatypes.py in show(self, *args, **kwargs)
3396 import plotly.io as pio
3397
-> 3398 return pio.show(self, *args, **kwargs)
3399
3400 def to_json(self, *args, **kwargs):
~/opt/anaconda3/envs/Spyder_env/lib/python3.8/site-packages/_plotly_utils/importers.py in __getattr__(import_name)
34 rel_module = ".".join(rel_path_parts[:-1])
35 class_name = import_name
---> 36 class_module = importlib.import_module(rel_module, parent_name)
37 return getattr(class_module, class_name)
38
~/opt/anaconda3/envs/Spyder_env/lib/python3.8/importlib/__init__.py in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
129
~/opt/anaconda3/envs/Spyder_env/lib/python3.8/importlib/_bootstrap.py in _gcd_import(name, package, level)
~/opt/anaconda3/envs/Spyder_env/lib/python3.8/importlib/_bootstrap.py in _find_and_load(name, import_)
~/opt/anaconda3/envs/Spyder_env/lib/python3.8/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)
~/opt/anaconda3/envs/Spyder_env/lib/python3.8/importlib/_bootstrap.py in _load_unlocked(spec)
~/opt/anaconda3/envs/Spyder_env/lib/python3.8/importlib/_bootstrap_external.py in exec_module(self, module)
~/opt/anaconda3/envs/Spyder_env/lib/python3.8/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)
~/opt/anaconda3/envs/Spyder_env/lib/python3.8/site-packages/plotly/io/_renderers.py in <module>
10 from plotly import optional_imports
11
---> 12 from plotly.io._base_renderers import (
13 MimetypeRenderer,
14 ExternalRenderer,
~/opt/anaconda3/envs/Spyder_env/lib/python3.8/site-packages/plotly/io/_base_renderers.py in <module>
10 from plotly import utils, optional_imports
11 from plotly.io import to_json, to_image, write_image, write_html
---> 12 from plotly.io._orca import ensure_server
13 from plotly.io._utils import plotly_cdn_url
14 from plotly.offline.offline import _get_jconfig, get_plotlyjs
~/opt/anaconda3/envs/Spyder_env/lib/python3.8/site-packages/plotly/io/_orca.py in <module>
1453
1454
-> 1455 #tenacity.retry(
1456 wait=tenacity.wait_random(min=5, max=10), stop=tenacity.stop_after_delay(60000),
1457 )
AttributeError: module 'tenacity' has no attribute 'retry'

you have described the data so synthesized it
used exactly your code, runs without issues. plotly 5.5.0
import plotly.express as px
import pandas as pd
import numpy as np
df_performance = pd.DataFrame(
{
"ytd": pd.date_range("1-jan-2021", freq="B", periods=100),
"cagr": np.linspace(2, 5, 100) * np.random.uniform(.7,1,100),
"Market Cap": np.linspace(5,20, 100) * np.random.uniform(.7,1,100),
}
)
fig = px.scatter(
df_performance,
x="ytd",
y="cagr",
size="Market Cap",
template="plotly_dark",
color_continuous_scale=px.colors.sequential.Viridis,
title="S&P 500 Companies Perfomance the Last 4 months",
)
fig

Related

Error importing LayoutLMv2ForTokenClassification from HuggingFace

I am trying to run this demo notebook on colab and I am getting the following pytorch error when importing LayoutLMv2ForTokenClassification:
from transformers import LayoutLMv2ForTokenClassification
Error:
ModuleNotFoundError Traceback (most recent call last)
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\transformers\utils\import_utils.py in _get_module(self, module_name)
1029 try:
-> 1030 return importlib.import_module("." + module_name, self.__name__)
1031 except Exception as e:
~\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py in import_module(name, package)
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
~\AppData\Local\Programs\Python\Python39\lib\importlib\_bootstrap.py in _gcd_import(name, package, level)
~\AppData\Local\Programs\Python\Python39\lib\importlib\_bootstrap.py in _find_and_load(name, import_)
~\AppData\Local\Programs\Python\Python39\lib\importlib\_bootstrap.py in _find_and_load_unlocked(name, import_)
~\AppData\Local\Programs\Python\Python39\lib\importlib\_bootstrap.py in _load_unlocked(spec)
~\AppData\Local\Programs\Python\Python39\lib\importlib\_bootstrap_external.py in exec_module(self, module)
~\AppData\Local\Programs\Python\Python39\lib\importlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\transformers\models\layoutlmv2\modeling_layoutlmv2.py in <module>
48 import detectron2
---> 49 from detectron2.modeling import META_ARCH_REGISTRY
50
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\detectron2\modeling\__init__.py in <module>
19 )
---> 20 from .meta_arch import (
21 META_ARCH_REGISTRY,
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\detectron2\modeling\meta_arch\__init__.py in <module>
5
----> 6 from .panoptic_fpn import PanopticFPN
7
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\detectron2\modeling\meta_arch\panoptic_fpn.py in <module>
13 from .build import META_ARCH_REGISTRY
---> 14 from .rcnn import GeneralizedRCNN
15 from .semantic_seg import build_sem_seg_head
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\detectron2\modeling\meta_arch\rcnn.py in <module>
17 from ..proposal_generator import build_proposal_generator
---> 18 from ..roi_heads import build_roi_heads
19 from .build import META_ARCH_REGISTRY
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\detectron2\modeling\roi_heads\__init__.py in <module>
14 )
---> 15 from .roi_heads import (
16 ROI_HEADS_REGISTRY,
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\detectron2\modeling\roi_heads\roi_heads.py in <module>
16 from ..matcher import Matcher
---> 17 from ..poolers import ROIPooler
18 from ..proposal_generator.proposal_utils import add_ground_truth_to_proposals
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\detectron2\modeling\poolers.py in <module>
9 from detectron2.structures import Boxes
---> 10 from detectron2.utils.tracing import assert_fx_safe
11
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\detectron2\utils\tracing.py in <module>
3 import torch
----> 4 from torch.fx._symbolic_trace import _orig_module_call
5 from torch.fx._symbolic_trace import is_fx_tracing as is_fx_tracing_current
ModuleNotFoundError: No module named 'torch.fx._symbolic_trace'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
<ipython-input-36-b5a73c6d310a> in <module>
4 device_ids = [0,1]
5
----> 6 from transformers import LayoutLMv2ForTokenClassification, TrainingArguments, Trainer
7 from datasets import load_metric
8 import numpy as np
~\AppData\Local\Programs\Python\Python39\lib\importlib\_bootstrap.py in _handle_fromlist(module, fromlist, import_, recursive)
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\transformers\utils\import_utils.py in __getattr__(self, name)
1019 elif name in self._class_to_module.keys():
1020 module = self._get_module(self._class_to_module[name])
-> 1021 value = getattr(module, name)
1022 else:
1023 raise AttributeError(f"module {self.__name__} has no attribute {name}")
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\transformers\utils\import_utils.py in __getattr__(self, name)
1018 value = self._get_module(name)
1019 elif name in self._class_to_module.keys():
-> 1020 module = self._get_module(self._class_to_module[name])
1021 value = getattr(module, name)
1022 else:
~\PycharmProjects\playground\camelot\camelotenv\lib\site-packages\transformers\utils\import_utils.py in _get_module(self, module_name)
1030 return importlib.import_module("." + module_name, self.__name__)
1031 except Exception as e:
-> 1032 raise RuntimeError(
1033 f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
1034 f" traceback):\n{e}"
RuntimeError: Failed to import transformers.models.layoutlmv2.modeling_layoutlmv2 because of the following error (look up to see its traceback):
No module named 'torch.fx._symbolic_trace'
Can anyone please help?
Thanks!
This is issue from importing torch.fix flag check for symbolic trace and new commit error of detectron (use 5aeb252b194b93dc2879b4ac34bc51a31b5aee13 this checkout and install )
for temporary work
or clone pytorch with new commit

No module named keras.api Mask R CNN

I am in the demo file of the Mask R CNN repo from matterport. Trying to run the first cell but encountering the following error. I have keras 2.3.0 installed. Running Python 3.8. The below is a trace of the error from the model.py file inside the Mask R CNN repo, which came with the clone. Thanks!
The repo referred to is here: https://github.com/matterport/Mask_RCNN.git
Thank you all for your kind support.
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_3220/983756133.py in <module>
7 import matplotlib
8 import matplotlib.pyplot as plt
----> 9 import keras
10
11 # Root directory of the project
~\OneDrive\New Project\myenv1\lib\site-packages\keras\__init__.py in <module>
1 from __future__ import absolute_import
2
----> 3 from . import utils
4 from . import activations
5 from . import applications
~\OneDrive\New Project\myenv1\lib\site-packages\keras\utils\__init__.py in <module>
24 from .layer_utils import get_source_inputs
25 from .layer_utils import print_summary
---> 26 from .vis_utils import model_to_dot
27 from .vis_utils import plot_model
28 from .np_utils import to_categorical
~\OneDrive\New Project\myenv1\lib\site-packages\keras\utils\vis_utils.py in <module>
5
6 import os
----> 7 from ..models import Model
8 from ..layers.wrappers import Wrapper
9
~\OneDrive\New Project\myenv1\lib\site-packages\keras\models.py in <module>
10 from .engine.input_layer import Input
11 from .engine.input_layer import InputLayer
---> 12 from .engine.training import Model
13 from .engine.sequential import Sequential
14 from .engine.saving import save_model
~\OneDrive\New Project\myenv1\lib\site-packages\keras\engine\__init__.py in <module>
6 from .base_layer import Layer
7 from .network import get_source_inputs
----> 8 from .training import Model
~\OneDrive\New Project\myenv1\lib\site-packages\keras\engine\training.py in <module>
12 from .network import Network
13 from .base_layer import Layer
---> 14 from . import training_utils
15 from . import training_arrays
16 from . import training_generator
~\OneDrive\New Project\myenv1\lib\site-packages\keras\engine\training_utils.py in <module>
15 from .. import backend as K
16 from .. import losses
---> 17 from .. import metrics as metrics_module
18 from ..utils import Sequence
19 from ..utils import generic_utils
~\OneDrive\New Project\myenv1\lib\site-packages\keras\metrics.py in <module>
1848 import tensorflow as tf
1849 if tf.__version__ >= '2.0.0':
-> 1850 BaseMeanIoU = tf.keras.metrics.MeanIoU
1851
1852
~\OneDrive\New Project\myenv1\lib\site-packages\tensorflow\python\util\lazy_loader.py in __getattr__(self, item)
60
61 def __getattr__(self, item):
---> 62 module = self._load()
63 return getattr(module, item)
64
~\OneDrive\New Project\myenv1\lib\site-packages\tensorflow\python\util\lazy_loader.py in _load(self)
43 """Load the module and insert it into the parent's globals."""
44 # Import the target module and insert it into the parent's namespace
---> 45 module = importlib.import_module(self.__name__)
46 self._parent_module_globals[self._local_name] = module
47
~\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
129
ModuleNotFoundError: No module named 'keras.api'
I read the repo that you have referred. You maybe try run your code with environment below:
Python 3.4, TensorFlow 1.3, Keras 2.0.8

Cannot load backend 'Qt5Agg' or it doesn't show any plot

I'm trying to use 'Qt5Agg' matplotlib backend in Jupyter , but when I run %matplotlib qt, i get the following error:
ImportError Traceback (most recent call last)
<ipython-input-1-f6a92ad1c7f8> in <module>
----> 1 get_ipython().run_line_magic('matplotlib', 'qt')
2 import numpy as np
3 from scipy.integrate import odeint
4 import matplotlib.pyplot as plt
5 from mpl_toolkits.mplot3d import Axes3D
~/.local/lib/python3.5/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2312 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2313 with self.builtin_trap:
-> 2314 result = fn(*args, **kwargs)
2315 return result
2316
</home/cs/.local/lib/python3.5/site-packages/decorator.py:decorator-gen-108> in matplotlib(self, line)
~/.local/lib/python3.5/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
~/.local/lib/python3.5/site-packages/IPython/core/magics/pylab.py in matplotlib(self, line)
97 print("Available matplotlib backends: %s" % backends_list)
98 else:
---> 99 gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
100 self._show_matplotlib_backend(args.gui, backend)
101
~/.local/lib/python3.5/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
3412 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
3413
-> 3414 pt.activate_matplotlib(backend)
3415 pt.configure_inline_support(self, backend)
3416
~/.local/lib/python3.5/site-packages/IPython/core/pylabtools.py in activate_matplotlib(backend)
312
313 import matplotlib.pyplot
--> 314 matplotlib.pyplot.switch_backend(backend)
315
316 # This must be imported last in the matplotlib series, after
~/.local/lib/python3.5/site-packages/matplotlib/pyplot.py in switch_backend(newbackend)
220 "Cannot load backend {!r} which requires the {!r} interactive "
221 "framework, as {!r} is currently running".format(
--> 222 newbackend, required_framework, current_framework))
223
224 rcParams['backend'] = rcParamsDefault['backend'] = newbackend
ImportError: Cannot load backend 'Qt5Agg' which requires the 'qt5' interactive framework, as 'headless' is currently running
I tried running first:
import matplotlib
matplotlib.use('Qt5Agg')
but if i run again %matplotlib qt, i'm getting the same error.
If i don't run the magic command, and i plot something, it doesn't show anything.

import matplotlib.pyplot as plt - KeyError: 'keymap.quit_all'

import matplotlib.pyplot as plt
When I enter the code above, I get the following error
#( conda install matplotlib/ python 3.5.2/ anaconda 3.4.2 / window10)
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-19-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt
C:\Users\kimjimin\Anaconda3\lib\site-packages\matplotlib\pyplot.py in <module>()
36 from matplotlib.cbook import deprecated, warn_deprecated
37 from matplotlib import docstring
---> 38 from matplotlib.backend_bases import FigureCanvasBase
39 from matplotlib.figure import Figure, figaspect
40 from matplotlib.gridspec import GridSpec
C:\Users\kimjimin\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in <module>()
51 import numpy as np
52
---> 53 from matplotlib import (
54 backend_tools as tools, cbook, colors, textpath, tight_bbox, transforms,
55 widgets, get_backend, is_interactive, rcParams)
C:\Users\kimjimin\Anaconda3\lib\site-packages\matplotlib\backend_tools.py in <module>()
389
390
--> 391 class ToolQuitAll(ToolBase):
392 """Tool to call the figure manager destroy method"""
393
C:\Users\kimjimin\Anaconda3\lib\site-packages\matplotlib\backend_tools.py in ToolQuitAll()
393
394 description = 'Quit all figures'
--> 395 default_keymap = rcParams['keymap.quit_all']
396
397 def trigger(self, sender, event, data=None):
C:\Users\kimjimin\Anaconda3\lib\site-packages\matplotlib\__init__.py in __getitem__(self, key)
904 val = alt_val(val)
905 elif key in _deprecated_set and val is not None:
--> 906 if key.startswith('backend'):
907 warnings.warn(self.msg_backend_obsolete.format(key),
908 mplDeprecation)
KeyError: 'keymap.quit_all'

sklearn import error. No module named winreg on ubuntu 14.04

When I try to import a module from sklearn a receive an error:
In [1]: import sklearn
In [2]: from sklearn.linear_model import Lasso
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-b932cb9c16f8> in <module>()
----> 1 from sklearn.linear_model import Lasso
/usr/local/lib/python3.4/dist-packages/sklearn/linear_model/__init__.py in <module>()
10 # complete documentation.
11
---> 12 from .base import LinearRegression
13
14 from .bayes import BayesianRidge, ARDRegression
/usr/local/lib/python3.4/dist-packages/sklearn/linear_model/base.py in <module>()
26 from ..externals.joblib import Parallel, delayed
27 from ..base import BaseEstimator, ClassifierMixin, RegressorMixin
---> 28 from ..utils import as_float_array, atleast2d_or_csr, safe_asarray
29 from ..utils.extmath import safe_sparse_dot
30 from ..utils.sparsefuncs import mean_variance_axis0, inplace_column_scale
/usr/local/lib/python3.4/dist-packages/sklearn/utils/__init__.py in <module>()
9
10 from .murmurhash import murmurhash3_32
---> 11 from .validation import (as_float_array, check_arrays, safe_asarray,
12 assert_all_finite, array2d, atleast2d_or_csc,
13 atleast2d_or_csr, warn_if_not_float,
/usr/local/lib/python3.4/dist-packages/sklearn/utils/validation.py in <module>()
15
16 from ..externals import six
---> 17 from .fixes import safe_copy
18
19
/usr/local/lib/python3.4/dist-packages/sklearn/utils/fixes.py in <module>()
103
104 try:
--> 105 with ignore_warnings():
106 # Don't raise the numpy deprecation warnings that appear in
107 # 1.9
/usr/local/lib/python3.4/dist-packages/sklearn/utils/testing.py in __enter__(self)
297
298 def __enter__(self):
--> 299 clean_warning_registry() # be safe and not propagate state + chaos
300 warnings.simplefilter('always')
301 if self._entered:
/usr/local/lib/python3.4/dist-packages/sklearn/utils/testing.py in clean_warning_registry()
582 reg = "__warningregistry__"
583 for mod in sys.modules.copy().values():
--> 584 if hasattr(mod, reg):
585 getattr(mod, reg).clear()
586
/usr/lib/python3/dist-packages/scipy/lib/six.py in __getattr__(self, attr)
114 if attr in ("__file__", "__name__") and self.mod not in sys.modules:
115 raise AttributeError
--> 116 _module = self._resolve()
117 value = getattr(_module, attr)
118 setattr(self, attr, value)
/usr/lib/python3/dist-packages/scipy/lib/six.py in _resolve(self)
103
104 def _resolve(self):
--> 105 return _import_module(self.mod)
106
107 def __getattr__(self, attr):
/usr/lib/python3/dist-packages/scipy/lib/six.py in _import_module(name)
74 def _import_module(name):
75 """Import module, returning the module after the last dot."""
---> 76 __import__(name)
77 return sys.modules[name]
78
ImportError: No module named 'winreg'
In [3]:
I have installed sklearn with the command pip3 as explained in the official documentation
In [3]: sklearn.__version__
Out[3]: '0.15.1'
winreg should be a module available only for windows... how can I solve this?
EDIT:
This is the command that I have used to install sklearn :
sudo pip3 install -U scikit-learn
I have solved removing sklearn and installing the git version as explained here
https://askubuntu.com/questions/449326/installation-error-in-sklearn-for-python3

Resources