ImportError: 'No module named plotly.plotly' in LinuxMint17.3
Asked Answered
A

19

28

Whenever I am trying to compile the following code to get a line graph shows some errors. But I don't know how to fix it. Here is my code :

import plotly.plotly as py
import plotly.graph_objs as go

# Create random data with numpy
import numpy as np

N = 500
random_x = np.linspace(0, 1, N)
random_y = np.random.randn(N)

# Create a trace
 trace = go.Scatter(
x = random_x,
y = random_y
)

data = [trace]

 py.iplot(data, filename='basic-line')

Shows the following error :

mks@mks-H81M-S /media/mks/KUTUBUDDIN1/test $ python datdaPlot.py 
Traceback (most recent call last):
  File "datdaPlot.py", line 1, in <module>
    import plotly.plotly as py
 ImportError: No module named plotly.plotly
 mks@mks-H81M-S /media/mks/KUTUBUDDIN1/test $   

How can this be fixed?

Added:
According to Spandan Brahmbhatt, I have installed pip by sudo pip install plotly. But still shows the following error:

enter image description here

Arrange answered 1/3, 2017 at 1:45 Comment(2)
I have a similar issue on Debian Jessie, only with Python3 - It works with Python2.7 Have you got any new update or workaround about this issue?Reputation
Note to future readers: This is not a good precendent. Do not post images of text. See here for why.Sweetbread
K
23

You will need to install them first.

pip install plotly
pip install cufflinks
Klimt answered 27/2, 2018 at 4:12 Comment(0)
D
10

In my case I wanted to use in a Jupyter Notebook in Windows 10 but was getting the same error

ModuleNotFoundError Traceback (most recent call last) in ----> 1 import plotly.express as px

ModuleNotFoundError: No module named 'plotly'

Jupyter Notebook can't use plotly

Considering you can also install Anaconda in Linux Mint and these came with Anaconda (in my case), if you decide to go with Anaconda you'll have at least two options to install plotly

  1. Anaconda Prompt

  2. Anaconda Navigator

Once installed, you'll be able to use it without any problem

Using plotly in Jupyter Notebook


1. Anaconda Prompt

Open Anaconda Prompt

W10 Anaconda Prompt

Run the following command

conda install -c plotly plotly=4.8.1

Install plotly in Anaconda


2. Anaconda Navigator

Open Anaconda Navigator

Open Anaconda Navigator Windows

Inside of it, go to Environment, select All in the dropdown and search for plotly.

Anaconda Navigator environments

Then select plotly from that list and click Apply.

Dactylo answered 11/6, 2020 at 9:2 Comment(1)
Using Anaconda Navigator as shown above solved the issue for me.Barratry
I
5

I had the same problem. I accidentally was using a file in my working directory named ploylt.py. I removed that file form the directory and it works fine now. First make sure that you have installed plotly

    pip install plotly 

(Test) Open an empty file, type

    import plotly  

and save it with a .py extension. Then run it. If this works, then your installation was ok. Move any other file named plotly (with any extension) in a different directory It will hopefully work.

Idomeneus answered 12/3, 2018 at 15:27 Comment(0)
H
4

Based on ImportError: No module named plotly.plotly, I assume you have not installed plotly module.

You can install it using pip

$ pip install plotly 

or

$ sudo pip install plotly 
Handbarrow answered 1/3, 2017 at 2:17 Comment(2)
@SB I have done it but still shows the error : I attached it to my post.Arrange
@Arrange The issue is import plotly.plotly as py does an online plotting for which you need to set up the credentials. You will need an API key. You can learn more about the key here : plot.ly/python/getting-startedHandbarrow
A
3

Firstly, I'm new to plotly 2, and I am not sure I can make you understand since I'm a Chinese.

Anyway, you can try this, for me, it works:

import plotly
plotly.offline.init_notebook_mode(connected=True)
import plotly.offline as py

import plotly.plotly as py: this command will communicate with a Plotly Cloud or Plotly Enterprise. get_figure downloads a figure from plot.ly or Plotly Enterprise. You need to provide credentials to download figures: Getting Started with Plotly for Python

Refer:

Adaiha answered 21/12, 2017 at 6:52 Comment(0)
S
3

Use this:

conda install -c https://conda.anaconda.org/plotly plotly
Salba answered 30/12, 2018 at 9:35 Comment(0)
S
3

If you are using jupyter notebook in windows, then open the Anaconda Powershell Prompt(better to open in admin mode) and use the below command.

pip install plotly
pip install cufflinks

If you are using python from command prompt or which is set in the Environment variable then open the command prompt and use the same command mentioned above.

