0

I set up a Python virtual environment in 'Visual Studio Code'. Here is the full path to my python interpreter:

"C:\Users\Hamid\Desktop\VisualStudio.venv\Scripts\python.exe"

I am creating an Azure function. I have the following files in my folder:

enter image description here

In my requirements.txt file I have the names of the Python packages I need installed for my main Python script. When I run the following command in the terminal:

pip install -r requirements.txt

I get the following message:

Requirement already satisfied: azure-functions in c:\users\hamid\appdata\local\programs\python\python39\lib\site-packages (from -r requirements.txt (line 5)) (1.12.0)

The Terminal doesn't seem to be connected to my Virtual Python environment. How can I set the terminal up so that it connects to the virtual enviornment?.

I came across two suggestions on stackoverflow. I tried to manually set the python interpreter and I also pressed ctrl+shift+' to reset the terminal. Unfortunately both methods did not work for me.

HamidBee
  • 187
  • 1
  • 7

1 Answers1

0

One of the workarounds is to activate the virtual environment and change the function run path to virtual environment folder in the VS Code terminal:

python -m venv .venv
source .venv/bin/activate

OR

set-executionpolicy remotesigned
.venv\Scripts\Activate.ps1

OR when you open the project in VS Code, you'll get the dialog box like below and click on yes:

enter image description here

and freeze the requirements file using the cmdlet

pip freeze > requirements.txt`

Refer to few of my workarounds SO Thread1 and Thread2 in regards of Virtual Environment activating in Azure Functions