YG Dang
YG Dang

Reputation: 11

No module named 'plotly'

I am new to python and I'm following a tutorial using python3. I installed plotly and I can see it in the pip list and pip3 list and python help("modules"). However, when I tried to import the module (from plotly import offline) I got the error:

ModuleNotFoundError: No module named 'plotly'.

Tried to reinstall but it did not work. I can import other modules in the list, like pygame or matplotlib without a problem.

Upvotes: 0

Views: 1166

Answers (3)

jsiot
jsiot

Reputation: 126

I had the same problem; after uninstalling/installing plotly, use venv, I realised (after 2h) that my script name was "plotly.py" => that was the cause of the error

Upvotes: 0

Chris
Chris

Reputation: 2860

It is usually a good idea to create a virtual environment to install additional modules. This will create a sealed Python environment with only the packages you specify. This usually fixes such errors, as Python sometimes installs packages where they can later not be found anymore. It is also a good idea to not use pip, as it might point to a pip from a different python version. Also it makes sense to upgrade pip before installing packages.

Try the following:

python3 -m venv env
. env/bin/activate       (on Linux)
.\env\Scripts\activate   (on Windows)

Check which packages we have:

python -m freeze

Here make sure this does not show anything except pkg-resources==0.0.0. Otherwise your PYTHONPATH might be mesed up.

Upgrade pip and install your package:

python -m pip install --upgrade pip
python -m pip install plotly

Run python and import your package:

python 
>>> import plotly

Upvotes: 1

Laurens
Laurens

Reputation: 63

If I typ this:

pip install plotly

in a CMD and this:

>>> from plotly import offline

In the interpreter it workes fine, try uninstalling and reinstalling plotly:

pip uninstall plotly

Enter y when it says Proceed (y/n)? And install again with

pip install plotly

Upvotes: 0

Related Questions