Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use created python virtual environment in vscode jupyter notebook

I am using notebook in VScode and I am working with tensorflow==1.15.5 but in my system version is 2.3.2.

So I created virtual environment with python 3.7 and on system activated python is 3.8 and installed version 1.15.5. Now I want to activate this virtual env in notebook too.

I tried selecting the interpreter (Ctrl + Shift + P) and selected the created environment. But this is not working.

I tried

import tensorflow as tf
print(tf.__version__)

this is still showing 2.3.2

and even

!python --version

is showing 3.8.0

even i tried this article but this is not working too. I am not using conda, any help on this

like image 435
Sunil Garg Avatar asked Mar 22 '26 05:03

Sunil Garg


1 Answers

Make sure your virtual environment is activated and selected as python interpreter in VS Code, and don't forget to select it for Jupyter.

Select and activate an environment

I create a virtual environment called venv and install tensorflow2.5.0. When i select venv as interpreter for .py file and .ipynb file, it will exactly show the same verison of tesorflow installed in new created venv:

enter image description here

[UPDATE]

In Jupyter Notebooks in VS Code, it says

To work with Jupyter notebooks, you must activate an Anaconda environment in VS Code, or another Python environment in which you've installed the Jupyter package.

That's why you install conda and it worked, and even though you select venv but no jupyter package in it, it wouldn't be used when running code cells.

like image 85
Molly Wang-MSFT Avatar answered Mar 23 '26 19:03

Molly Wang-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!