Module plotly.offline not found - python

I get this error importing in a Python virtual environment,
import plotly.offline
ModuleNotFoundError: No module named 'plotly.offline'
I installed plotly using pip install plotly. Tried to uninstall and reinstall. But still same eror. I'm using Python3 in the venv. I can import plotly with import plotly but none of its modules I can't.
But when I tried a global install (not using a venv) I am able to import plotly.offline.

Related

How to install 'plotly' from inside Anaconda under Colab on Mac

I tried to import plotly in Anaconda with code
import plotly.graph_objs as go
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
but received error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-11-978bd9a5088a> in <module>
14
15 # import plotly.plotly as py
---> 16 import plotly.graph_objs as go
17 from plotly import __version__
18 from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
ModuleNotFoundError: No module named 'plotly'
I have checked a number of similar posts to install 'plotly' on Jupyter but somehow I couldn't do it on Mac. I usually use Google Colab, could it be the reason that I am using different platforms that caused the confusion when installing?
Jupyter Notebooks start in an "environment". Anaconda created the environment and it contains a lot of useful libraries. It also holds a self-contained python interpreter. In this instance, the environment didn't have the library plotly installed (it's not a default library that Anaconda provides) so you had to install plotly in your environment that the notebook lives in.
The environments that are used with Jupyter Notebooks are a little tricky to get to in order to install things, so this way, using import sys then installing the library with !{sys.executable} -m pip install plotly finds the python interpreter with !{sys.executable} and installs plotly using pip right in the Notebook itself.
More reading:
Environments
Pip
Packages included with Anaconda
try:
import sys
!{sys.executable} -m pip install plotly
import plotly.graph_objs as go
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)

ModuleNotFoundError: No module named 'websocket' even though I installed pip install websocket

I am trying to run some code that has 'import websocket' however I am getting the error: ModuleNotFoundError: No module named 'websocket'
I have Python 3.7.3 and I am running in Spyder (if that makes a difference).
So from other questions/answers I found on here, in my cmd I ran pip install websocket and then also pip install websocket-client when the first one didn't run.
I am still getting the ModuleNotFoundError. Does it matter the location/folder of the code or where I install the pip command in cmd?
My python code starts with these import statements:
import json
import websocket
import traceback
import helper
import ssl
import time as time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
from mpl_toolkits.mplot3d import Axes3D
In cmd I ran:
C:\Users\myname>pip install websocket
and also:
C:\Users\myname>pip install websocket-client
The error I am getting is:
File "C:/Users/micki/Downloads/Derbit-Volatility-Visulization-master/Derbit-Volatility-Visulization-master/Volatility Surface Class.py", line 2, in <module>
import websocket
ModuleNotFoundError: No module named 'websocket'
Not sure, as you did not cover how you installed and are using Spyder, though I think it is probably an issue with your environment. You might also find that you are missing the module "helper" as well. There's two easy options as follows:
If you installed and are using Spyder via conda or anaconda, follow their documentation on installing websocket-client to the correct environment found here.
The second option (the preferred option IMHO, as you can use any IDE or text editor going forward), regardless of how you installed Spyder, would be to create a python virtual environment python3 -m venv /path/to/new/virtual/environment, pip install all your dependencies in said environment, then link Spyder's interpreter to the interpereter that was installed when you made the environment. In Spyder, go to Tools -> Preferences -> Python interpreter -> check the "Use the following Python interpreter:" radio button and enter the path to the interpreter from the environment you just created. For reference, see docs on making and using a python venv here.
If the websocket and websocket-client doesn't work, try:
pip install websocket_client
This solved my issue:
sudo pip install websocket-client

Cannot import name cbook in jupyter

I have matplotlib-2.2.3 installed. When I used matplotlib in jupyter, it throws the following error:
ImportError: cannot import name cbook in jupyter
All is OK when I run the code in PyCharm. I used python 2.7 and I have tried many suggestions like that in ImportError: cannot import name cbook but none worked.
I finally found the solution that downgrade the matplotlib and six, and that solves my question.
pip install six==1.10.0
pip install matplotlib==2.0.2

get Error: 'no module named 'matplotlib.style' while matplotlib works fine

I'm using PyCharm on an ubuntu 14.04.1 LTS with python3. I want to use the 'ggplot' style module, but I get an 'no module named' error. Matplotlib 1.3.1 is installed and works fine (I updated it recently).
import matplotlib as mpl
import matplotlib.style as mplstyle
mplstyle.use('ggplot')
ImportError: No module named 'matplotlib.style'
I also checked for the matplotlibrc file and matplotlibtool and everything seems to be as the documentation recommends. Anyone knows, what I can do?
According to What's new in matplotlib, the style package was added to matplotlib since version 1.4.
So, check your matplotlib version by,
$ pip freeze | grep matplotlib
matplotlib==1.3.1
Upgrade matplotlib to the newest version by,
$ sudo pip install matplotlib --upgrade
$ pip freeze | grep matplotlib
matplotlib==1.5.1
This works fine for me.
import matplotlib.pyplot as plt
plt.style.use('ggplot')

Python - Can't import Seaborn

I'm running iPhyton Notebooks and I'm trying to import the Seaborn package. When I try to import it from the Terminal, it loads up fine, but when I import it through iPython Notebooks, it give me the following error.
I have even tried to re-install Seaborn using both Conda and Pip inside iPython notebooks and still it wont work.
Any idea why?
Thanks.
ImportError Traceback (most recent call last)
<ipython-input-1-417274a1ae6c> in <module>()
1 get_ipython().system(u'conda install seaborn')
2 get_ipython().system(u'pip install seaborn')
----> 3 import seaborn as sb
4
ImportError: No module named seaborn
Try this
import sys
print sys.path
sys.path.append('<path to package in your syste>')
import seaborn
In my Ubuntu 14.4LTS the packages get installed in the following folder
/usr/local/lib/python2.7/dist-packages
So I simply add the package path at run time
Donit install Ipython on all your system. Install it only in the environments you want it. Otherwise Ipython will look for modules in the default path instead of the environment's path.
This is probably where your ipython is looking:
/home/user/anaconda2/lib/python2.7/
It should be looking for modules here:
/home/user/anaconda2/envs/name-of-env/lib/python3.4/
To check the path you type:
import sys
sys.path
Try entering the following in your terminal:
conda install seaborn
It will install seaborn and make it available for you to import into your notebook
Open anaconda prompt and Type
pip install seaborn

Categories