Python Tutorial: VENV (Mac & Linux) - How to Use Virtual Environments with the Built-In venv Module

Поделиться
HTML-код
  • Опубликовано: 2 янв 2025

Комментарии • 238

  • @Rocorama1
    @Rocorama1 5 лет назад +213

    You've gotta show this guy the love as he always explains things in such simple terms and then gives you a little extra that you weren't expecting! Thank you sir for all the time you invest to give us great content!

  • @ruixue6955
    @ruixue6955 4 года назад +143

    0:48 why virtual environment
    to have a space where we can install packages specific to a certain project
    0:57 example for updating from Django 1 to Django 2
    1:22 each project should have its own packages separate from each other
    1:34 demo: need *Python 3.3 or higher*
    2:05 pip3 list
    2:51 create a new virtual environment - 2:57 *python3 -m venv project_env* (project_env is the name of the project to be initialized)
    3:42 activate the created virtual environment - 3:45 *source* project_env/bin/activate
    5:34 if other wants to export the packages that are used 5:39 *requirement.txt*
    5:56 *pip freeze*
    6:25 in Linux: *pip freeze > requirements.txt*
    6:55 deactivate the project
    *7:43** normal practice of using venv*
    8:24 use of the created requirements.txt
    8:35 *pip install -r requirements.txt*
    9:04 one thing to mention: *it is common to put virtual environment inside your project folder, but you don't want to put project files into your virtual environment*
    9:29
    10:01 you shouldn't commit your virtual environment to your source control
    10:16 what should be committed in version control: your requirements.txt
    10:38 how to create an environment with access to system-packages
    11:29 --system-site-packages
    12:08 the additional packages installed in this environment won't affect the system packages
    12:35 pip list --local

  • @kipronoelijahkoech4630
    @kipronoelijahkoech4630 4 года назад +36

    You are just too great. Nowadays I search RUclips with your name I be like "virtual environment in Python Corey Schafer" .

  • @alexandrostsagkaropoulos
    @alexandrostsagkaropoulos Год назад +3

    So simple, yet elegant and concise explanation of something I just now comprehended completely. Congrats Corey, you are a phenomenal teacher!

  • @Ben-kz2km
    @Ben-kz2km 5 лет назад +4

    These virtual environments are a really clever way to not run into problems when you have different projects with different requirements. I love it!

  • @pavelow36
    @pavelow36 5 лет назад +5

    been to numerous pages, wikis, stackoverflows and only got confused snippets of virtual environments. Watched your video and my brain got opened and clarity shone inside... magnifico!

  • @joelprestonsmith
    @joelprestonsmith 2 года назад +1

    I love how simple and straightforward this video is. Whenever I want to learn something new about Python, I first check to see if you've covered it.

  • @rafaelalvesduarte4928
    @rafaelalvesduarte4928 5 лет назад +46

    Simple, direct and well explained.
    Thanks man, this helped me!

  • @sakhawatali9481
    @sakhawatali9481 4 года назад +1

    Great tutorial thanks. Short and informative.
    Below are my notes.
    1. Create a seprate folder for venv data inside the project source
    2. Create virtual environment
    -python3 -m venv {path/folder}
    $ python3 -m venv venv
    3. Create virtual environment which have access to system packages
    $ python3 -m venv venv --system-site-packages
    4. Activate virtual environment
    -source {folder}/bin/activate
    $ source venv/bin/activate
    5. Check if venv is activated
    $ which python
    6. List installed package
    pip list
    7. List packages installed in venv
    $ pip freeze
    8. Export required package to requirment.txt
    pip freeze > requirment.txt
    9. Exit venv
    deactivate
    10. Install packages from requirment.txt in venv
    $ pip install -r requirement.txt

  • @abraraltaflone
    @abraraltaflone 4 года назад +9

    I was so much confused about the environment thing earlier but after watching the video you made so easy for me to understand. You're great!

  • @nicklansbury3166
    @nicklansbury3166 4 года назад +1

    Thanks for the helpful explanation Corey.
    For those folks (like me) using the fish shell, at around the 3:50 mark you'll need to enter *source py3env/bin/**activate.fish* in the terminal otherwise you'll most likely get an error like this:
    project_env/bin/activate (line 74): Missing end to balance this if statement
    if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
    ^
    from sourcing file project_env/bin/activate
    called on standard input
    source: Error while reading file 'project_env/bin/activate'

  • @0x007A
    @0x007A 3 года назад +2

    The introduction to venv that I was seeking - concise yet complete.

  • @VictorOlet
    @VictorOlet 5 лет назад +4

    7:22 Creating a new virtual environment (Best practice)
    4:28 If you need to use a different version of python
    5:40 Exporting packages from your environment with requirements.txt
    file
    8:25 Creating a virtual environment from a requirements.txt file
    10:30 Deactivating environment
    11:00 Creating a virtual environment containing all system packages
    12:35 Listing packages you've installed within the environment (not system packages)

  • @NormanBaatz
    @NormanBaatz Год назад

    Best video on venv that I found of the six I watched (and didn't even care to finish watching in some cases).

  • @edwardwong654
    @edwardwong654 Год назад +1

    I had to watch this like at least 3 times, probably more. But Corey is still the best. If I am not going to understand it with Corey, then it was not meant to be. But I definitely got a little more each time.

  • @Ausare911
    @Ausare911 2 года назад

    On all of your videos (that I've watched) you fill knowledge gaps perfectly.

  • @sheesh_kebab
    @sheesh_kebab 5 лет назад +7

    This video explains everything...and then goes beyond! Loved it.

  • @rudiklein
    @rudiklein 5 лет назад +5

    You're a great teacher. All of your video's are clear and interesting. Especially for an advanced noob like me.

  • @ichbrauchmehrkaffee5785
    @ichbrauchmehrkaffee5785 2 года назад

    thank you for clearling up, not only how it's done, but also how the convention is

  • @heinrichhelmbold419
    @heinrichhelmbold419 Год назад

    Best tutorial I have seen to date regarding virtual environments, thank you! Unfortunately the wheels keep falling off 😜 Installing libraries I constantly get : "ERROR: Could not build wheels for X" With Linux it's a wormhole of issues and errors... find a solution like virtual environments for one problem, and Linux will open a door to a list of new ones 🤣😂

  • @loudencm
    @loudencm 4 года назад

    Corey...thank you...I have just started the road to data science and one thing I have never had a good simple explain action if were basics of setting up environments without much hassle. I followed this like ABC. I understand what is happening, what to do, how to undo it and how to pass it on.

  • @ighsight
    @ighsight 2 года назад

    Right on time. I usually do Python work in Lambda/Cloud Functions environments so my understanding of setting up projects on the desktop is lacking. I always struggle with setting up projects and getting virtual environments working when I have to code the traditional way. The MacOS transition to the z shell has made it worse. Luckily Corey is my Python guru, problem solved. This is the number one Python channel on RUclips.

  • @leedavies6779
    @leedavies6779 5 лет назад +6

    concise, clear and perfectly delivered. I will be using this a lot from now on.

  • @Ko0lHaNDLuKex
    @Ko0lHaNDLuKex 3 года назад

    As someone coming to Python from another programming language, this was very helpful!

  • @MrKalindro
    @MrKalindro 3 года назад +2

    Yo dude this is like the best guide in this topic

  • @karthickchandrasekaran7284
    @karthickchandrasekaran7284 8 месяцев назад

    Really helped me understand the importance of virtual environment

  • @irisx3375
    @irisx3375 4 года назад +2

    It's like whatever my problems are, you have a solution or tutorial. Thanks soooo much!

  • @oselokaiweka6563
    @oselokaiweka6563 Год назад

    Honestly, Corey is a life saver!

  • @sandeepvk
    @sandeepvk 5 лет назад +15

    I click the like button first and then watch the videos , 'cause i know its gonna be awesome

  • @souravkaranjai6428
    @souravkaranjai6428 4 года назад +1

    Thank you for such an amazing video, You seem to know exactly what your student has in mind and what problems he is trying to solve while watching your videos.

  • @charlesbovalis6591
    @charlesbovalis6591 5 лет назад +1

    Awesome - much simpler than pipenv ... Thank you for posting that video.

  • @RohanKumar-vx5sb
    @RohanKumar-vx5sb 2 года назад

    pretty good idea? bro gotta hand it to you. so clarifying illustrations of venv. thank you for another great tut

  • @RickoDeSea
    @RickoDeSea 2 года назад

    Thank you. I learned Python Virtual Environment Quickly

  • @prabhathkota107
    @prabhathkota107 5 лет назад +7

    -system-site-packages was a good tip 👍

  • @matiascoca
    @matiascoca 5 лет назад +4

    Great videos Corey. Clear and perfect explanation.

  • @lofi_Insomnia_
    @lofi_Insomnia_ 4 года назад

    As a newbie I'm super frustrated by the whole python setup thing cuz Mac has 2 versions of python. It drove me nuts and I found your video -- THANK YOU

  • @omarcruz6326
    @omarcruz6326 3 года назад

    Dear Sir.
    Thanks for the great work !!!
    I was looking for a env tutorial for Mac and this is exactly what I found here !!!
    Great job.
    I give like and ... subscribe !
    Greetings from Belgium.

  • @AdeAderinto
    @AdeAderinto 4 года назад +2

    Simple and straight to the point. Thank you for this. Much appreciated.

  • @jassrajput890
    @jassrajput890 4 года назад

    this is very helpful. thanks very much. i was puzzled from last 4 days OMG. thanks again...

  • @timblichfedlt3984
    @timblichfedlt3984 3 года назад

    Still works - virtual enviroments can be pretty difficult for beginners, thanks for explaining so detailed

  • @suhasramesh2773
    @suhasramesh2773 3 года назад

    Very clear explanation and covers only what is needed, Thanks for this crisp and clear video clip!

  • @ridhamsuhagiya4886
    @ridhamsuhagiya4886 2 года назад

    You use terminal so efficiently amazing

  • @KentBui
    @KentBui 9 месяцев назад

    Amazing video, straight to the point

  • @snehithtampa7106
    @snehithtampa7106 4 года назад +2

    This guy is the dopest guy and I love his videos.

  • @shadow-x1s3c
    @shadow-x1s3c 4 дня назад

    This is exactly what I need, thank you so much.

  • @MawaMaverick
    @MawaMaverick 4 года назад

    Wow. Genius instructor.

  • @einarpersson8257
    @einarpersson8257 4 года назад

    Super clear explanation!

  • @armena2866
    @armena2866 4 года назад +1

    Super thorough! Thank you

  • @DEADPODVAL
    @DEADPODVAL 2 года назад

    Very useful even for people with low knowledge at english) thx 🤙

  • @lauradillon7173
    @lauradillon7173 4 года назад

    Excellent video to explain the basics of virtual environments! Thank you!!

  • @tkadado
    @tkadado Год назад

    thanks for the best explanation I ever seen

  • @Cosmos-g2n
    @Cosmos-g2n 3 года назад

    thanks very much for the simplest explanation !

  • @Naton
    @Naton 5 лет назад +3

    Thanks! I finally got my head around venv...

  • @domleonhardt7943
    @domleonhardt7943 4 года назад

    @corey shafer thanks for the great videos and sharing you knowledge with us. its nice to watch an informative video from someone who speaks clearly;y and is professional and to the point. THANK YOU

  • @kodiak4777
    @kodiak4777 4 года назад

    Incredible videos. Kept answering my questions as he went. Keep up the good work.

  • @winstonyeung1461
    @winstonyeung1461 8 месяцев назад

    Thank you so much. Very clear explanation.

  • @st3114rr
    @st3114rr 3 года назад

    This was so clear, concise, and comprehensive. Thanks so so much!

  • @ritheshjarvis4177
    @ritheshjarvis4177 4 года назад +1

    Super. What exactly is needed.

  • @Ghasakable
    @Ghasakable 5 лет назад +3

    Man! Your channel is awesome
    Keep up with the awesome work

  • @AbhishekKumar-ob1bs
    @AbhishekKumar-ob1bs Год назад

    Great explanation. Thanks it was very helpfull Cory

  • @paulliu6057
    @paulliu6057 2 года назад

    You explained so clearly! Thank you!

  • @vbplayar
    @vbplayar 3 года назад

    I just wanted to comment because I really enjoyed this video and wanted to say thanks for putting it together. Very informative and to the point. Cheers!

  • @twowheelsgood28
    @twowheelsgood28 3 года назад

    Great job Corey. I really appreciate the detailed tutorial.

  • @scottchristesen2660
    @scottchristesen2660 3 года назад

    Exactly what I was looking for. Thank you!

  • @uberacyjunior3613
    @uberacyjunior3613 4 года назад +1

    Thank you. Very well explained!

  • @ignacio2921
    @ignacio2921 3 года назад

    Couldn't have been explained better, thanks!

  • @vamekhbasharuli4585
    @vamekhbasharuli4585 2 года назад

    This video helped me so much, thanks!

  • @Reftsquabble
    @Reftsquabble 3 года назад

    fantastic overview, which is why the like-to-dislike ration is the highest i've ever seen

  • @gyan277
    @gyan277 2 года назад

    THANK YOU SIR! it really helped me out i was trying for very long time

  • @gorg212
    @gorg212 3 года назад

    Very clear explanation! Thanks!

  • @piyushramnani1014
    @piyushramnani1014 3 года назад

    Such a life-saver video. Thanks a lot man

  • @ivanlo7195
    @ivanlo7195 2 года назад

    I need to say I have smashed the like button

  • @aV5d9nlUBQ9
    @aV5d9nlUBQ9 8 месяцев назад

    Very helpful. Thanks, man!

  • @webuilt_america_period5062
    @webuilt_america_period5062 5 лет назад +1

    This was super helpful

  • @nathansonic
    @nathansonic 5 лет назад +1

    Man alive! This is useful

  • @Chuukwudi
    @Chuukwudi 3 года назад

    Thanks man! I love you. You just saved me.

  • @westCOpaintball
    @westCOpaintball 4 года назад +1

    Super helpful, Thank you!

  • @JohnDoe-he6yc
    @JohnDoe-he6yc 4 года назад +1

    great video. thanks!!

  • @fvgoya
    @fvgoya 5 лет назад +1

    Your videos are Awesome! Thanks for sharing your knowledge.

  • @raffaelloringue
    @raffaelloringue Год назад

    great explanation! thanks a lot!

  • @daegudude1048
    @daegudude1048 5 лет назад +1

    Always appreciate your video Corey, Thanks :)

  • @easy_tech_explained
    @easy_tech_explained 11 месяцев назад

    Great tutorial!

  • @wakanayt
    @wakanayt 4 года назад

    Thanks, Corey! Very nicely done!

  • @fabianhaglund5792
    @fabianhaglund5792 4 года назад

    Clarity!
    Thank you

  • @FrancisDivine
    @FrancisDivine 5 лет назад +1

    Thank you Mr CoreyMS

  • @pradeepj8266
    @pradeepj8266 4 года назад

    You are great thalaiva...😎

  • @dalmirog
    @dalmirog 4 года назад

    Love your videos, Mate.

  • @santosharakere
    @santosharakere 4 года назад

    Excellent demo. Thanks.

  • @zolongOne
    @zolongOne 5 лет назад +1

    Thanks for this awesome tutorial. cheers!

  • @kiwiboy8492
    @kiwiboy8492 5 лет назад +1

    Thanks, very helpful stuff...

  • @arturocampos1879
    @arturocampos1879 4 года назад

    Great explanation skills. Thanks!

  • @SheryarZahoor
    @SheryarZahoor Год назад

    3:34 Well explained

  • @lotussymphony
    @lotussymphony 4 года назад

    Thanks for the video, as always is explained perfectly!

  • @bigdaddyped
    @bigdaddyped 3 года назад

    amazing tutorial thank you!

  • @godnyx117
    @godnyx117 4 года назад

    Thanks a lot man! That video was amazing!!

  • @harithm8172
    @harithm8172 4 года назад

    i love the content. pls make use of windows comments too

  • @acrospidey
    @acrospidey 4 года назад

    So clear. Thank you.

  • @calvary1808farm
    @calvary1808farm 5 лет назад

    Just what I needed! Thanks!

  • @kalisz01
    @kalisz01 Год назад

    This is great. One thing I'm not sure about, when you use '--system-site-packages' option, I assume that nothing you do to those packages in the venv affects the system packages. Like testing a package upgrade. Seems obvious but wanted to be sure, lol.

  • @WilliamMastrocola
    @WilliamMastrocola 7 месяцев назад

    Great Video!