ImportError: 'No module named plotly.plotly' in LinuxMint17.3

孤者浪人 提交于 2019-12-05 20:03:17

问题


I am New in Python. 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 $   

Please help to fix this. Thanks in advance.

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


回答1:


You will need to install them first.

pip install plotly
pip install cufflinks



回答2:


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:

  • Why Python line plot shows : Don't have an account? plot.ly



回答3:


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




回答4:


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.




回答5:


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.




回答6:


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




回答7:


Use this:

conda install -c https://conda.anaconda.org/plotly plotly



回答8:


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 



回答9:


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 pip command in Anaconda PowerShell than it will installed the library in the python folder that comes with anaconda package.



来源:https://stackoverflow.com/questions/42521772/importerror-no-module-named-plotly-plotly-in-linuxmint17-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!