Тёмный

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

Corey Schafer
Подписаться 1,4 млн
Просмотров 287 тыс.
50% 1

In this Python Programming Tutorial, we will be learning how to use virtual environments on the Mac and Linux operating systems with the built-in venv module. We will learn how to create them, activate them, remove them, and much more. Let's get started...
VENV (Windows) - • Python Tutorial: VENV ...
✅ Support My Channel Through Patreon:
/ coreyms
✅ Become a Channel Member:
/ @coreyms
✅ One-Time Contribution Through PayPal:
goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
www.amazon.com...
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python #venv

Опубликовано:

 

29 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 236   
@0x007A
@0x007A 3 года назад
The introduction to venv that I was seeking - concise yet complete.
@Rocorama1
@Rocorama1 5 лет назад
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!
@coreyms
@coreyms 5 лет назад
Thanks!
@timothynicholson8231
@timothynicholson8231 4 года назад
Thank you!
@leehaney4390
@leehaney4390 3 года назад
I ended up with this error message when I ran the "sudo apt-get install python3-venv" command: The following packages have unmet dependencies: python3-venv : Depends: python3 (= 3.6.7-1~18.04) but 3.8.2-0ubuntu2 is to be installed E: Unable to correct problems, you have held broken packages.
@leehaney4390
@leehaney4390 3 года назад
Turns out it was a problem with Linux Mint. Had to enable "Unstable packages (romeo)" in the Software Sources->Official Repositories menu
@ruixue6955
@ruixue6955 4 года назад
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
@lofi_Insomnia_
@lofi_Insomnia_ 3 года назад
this is awesome
@viviantomlinson
@viviantomlinson 3 года назад
thank you!!
@kipronoelijahkoech4630
@kipronoelijahkoech4630 4 года назад
You are just too great. Nowadays I search RU-vid with your name I be like "virtual environment in Python Corey Schafer" .
@rafaelalvesduarte4928
@rafaelalvesduarte4928 4 года назад
Simple, direct and well explained. Thanks man, this helped me!
@AllAboutJailbreak
@AllAboutJailbreak 4 года назад
python3 -m venv project_env source project_env/bin/activate deactivate rm rf -project_env/
@abraraltaflone
@abraraltaflone 3 года назад
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!
@pavelow36
@pavelow36 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!
@sandeepvk
@sandeepvk 5 лет назад
I click the like button first and then watch the videos , 'cause i know its gonna be awesome
@MouradMourad1000
@MouradMourad1000 5 лет назад
same for me :)
@sheesh_kebab
@sheesh_kebab 4 года назад
This video explains everything...and then goes beyond! Loved it.
@rudiklein
@rudiklein 5 лет назад
You're a great teacher. All of your video's are clear and interesting. Especially for an advanced noob like me.
@VictorOlet
@VictorOlet 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)
@alexandrostsagkaropoulos
@alexandrostsagkaropoulos Год назад
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 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!
@prabhathkota107
@prabhathkota107 5 лет назад
-system-site-packages was a good tip 👍
@edwardwong654
@edwardwong654 Год назад
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.
@irisx3375
@irisx3375 4 года назад
It's like whatever my problems are, you have a solution or tutorial. Thanks soooo much!
@rohanm4130
@rohanm4130 5 лет назад
Nice video, as always. Which is better to use Anaconda/miniconda or pipenv or venv for virtual environment? I use Anaconda for both virtual environment and as a package manager (and use pip too). Thanks.
@coreyms
@coreyms 5 лет назад
Really it all comes down to preference. If you're using Anaconda then I would recommend staying with that.
@rohansambidi1855
@rohansambidi1855 4 года назад
Please let me know how to change the version of Python in a virtual environment. My system (Mac) has 3.8.1, and I want to use 3.7.8 in the virtual environment. (Because I want to install Turi Create API, which is not yet supported by 3.8 version). Thank you.
@nicklansbury3166
@nicklansbury3166 4 года назад
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'
@leedavies6779
@leedavies6779 5 лет назад
concise, clear and perfectly delivered. I will be using this a lot from now on.
@sakhawatali9481
@sakhawatali9481 4 года назад
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
@MrKalindro
@MrKalindro 3 года назад
Yo dude this is like the best guide in this topic
@jhuliuscastillosuarez3324
@jhuliuscastillosuarez3324 4 года назад
Thanks bro, this was very helpful!!! Everything works well on the console but the IDE (ex. Geany) do not recognize the package installed on the venv. Do you have any tutorial about it?
@matiascoca
@matiascoca 5 лет назад
Great videos Corey. Clear and perfect explanation.
@JohnDoe-he6yc
@JohnDoe-he6yc 4 года назад
great video. thanks!!
@LatinoWebStudio
@LatinoWebStudio Год назад
thanks for the video! I'm trying to use turtle graphics on my venv but I get the following error: ModuleNotFoundError: No module named '_tkinter' Do you know why that's happening? tk is installed and I've installed and uninstalled it several times. Turtle works when the python interpreter is set to global but then none of the packages work. When I set the python interpreter to the venv, the installed packages work but turtle doesn't work.
@NobleSteed00
@NobleSteed00 4 года назад
I keep trying to scroll up in the video to see previous typed commands.
@charlesbovalis6591
@charlesbovalis6591 4 года назад
Awesome - much simpler than pipenv ... Thank you for posting that video.
@robsong6689
@robsong6689 4 года назад
I use asdf. Do i need to do this?
@dejan010
@dejan010 8 месяцев назад
Hy Thanks for the video. You explained it preety good! I have a question, hopefully you can help me. How do i can use the venv environment in my Project? For example: i have a .py file where i would like to import a library from the venv environment. how i can access this library? Thanks in advance for your support!
@jassrajput890
@jassrajput890 3 года назад
this is very helpful. thanks very much. i was puzzled from last 4 days OMG. thanks again...
@ryansanderson7023
@ryansanderson7023 Год назад
Urghh. Virtual environments are so confusing. In another tutorial, to create the env it says to use this command: virtualenv So what command do I use? Corey says to use: python3 -m venv project_env
@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.
@Anonymous-xv4ol
@Anonymous-xv4ol 2 года назад
when i do the 'pip3 list' command, I'm getting a 'bad interpreter: no such file or directory'. Any help? Thanks
@MichaelCampbell01
@MichaelCampbell01 2 года назад
Why would you need to use virtualenv for a different version of python? Only if you want to use a version that predates `venv`, right? You could totally set up a venv based env with python 3.3, and another with 3.8, and another with 3.7, etc. right?
@redpandason
@redpandason 3 года назад
because im constantly forgetting the commands for this and always come back to this video for them (and im sure others are in the same boat): make virtual environment: `python3 -m venv venv` activate the environment: `source venv/bin/activate` kill environment: `deactivate`
@kartikpodugu
@kartikpodugu Год назад
What is the difference between module, package and library in Python? I am confused
@lundebc
@lundebc 10 месяцев назад
So, newbie here, once you create the virtual environment, how do you use what was installed in the venv from the main system. By this I mean I have a program in the main that needs the library I installed in venv. If that environment is active, with my program “see” that library?
@gyan277
@gyan277 2 года назад
THANK YOU SIR! it really helped me out i was trying for very long time
@AndJusTIceForRob
@AndJusTIceForRob 4 года назад
I'm running python 3.8.2., and venv was not part of the standard library. I had to install it separately.
@saifeddinemahmoudi1138
@saifeddinemahmoudi1138 4 года назад
when I do pip list in my virtualenv I can see all my system python packages, please help
@nolevel433
@nolevel433 2 года назад
when I install matplotlib for example, I always get the message that there is no module like matplotlib. I don't know why this happens
@RickoDeSea
@RickoDeSea 2 года назад
Thank you. I learned Python Virtual Environment Quickly
@snehithtampa7106
@snehithtampa7106 4 года назад
This guy is the dopest guy and I love his videos.
@RAJASEKARCMR
@RAJASEKARCMR Год назад
this solves one doubt, but i have pyenv, i can use the same requirements.txt and other methods with pyenv and not rely on venv at all right?
@haneulkim4902
@haneulkim4902 3 года назад
Hi Corey, is venv for python packages only? so if I download docker on venv it will only be downloaded inside venv or globally?
@fightingfaito
@fightingfaito Год назад
everything works perfectly, but when I run "pip list" in the venv it still lists all my libraries :/
@NetScalerTrainer
@NetScalerTrainer Год назад
Is there a summary of the “venv commands” and their usage document somewhere?
@AbhishekKumar-ob1bs
@AbhishekKumar-ob1bs Год назад
Great explanation. Thanks it was very helpfull Cory
@Ghasakable
@Ghasakable 5 лет назад
Man! Your channel is awesome Keep up with the awesome work
@ccall48
@ccall48 4 года назад
Hey mate, A little bit unrelated, but how do I set up my Mac terminal to be as clean as yours? So I get the colours and the prompt under the working directory? Hopefully I work it out, as I've only had a MacBook for a few days ;)
@_boris
@_boris 4 года назад
Did you find a way to do it? I'm looking for the same thing, looks so neat and clean
@AeRUBIKCubing
@AeRUBIKCubing 4 года назад
@@_boris I suggest looking into ZSH and iTerm2
@timheller7014
@timheller7014 4 года назад
Late reply but might help someone else: He has videos on this search his channel directly ;) I did mine the same, it's amazing
@winstonyeung1461
@winstonyeung1461 5 месяцев назад
Thank you so much. Very clear explanation.
@chevvvv
@chevvvv 5 месяцев назад
so it's basically like node_modules and package.json
@karthickchandrasekaran7284
@karthickchandrasekaran7284 4 месяца назад
Really helped me understand the importance of virtual environment
@soype
@soype 3 года назад
Why would you use a venv if you're not planning on using a different python version than the current one. Geez.
@petraschubert8220
@petraschubert8220 3 года назад
I haven't installed python yet on Linux. How to proceed?
@uberacyjunior3613
@uberacyjunior3613 4 года назад
Thank you. Very well explained!
@jeremytanwm
@jeremytanwm 4 года назад
Hi great video but does it work with jupyter notebook as well? thanks!
@DEADPODVAL
@DEADPODVAL 2 года назад
Very useful even for people with low knowledge at english) thx 🤙
@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
@ritheshjarvis4177
@ritheshjarvis4177 4 года назад
Super. What exactly is needed.
@joelprestonsmith
@joelprestonsmith Год назад
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.
@Naton
@Naton 5 лет назад
Thanks! I finally got my head around venv...
@Nricaldi380
@Nricaldi380 3 года назад
how do I change the version of python inside my virtual environment?
@dylanokyere4486
@dylanokyere4486 Год назад
Do you put the requirements.txt within the venv directory?
@CristianHeredia0
@CristianHeredia0 5 лет назад
With venv where do you put environment variables?
@kevincannon2269
@kevincannon2269 3 года назад
fantastic overview, which is why the like-to-dislike ration is the highest i've ever seen
@Gauravjin
@Gauravjin 2 года назад
how to find a virtual environment that already exists in mac?
@souravkaranjai6428
@souravkaranjai6428 4 года назад
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.
@AdeAderinto
@AdeAderinto 4 года назад
Simple and straight to the point. Thank you for this. Much appreciated.
@aV5d9nlUBQ9
@aV5d9nlUBQ9 4 месяца назад
Very helpful. Thanks, man!
@chanwoopark5397
@chanwoopark5397 Год назад
python3.x -m venv project_name
@heinrichhelmbold419
@heinrichhelmbold419 9 месяцев назад
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 🤣😂
@Chuukwudi
@Chuukwudi 3 года назад
Thanks man! I love you. You just saved me.
@kiwiboy8492
@kiwiboy8492 5 лет назад
Thanks, very helpful stuff...
@daegudude1048
@daegudude1048 5 лет назад
Always appreciate your video Corey, Thanks :)
@PawanMusing
@PawanMusing 4 года назад
Nice explanation good for novice people like me. I'm using pyspark with python 3.6 and try to create venv as per this video that works fine but when i try to instantiate pyspark it throws error like below Python in worker has different version 2.7 than that in driver 3.6, PySpark cannot run with different minor versions.Please check environment variables PYSPARK_PYTHON and PYSPARK_DRIVER_PYTHON are correctly set. Any help would be appreciated
@westCOpaintball
@westCOpaintball 4 года назад
Super helpful, Thank you!
@Dani-si8ie
@Dani-si8ie 3 года назад
I'm coming from iOS and Swift and this is quite similar to CocoaPods for example, however, we don't need virtual env and you generally have 1 version of (stable) Swift, so that's making it a bit harder to grasp about Python
@prashantpathak3175
@prashantpathak3175 4 года назад
Hello, I hope you are doing great... Actually, I need your's or anyone's help to understand how in Python an Object Holds millions of list items without consuming memory. I mean an object holds a lot of elements of list/tuples but takes very less memory and it only shows those elements when we call list/tuple(OBJ_NAME). What happens in the background when we call list () on these objects? Please help
@vamekhbasharuli4585
@vamekhbasharuli4585 2 года назад
This video helped me so much, thanks!
@falconX5000
@falconX5000 4 года назад
Can I store my project files outside my virtual environment folder. e.g. I want to make a web-app using flask and I made my virtual environment folder in ~/documents, so can I store my flask app and my HTML templates on desktop.( Linux )
@lofi_Insomnia_
@lofi_Insomnia_ 3 года назад
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
@haneulkim4902
@haneulkim4902 3 года назад
Thanks Corey, if I have python 2.7 and 3.6 on global environment it depends on which python version I use to create venv and for both of them I would just use python, pip command?
@optimisticblackorange
@optimisticblackorange 4 года назад
Thanks for the vid Corey, I followed and create a venv using the --system-site-packages command, but inside the new venv my global packages aren't there, I have tried a couple of time but the same result prevailed. Any idea? I am using python 3.8.5. thanks for the vid again!
@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 RU-vid.
@TirsoMenesesRojas
@TirsoMenesesRojas 5 лет назад
Hello, I can't execute "pip3 list" command if there isn't and active virtual environment, system ask for an active virtual environment. There is somebody that can help me to solve this issue. I use Ubuntu 18.04.3. Thanks in advance.
@invisiblevfx
@invisiblevfx Год назад
can you make a video on how this works with wsgi?
@Juan_deep
@Juan_deep 5 лет назад
Hey Corey, I have 2 versions of python executable /bin/python and /bin/python3 I checked and they’re both the same version just not sure if this makes a difference? My Django site packages is in version 3.6
@catznik3
@catznik3 3 года назад
Assuming you have multiple versions installed on your base system such as 3.6, 3.7, and 3.9, you can easily use any of these in the virtual environment. E.g., $ python3.6 -m venv project_env to create a virtual env. with python 3.6
@fvgoya
@fvgoya 5 лет назад
Your videos are Awesome! Thanks for sharing your knowledge.
@ulfgj
@ulfgj 4 года назад
but... i thought u moved to pipenv, corey....
@Krutchhh
@Krutchhh 2 года назад
i get a no such file or directory project_env/bin/acivate. have it the same way in the desktop
@preritdas6998
@preritdas6998 2 года назад
Great video! How do you move virtual environments between Linux and Mac, ex. If projects are stored in Dropbox?
@charlesspringer4709
@charlesspringer4709 3 года назад
What is your shell? I like the way to lays out your path.
@KentBui
@KentBui 6 месяцев назад
Amazing video, straight to the point
@abhiraj533
@abhiraj533 3 года назад
That's a great video for virtual env using Python i was looking for .. Although i have 1 question, if i am running py3 in venv & py2 globally .. is there any chance of disruption between these 2 version of python .. Like do we need to set any other environment variable to avoid any conflict.
Далее
▼ КАПИТАН НАШЁЛ НЕФТЬ В 🍑
33:40
Просмотров 384 тыс.
Watermelon magic box! #shorts by Leisi Crazy
00:20
Просмотров 27 млн
The Complete Guide to Python Virtual Environments!
15:52
Python Virtual Environment and pip for Beginners
30:39
Virtual Environments in Python - Crash Course
13:33
Просмотров 94 тыс.
▼ КАПИТАН НАШЁЛ НЕФТЬ В 🍑
33:40
Просмотров 384 тыс.