How To Create & Activate A Virtual Environment In Visual Studio Code (Python 3.12)

Поділитися
Вставка
  • Опубліковано 20 лип 2024
  • In this video I will be showing you how you can create and activate a virtual environment for Python using Visual Studio code. It's good to know in case you are not using PyCharm since a lot of code editors will not have it created or activated by default.
    ▶ Become job-ready with Python:
    www.indently.io
    ▶ Follow me on Instagram:
    / indentlyreels
    00:00 Intro
    00:10 Visual Studio Code
    00:16 Project setup
    00:34 Python 3.12
    00:43 What if?
    00:51 Error
    01:15 Creating a virtual environment
    01:48 Activating a virtual environment
    02:24 Success!
    03:28 One more thing…
    03:49 It was that easy
    03:54 Let me know what you think

КОМЕНТАРІ • 66

  • @paulmoss4199
    @paulmoss4199 9 місяців тому +4

    Thank you, that is very helpful. Is there a way to activate the VENV automatically when a new terminal window is opened?

  • @Tcrrxzz
    @Tcrrxzz 8 місяців тому

    This helped me out a lot. Thanks!

  • @insight_generator
    @insight_generator 6 місяців тому

    This video was really helpful. Thanks!

  • @kunalsoni7681
    @kunalsoni7681 9 місяців тому

    love to watch your python videos :)

  • @JoanApita
    @JoanApita 9 місяців тому

    man thank you this is what im looking for.

  • @larsthomsen6434
    @larsthomsen6434 3 місяці тому

    thank you, this was simple and easy to follow

  • @Showtime_007
    @Showtime_007 9 місяців тому

    Love your content ❤

  • @rsKayiira
    @rsKayiira 7 місяців тому

    Excellent explanation thank you

  • @krishj8011
    @krishj8011 Місяць тому

    Thanks... Great tutorial

  • @anphanhoang5308
    @anphanhoang5308 9 місяців тому

    Hello sir, when i use javascript in vs code and ctrl + s to save my code it will auto help me auto formatting, how can i do the same thing with python (.py file) in vscode

  • @Confusedcapybara8772
    @Confusedcapybara8772 4 місяці тому

    but how do you keep the venv actively when trying to run the app in debug mode, with the run button in the top right of vs code?

  • @prior2915
    @prior2915 4 місяці тому

    so would using pipenv shell be the same thing or are there any major difference?

  • @JosephAlnasl
    @JosephAlnasl 25 днів тому

    Great tutorial

  • @Nordlys0
    @Nordlys0 6 місяців тому +2

    I prefer to use virtualenv instead of venv from a terminal/cmd/powershell, which is better and faster for some reasons. Some say it's the same, which is not the case at all..
    So I've not tried virtualenv inside of VScode and give it a try.

  • @sahillimba4585
    @sahillimba4585 9 місяців тому

    Love you bro❤

  • @jagadishdasari6466
    @jagadishdasari6466 4 місяці тому

    Fantastic...

  • @gohilurvish
    @gohilurvish 5 місяців тому

    I made some python based tools for our team and had a git repo for it.
    Everytime someone new joins, I needed to get them install needed libs and sometime conflicts happen.
    Since I found venv, the issue is partially solved.
    But now I face the issue on how to manage the venv with git.
    A tutorial for that would be appreciated.

  • @neethugeorge7501
    @neethugeorge7501 4 дні тому

    Thanks a ton :) Is there a way to activate the VENV automatically when a new terminal window is opened? (.venv) is not coming when we open Terminal after closing the IDE. @Indently Plz reply

  • @KoljaMineralka
    @KoljaMineralka 4 місяці тому +1

    It would be nice if you created Best Practices playlist and gather all this tips, like using __name__ == __main__, creating virt env when starting new project etc...

  • @diegogutierrezraghunath9315
    @diegogutierrezraghunath9315 2 місяці тому

    super helpfull, however one question i have is if I close vs code, how to I get back into the virtual environment(windows)

  • @KoljaMineralka
    @KoljaMineralka 4 місяці тому

    it doesn't see pip :( in VS code, even though I installed it in virt env as per tutorial

  • @pablofueros
    @pablofueros 9 місяців тому +4

    Personally, in vscode y prefer creating and activating a virtual enviroment using the "create environment" command

  • @vincentlaizer
    @vincentlaizer 9 місяців тому +7

    It could have been nice if you showed how to deactivate the virtual environment, great video btw ❤

    • @Indently
      @Indently  9 місяців тому +2

      I will write this down for the next tutorial!

    • @Tora_Makun
      @Tora_Makun 9 місяців тому

      I thought the same thing, just tried `exit` and it worked for me

  • @hamzahassan6726
    @hamzahassan6726 8 місяців тому

    legend

  • @krzysiekkrzysiek9059
    @krzysiekkrzysiek9059 9 місяців тому +1

    Useful content 👍. Venv is good as built-in feature. Personally i prefer Pipenv 😁

    • @Indently
      @Indently  9 місяців тому

      I never explored anything else other than the built-in; any particular reason your prefer pipenv?

    • @krzysiekkrzysiek9059
      @krzysiekkrzysiek9059 9 місяців тому

      @@Indently Pipenv is:
      1. More automatic, one command (`pipenv install`) creates virtual environment and file with dependices
      2. Just type `pipenv shell` to activate environment
      3. New module installation adds depedicies automatically
      4. Type just `exit` to deactivate environment
      5. If You want clone virtual environment on other computer just paste depedicies file (`Pipenv.lock`) and type `pipenv sync`.
      6. To remove environment just type `pipenv --rm`
      7. You can create a requirements.txt file for venv
      It is worth trying `pipenv`, at most it will not appeal to you.

    • @Indently
      @Indently  9 місяців тому

      Thanks for sharing, I will take a dive into it!

  • @josericardoochoa3126
    @josericardoochoa3126 3 дні тому

    Excuse me, friend, I would like to ask you for help because when I try to create a virtual environment and write the python location in the terminal, I get the following error "Set-location: No position parameter found", just, I would like to know what mistake I made so that it does not detect it

  • @kishanbsh
    @kishanbsh 9 місяців тому

    For the virtual environment folder is ".venv" the standard? I have seen some projects use "venv" as the folder name

    • @Indently
      @Indently  9 місяців тому +3

      I know that the "." makes the folder invisible on Mac OS, but to be honest it's just what I've been doing since I started programming in Python. I would love to hear from someone else whether there's any benefit of doing that other than hiding folders for a cleaner directory.

    • @JeremyLangdon1
      @JeremyLangdon1 9 місяців тому +7

      The “.” is helpful for alphabetical ordering as well. “venv” gets mixed in with other folders while “.venv” is at the top. It also makes it more explicit that it is not meant to be part of the codebase but rather a supporting config type folder… similar to the .vscode, .git folders, etc.

  • @NiceChange
    @NiceChange 9 місяців тому +1

    You made it so simple that it instantly became a new muscle memory command...THANKS!!!

  •  9 місяців тому

    What are the advantages of using this virtual environment instead of regularly installing the package you want to use?

    • @vincentlaizer
      @vincentlaizer 9 місяців тому +1

      It helps you separate your code when working with same modules but of different versions, that's just one advantage

    • @darrenlefcoe
      @darrenlefcoe 9 місяців тому

      Actually, it's a great question.
      The number of cases where the regular install is sufficient far outweighs the cases where venv is useful (plus it is clunky to use even with a great explanatory video like this).
      ...so I rarely use venv.
      I would be interested to hear good use cases other than encapsulation of packages (which can be achieved with a simple requirements.txt file).

    • @darrenlefcoe
      @darrenlefcoe 9 місяців тому

      ​@vincentlaizer I agree with this, but still prefer to avoid...

  • @KrAsHeDD
    @KrAsHeDD 9 місяців тому

    The command for windows doesn't work for me. I've been trying to activate mine in vscode even before you uploaded this video. It says and error message "cannot be loaded be because the running script is disabled in this system"
    Despite several stackoverflow questions, it doesn't help still.
    Cmd command works fine but powershell doesn't.

    • @Indently
      @Indently  9 місяців тому

      Someone else correct me if I'm wrong since I don't have Windows, but it sounds like this is more a setting that has to do with the security settings on your computer?

    • @KrAsHeDD
      @KrAsHeDD 9 місяців тому

      @@Indently you're probably right too because it the same command I found on other places. I guess there are settings to be done to tackle the issue.

    • @mentalwall
      @mentalwall 9 місяців тому

      But the better solution is to use WSL with VSCode - solves many compatibility issues

    • @alfredopalaciosolagaray7558
      @alfredopalaciosolagaray7558 9 місяців тому +1

      Maybe it has something to do with execution policies. Run powershell as admin and try the command Set-ExecutionPolicy -ExecutionPolicy Unrestricted and try again the activate command.

    • @KEN-nh7om
      @KEN-nh7om 6 місяців тому

      @@alfredopalaciosolagaray7558 This helped so much, thank you!

  • @marcostark8926
    @marcostark8926 9 днів тому +2

    Doesnt work

  • @athirariijil4303
    @athirariijil4303 2 місяці тому

    how to deactivate virtual environment in mac (in different shell)

  • @Indently
    @Indently  9 місяців тому +1

    Here are the commands:
    Mac OS:
    python3 -m venv .venv
    source .venv/bin/activate
    Windows:
    python -m venv .venv
    .\.venv\Scripts\activate
    (Please correct me if I'm wrong for Windows, I will update this comment)

    • @SiddharthSharma-cp5vk
      @SiddharthSharma-cp5vk 9 місяців тому

      in vs code you can create and activate virtual environment using command panel too

    • @diegolramirez
      @diegolramirez 9 місяців тому

      In Windows Activate goes with capital "A" -> .venv\Scripts\Activate

    • @sayenation
      @sayenation 9 місяців тому +3

      I have just done it yesterday. Depending on which shell you use it might be correct.
      For example in Powershell you need to ".\.venv\Scripts\Activate.ps1" and also enable scripts in powershell. But scripts in PS is another topic

    • @hannesweichselbaum2038
      @hannesweichselbaum2038 9 місяців тому

      .\.venv\Scripts\Activate

    • @braydenmchan
      @braydenmchan 9 місяців тому

      You might want to run the windows command to check the .venv directory since I believe that "python -m venv .venv" and "py -m venv .venv" produce different folder structures in .venv

  • @Lord_Shan
    @Lord_Shan 9 місяців тому +1

    Continuing with this topic, it's worth mentioning the use of pip freeze > requirements.txt to generate a list of installed packages and their versions and the subsequent installation of these packages from the generated requirements.txt file.

    • @Lord_Shan
      @Lord_Shan 9 місяців тому

      @@squishy-tomato
      👍Certainly, Poetry offers distinct advantages over pip. However, for beginners and a general understanding of virtual environments and package installation for their projects, using pip is entirely sufficient.

  • @mehdimj_ir
    @mehdimj_ir 9 місяців тому

    This is nice, but please continue with Flet and create a real application.

    • @Indently
      @Indently  9 місяців тому +1

      I will upload plenty of them, but it's not the only thing I will upload on this channel ;)

  • @-ese.soy.yo-
    @-ese.soy.yo- 9 місяців тому +2

    Next video: How to deactivate venv. (Congratulations for a great channel)

    • @brien.
      @brien. 3 місяці тому

      just type deactivate on windows

  • @SiddharthSharma-cp5vk
    @SiddharthSharma-cp5vk 9 місяців тому +1

    know already

    • @Indently
      @Indently  9 місяців тому +1

      Impressive!

  • @JeremyLangdon1
    @JeremyLangdon1 9 місяців тому

    You didn’t really describe why virtual environments are helpful. Could be useful to describe using a requirements file in conjunction with a virtual environment. My preference for managing my virtual environments and dependencies is Poetry.

    • @Indently
      @Indently  9 місяців тому +1

      I actually didn't describe why they are helpful at all, but I covered how to create and activate them. I will consider the rest for another tutorial :)

  • @ButchCassidyAndSundanceKid
    @ButchCassidyAndSundanceKid 9 місяців тому +1

    Can you do a tutorial running a python virtual environment inside docker please, I'd like to use it as my development environment. Thanks.

    • @TheMusterionOfRock
      @TheMusterionOfRock 9 місяців тому +1

      We do this at work. Our conclusion was that inside docker a virtual environment makes no sense, because you are already in an isolated environment.