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?
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.
Related
I just downloaded vscode using homebrew and install python#3.11 using homebrew as well. I used pip3 install jupyter as I saw other recommend to fix this issue and still no luck. I have downloaded all the extensions on vscode and I have set the kernal to homebrew version of python and I still recieve this issue. Note that I have used notebooks in the past and have never gotten this issue so I am not really sure what it is this time. I have not installed anaconda.
I have tried uninstalling and installing the extensions but no luck. I have tried to pip3 uninstall jupyter, pip3 uninstall notebook and reinstall them and still no luck. I have tried to change the kernal to the default python3 on the mac and still nothing. My mac is m1 running on Ventura 13.2. I am able to run python code on regular python files just not using jupyter notebook. I followed the instructions how to set it up on vscode website but I got this error. Any help would be appreciated thank you.
I have same issue using VSCode on Mac OS.
VSCode's 'Jupyter' plugin is broken, causing VSCode unable to bind with python interpreter. Downgrading from v2023.1.2000312134 to v2022.11.1003412109 fixed my issue.
I had the same issue, running on m1 mac (Ventura 13.2). If you aren't already, make sure you are utilising a python virtual environment:
# Create a python virtual environment
$ python -m venv venv
# Activate your python virtual environment
$ source venv/bin/activate
Form your VSCode Command Palette (Shift+Command+P), search and then choose
Jupyter: Select Interpreter to Start Jupyter Server
You should then select the python version that is associated to your virtual environment (venv).
For the life of me I can't get the VSCode integrated terminal to correctly run a simple program that just has import torch in it. I've tried it all. I tried just installing pytorch via conda (I have Anaconda) inside the VSCode terminal, and then running my program inside the VSCode terminal as well. I tried creating a conda virtual environment, activating it, installing pytorch in it, and then running my program using the virtual environment. I tried switching the VSCode python to ('base': conda) and it didn't work. I tried switching the VSCode python to ('pytorch': conda) (I read this somewhere on StackOverflow), but I didn't find this. I tried uninstalling and re-installing the Python extension in VSCode. I tried just running python3 inside the VSCode terminal and seeing if >>> import torch would run, but it doesn't. I tried installing torch with pip or pip3 instead of with conda but it doesn't work, it just tells me that No matching distribution found for torch.
However, outside of VSCode, I can do import torch and it runs correctly. How could I solve this? I would very much prefer to use VSCode and its integrated terminal, but VSCode can't find pytorch for the life of me.
EDIT: Using MacOS Monterey and most updated python extension in VSCode
I installed scikit-learn via pip3 but I can't access them in the jupyter notebook in the vs-code.
And when I am writing !sudo pip3 install -U scikit-learn in a jupyter cell, i can't enter the password for sudo.
Your Python version in the terminal is 3.8 and according to the very lower left hand corner of the screenshot you posted, the version of Python that VSCode is running is 3.9.0.
I'd recommend switching the version of Python that VSCode is running, by clicking on the version in the lower left hand corner of the VSCode window and selecting the one that matches the version in the terminal. That should solve it.
I am on Ubuntu 20.04 and have both Python2 and Python3 installed natively. I have also installed Python through miniforge, a variant of miniconda. In VSCode I have both the MS Python extension and Pylance installed.
I use the miniforge python for my coding. This works perfectly fine in PyCharm.
However in VSCode, when I try to execute the same file I get errors. After investigating it seems that VSCode is picking native Python2 - even though I have the miniforge Python selected. In this picture it can be seen that the status bar at the bottom states Python interpreter selected is Python3. But the output window shows that the python interpreter is Python2.
A more confusing thing is when I use VSCode for Jupyter notebook files then it picks up the interpreter correctly and I have no issues.
I have checked both User and Workspace settings, and they all point to Python3. How can I fix this for standard .py files?
I prefer VSCode to PyCharm, but will need to use PyCharm till this is resolved.
It seems that your system console cannot see python3. You need to put the python3 in the PATH variable, before python2. Like:
PATH=path/to/python3:path/to/python2:$PATH
Also, make sure that the environment containing python3 is activated before command prompt appears. It can be done in bash_profile by adding a line like
conda activate my_env_with_python3
Try changing the settings "Python:Python path", "Python:default interpreter path" and "Python:conda path" also.
I have just bumped into something similar. The Run code option resulted in the file being run with the default interpreter instead of the venv-based one with necessary packages installed.
The fix was simply to use "Run python file" instead:
The run-code behavior must be customizable, something is mentioned e.g. here: Run Code vs Run Python File in Terminal for VSCODE but I didn't bother.
I will come straight to the point. I installed python version 3.8.5 as the latest stable python version but when I use the command python3 in my terminal it makes me use python 3.7.6.
Is there a way to fix this?
screenshot of the problem
Make sure you have added the local of the new version to your PATH variable, and ensure the command s referring to the right file with
python3 —version
Check this out: https://superuser.com/questions/433897/python-in-command-line-runs-the-wrong-version