Both use different instance of python. So, if you use the above mentioned pip command in Anaconda PowerShell than it will install the libraries(plotly and cufflinks) in the python folder that comes with anaconda package but not in the python folder that you are using form the command prompt or which is set in the Environment variable.

Schonthal answered 20/11, 2019 at 7:36 Comment(0)
M
2

I had the same problem. I found the solution by going through the directories. pip install is installing in default python lib folder, all you have to do is copy the plotly folder from python lib to jupyter notebook lib folder. Since I am using windows the directories were as following :

c:\python34\lib\site-packages

c:\Anacoda3\Lib\site-packages

Michaelson answered 13/2, 2018 at 19:25 Comment(0)
P
2

In case you searched around like I did until I found the link below, but looked here first, hopefully this will save you some frustration.

Delete the plotly.py file in your root folder. The one you created to test the get started code.

After you do that you'll be searching for a while again unless you delete the .pyc file (and get the ImportError: bad magic number in 'plotly': b'\x03\xf3\r\n').

https://github.com/plotly/plotly.py/issues/723

Playwriting answered 22/11, 2018 at 23:20 Comment(0)
M
1

I was also having the same issue, but then it was due to different versions of python.

You might want to try the following command as well: (assuming you have python3 installed)

sudo pip3 install plotly
pip3 install plotly --upgrade
python3 <filename.py>

Please ensure that all the packages that are being used are installed for one python version only. As in my case all packages were installed for python3 but then I was trying to run my code with "python filename.py" and somehow that did not work.

Moreover, I also setup the credentials by following the link: https://plot.ly/settings/api. Register yourself using the link https://plot.ly/settings/api. Then create a file ~/.plotly/.credentials with your username and authentication key.

Makepeace answered 31/10, 2017 at 15:47 Comment(0)
M
1

Hi I ran into something similar on my PC and here is what I advise you to do because it worked for me:

  • Open your Anaconda Prompt and run pip install plotly==4.1.1 cufflinks

  • Note that the 4.1.1 here is the version of plotly.

Installation:

Terminal:
- You can find more information about both plotly and cufflinks here.

Anaconda, Jupyter Notebook and Visual Studio Code:
- I believe I ran into this error because I did not install plotly on my PC so you can find more information on various ways of installing plotly here.

Materials answered 24/5, 2020 at 10:8 Comment(0)
M
1

Like @Ananada, I had named my test file "plotly.py", i.e. the one containing the import plotly.graph_objects as go statement. So Python was trying to import the module from the script file I was running. Doh! Renamed it and problem solved.

Milone answered 4/7, 2020 at 2:8 Comment(1)
Almost same issue - I had ANOTHER plotly.py in the folder.. !@#$QDFASDEF!@Magnetochemistry
B
1

To install plotly:

conda install -c plotly plotly

To check whether the installation was successful:

python3 -m pip show plotly

This shows the version of plotly installed in case of successful installation. This worked for me!

Brilliantine answered 5/10, 2022 at 10:8 Comment(0)
H
0

Activate your environment again after installing the package if you are using a virtual environment.

Do source bin/activate if using bash. See https://docs.python.org/3/tutorial/venv.html.

Hal answered 26/4, 2020 at 14:30 Comment(0)
M
0

Check your folder ... If this a temporary/test folder, maybe just like me you are wasting your whole day trying to understand why you cannot import .... .. .. Maybe, just like happened to me - you have ANOTHER plotly.py file in your folder. Yes, that one.

Magnetochemistry answered 26/7, 2020 at 19:38 Comment(0)
T
0

Actually the module plotly is not pre-installed and we need it to be installed on our machines before using. It can be installed by using pip command :

pip install plotly

Also, we can install cufflinks. Cufflinks are smart plots.

pip install cufflinks

Timtima answered 13/4, 2021 at 7:41 Comment(0)
D
0

When you will get an error using anaconda navigator plotly install.

  1. Go to the particular environment in Anaconda Navigator.
  2. Then open terminal for the environment. open terminal for the environment
  3. Install the packages.
Dewyeyed answered 25/8, 2021 at 16:52 Comment(0)
C
0

On my Laptop, I had to use this code

!pip install pip plotly

Installing the "!" is key for my installation

All the best

Corley answered 23/1, 2022 at 16:22 Comment(0)
S
0

I was encountering a ModuleNotFoundError for Plotly even after "installing" it. It turned out that the pip I was using was pointing to my .local directory, so it was not installing Plotly in my conda environment as desired.

I used which pip in the terminal, which was pointing to /home/user/.local/bin/pip. So I used:

/home/user/anaconda3/envs/<env_name>/bin/pip install plotly

Also, I double-checked the Python interpreter in VS.

Working! :)

Scudo answered 15/7 at 23:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.