skip to Main Content

so I am using Python 3.12.2. I am using Visual Studio Code. I cloned a project I had made on my laptop onto my desktop. I created a virtual environment like I usually do with the command ("Python -m venv venv")(I usually have better names but project is simple so name wasn’t too important). I can activate the virtual environment using the command venvScriptsactivate.bat but I don’t want to do this. I like the option of just running the python programs and have the venv automatically "activated" without having to always run this command. I am assuming this has something to do with my environment variables but I am unsure. I attached a screenshot of my environment variables if that helps.
I am using just the default venv module that comes with base python
enter image description here

Forgot to add that the interpreter is just 3.12.2(‘venv’:venv). Probably isn’t necessary to state but just trying to give as much useful info as possible.

EDIT: I fixed my problem, I needed to set python.terminal.activateEnvironment to True

2

Answers


  1. Chosen as BEST ANSWER

    I found the answer to my issue and am posting it here in case people experience the same issue as me. If you find that your virtual environment in visual studio code is not being activated every time you open a new terminal you need to go to file -> preferences -> settings and from there search up python.terminal.activateEnvironment in the search bar and ensure you have this feature activated(checked). This is set to true by default though. There is another post with the same problem which was solved several years ago, I however did not find it when searching for a solution to my problem initially. Here is that post

    https://stackoverflow.com/questions/58433333/auto-activate-virtual-environment-in-visual-studio-code#:~:text=Set%20needed%20configurations%20in%20your%20settings.json&text=(Optional)%20Internally%2C%20%22python,to%20false%20in%20your%20settings.


  2. I think you can do it by chosing your python interpreter

    Just use F1 -> Python: Select Interpreter -> Select your virtual environment
    Then if you open a terminal or execute python file you should be using your virtual environment

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search