3

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

1 Answer 1

3

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.

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

4 Comments

yes i have selected and actovated the created env, but no luck
So now your question is it's showing venv in the top right corner of Jupyter, when you run code, it still uses the global python environment? Run import sys print(sys.version) print(sys.executable) in Jupyter to check the current used python in Jupyter, Is it as the same as the one in top-right corner of Jupyter?
yes, it is using venv but still refer to global python and global packages, i installed conda, and no changes i have made, and it worked
@SunilGarg. Got the reason! Please have a look at my answer update.

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.