0

I'm trying to create graphs using plotly for the first time. Since I'm currently using Visual Studio Code for my coding (either python scripts or notebooks), I'm currently trying to use plotly in VSC.

I've installed everything from the plotly getting started page (conda installed plotly, notebook, ipywidgets and even jupyter) but I'm still getiing an error when importing.

The thing is, when I've tried importing plotly in a python file in VSC, it's running well. I've also tried running it in a Jupyter Notebook and it's also running.

import plotly.express as px

I'm pretty sure that I've installed everything in the correct environment and I'm using the same environment all throughout.

What do I need to run plotly in a notebook in VSC?

3
  • try doing a which python and which pip if you're on mac or python -v and test if the two versions are the versions you're expecting. Commented Jul 20, 2020 at 10:17
  • @Nathan I'm not sure how to run these commands in VSC but I got a hint from your comment to double check the all versions I'm using. Turns out that though I'm using the correct venv, the kernel I'm running is not from that environment. When I switch the kernel, it executes perfectly. Don't know that there is difference in the venv and kernel environment settings in VSC. Thanks for your help! Commented Jul 20, 2020 at 11:13
  • No problem, next time check all versions :) Commented Jul 20, 2020 at 11:23

1 Answer 1

1

It seems like your python versions/pip versions are different (especially if you're using an env). In Visual studio Code, you can bring up a simple terminal directing to the directory of your project (or env). Just click Terminal > New terminal. This will bring up a terminal (like CMD or terminal) at the bottom of the screen.

From then you can check the version of Pip and python for either your system globally, or the version install in your env. As long as your env is activated, then it will check the versions for the env, not your system.

For macOS:

To show all python installations of your system:

which -a python

To get the version for python 3 (which is what you should be on):

python3 --version

To get the version for pip:

pip -v

For windows:

python3 --version

pip -v

If the versions are incorrect then you can either install the right version of pip in your env or change python paths. First option is recommended.

If you are using macOS. Entering the command which -a python will show a very old Python 2.X version. Do not tamper with this or it's path as it is needed by macOS to run.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.