I have followed the Plotly installation instructions using conda and pip and both lead to the following Python traceback error: ModuleNotFoundError : No module named āplotlyā
I have been Googling for more than an hour to find answer to this and no matter what I have tried, I canāt resolve this error. The simplest test case I have done is:
Sorry to hear this @adiadidas15. Itās hard to know whatās going on, so here are a couple of questions which might help you debugging.
What happens if you donāt specify the version number of plotly (just conda install -c plotly plotly)?
Also, does the conda install command raise any error or does it complete successfully?
You can also check in the notebook the sys.path (import sys; sys.path) and check whether the directory where conda installed plotly is in the list of the sys.path.
Finally, did you try to install another package with this method just to check that itās not something wrong with your version of conda?
Did you already have an older version of plotly installed? (With a fresh environment this shouldnāt be a problem, butā¦)
Hello Emmanuelle,
When I execute conda install -c plotly plotly, I get # All requested packages already installed.
conda install has never returned an error in my many attempts to get plotly installed.
Iām not sure how to find where conda āinstallsā plotly, so I canāt conform that is in the sys.path.
But when I execute conda list, plotly is listed.
But when you remove it then during a conda install it should tell you in which directory itās installing the package? Iām not using conda much but thatās what pip does.
To answer some of your other questions, I may have (Iām not sure) first installed plotly using Anaconda Navigator rather than the Anaconda Prompt. I have successfully installed other packages using Anaconda Prompt such as selenium, pandas, numpy, etc.
Conda tells me the path to my virtual environment when I install a package. It doesnāt tell me a path to where the package is installed. Iām happy to use pip instead of conda if that would help.
Which OS are you using? With windows it can be hard without anaconda. Otherwise (linux and mac) trying with pip is a good idea for debugging. I would start by uninstalling plotly with both conda and pip as described in the troubleshooting guide https://plot.ly/python/troubleshooting/#import-problems
Okay, I executed conda uninstall plotly without getting any errors. FYI, the troubleshooting guide gives the wrong command. It instructs pip remove plotly but I believe it should be pip uninstall plotly. I got an error with the former (ERROR: unknown command "remove") and got WARNING: Skipping plotly as it is not installed. with the latter.
I then executed conda install -c plotly plotly=4.3.0 and didnāt get any errors.
Running the Python command import plotly still gives the same error.
Hello Batalex,
With my virtual environment activated, where python does reveal python.exe to be present in my environment directory. Also, pip freeze does list plotly.
Well I have some new information. When I run import plotly in an IPython window via VS Code I get the same result as in a Jupyter notebook. But when I run this line in a Python terminal via VS Code it executes without an error!
Hum, is jupyter installed in the virtual environment? If not, then the jupyter/ipython command would use the global python installation instead of the venvās. Can you try in your venv to launch jupyter with python -m jupyter notebook?
After running into this problem with another package just now, I started doing some more Googling. Running import sys then print(sys.path) in both the VS Code terminal and the VS Code IPython REPL gives different paths. The terminal lists my virtual environment directories, but the IPython session does not. Therefore my problem is figuring out how to configure Anaconda so that it will launch IPython sessions with the same virtual environment as my terminal. Iāll post this question on stackoverflow since it is clearly not specific to plotly. Thanks for your help!
OK, good luck then, hope you can solve the issue. A different solution could be to reinstall Anaconda from scratch, they provide plotly 4.1 which is not the most recent version but maybe itās enough for your needs?
For posterityās sake, hereās my SO question and answer. Ultimately the problem was a silly mistake on my part. I hadnāt installed jupyter in my virtual environment, so whenever I started a session based on IPython, it was failing to do so in my activated environment. It would then look for other virtual environments to use, in my case choosing the base conda envirornment. This environment does not have plotly installed, but it had all the other packages I needed.