virtualenv vs. venv (beginner - intermediate) anthony explains

  Рет қаралды 40,679

anthonywritescode

anthonywritescode

4 жыл бұрын

today I explain the basics of virtualenv / venv and why you should use them! I also compare / contrast venv and why I tend to pick virtualenv
playlist: • anthony explains
==========
twitch: / anthonywritescode
dicsord: / discord
twitter: / codewithanthony
github: github.com/asottile
stream github: github.com/anthonywritescode
I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like to see please comment below!

Пікірлер: 86
@bulelanibotman
@bulelanibotman Жыл бұрын
always wondered whats the difference and thank you so much for this video, very informative
@Tech-Dev
@Tech-Dev 2 жыл бұрын
Cheers Anthony for the clarification - virtualenv & venv.
@SouhaibD
@SouhaibD 3 жыл бұрын
Perfect explanation man. Thanks!
@shivanshmishra7992
@shivanshmishra7992 4 ай бұрын
DUDE!! I WAS SOO CONFUSED BEFORE WATCHING THIS!! THANK YOU MY MAN!! YOU GOT A SUB!
@jamesmunroe6558
@jamesmunroe6558 Жыл бұрын
Thanks for this, Anthony... another great video.
@jamescowling4559
@jamescowling4559 3 жыл бұрын
Cheers mate! This really helped a lot, didn't know about virtual environments before this week... My Python setups were pretty much configured in all the ways you should NOT set up Python and in hindsight they were really quite hideous hah. With this knowledge things are miles better now, I managed to use the knowledge gained in this video to overcome an issue that has been causing me so much grief for the last 3 days. Really appreciate the help.
@brpawankumariyengar4227
@brpawankumariyengar4227 3 жыл бұрын
Awesome video ....Thank you very much for posting
@kylespanish2es
@kylespanish2es 3 жыл бұрын
Great video, so helpful to just have all of this laid out in a straightforward manner. Also in general recently discovered your channel and twitch, can't tell you how useful it's been! Two questions I quickly had: 1. Do you have any practices around storing / keeping track of virtual environments? 2. For python versions, does is virtualenv natively ship with all python versions? Or do you need to download each python that you want to create virtual environments with?
@anthonywritescode
@anthonywritescode 3 жыл бұрын
good questions! glad you enjoy the content :) (1) on my system I ~usually follow this: - I have one at ~/opt/venv where I store tools I use (more details in these videos: kzfaq.info/get/bejne/hb6djK6Zlcu4gWw.html kzfaq.info/get/bejne/hZlpY8KSx-DTYGw.html ) -- I then symlink those tools into ~/bin so they're "globally" available (things like my text editor, pre-commit, and actually virtualenv too!) - then I make virtualenvs per-project at ./venv (sometimes ./venv2 or ./venv39 if I need to have ones versioned based on the python version) (2) virtualenv needs the pythons available _somewhere_ to work. I use deadsnakes (launchpad.net/~deadsnakes/+archive/ubuntu/ppa which I maintain!) to install pythons on ubuntu. on other platforms you'd probably use either the python.org installers or something like pyenv (though pyenv is very difficult to get correct in my opinion)
@kylespanish2es
@kylespanish2es 3 жыл бұрын
@@anthonywritescode Thank you so much for this info - I'm realizing how important it is to get to know the file structure on your OS :)
@bgable7707
@bgable7707 3 жыл бұрын
Cool, for someone relatively new to Python's virtual env, this sort of helped. Good to know that the virtualenv, has some advantages over the newer venv. So, it appears that knowing/using both would be good and not just abandoned virtualenv altogether. I appreciate your taking the time to make these videos and I'm sure you want to do the best with them. So, don't take this the wrong way, but, it would be helpful if you could slow down or meter your speech more. I struggled understanding some of your descriptions. I found CC did too.
@anthonywritescode
@anthonywritescode 3 жыл бұрын
you can always watch in .75 if you need it slower!
@kosnowman
@kosnowman 2 жыл бұрын
Great explanation!
@jackfrankmurphy
@jackfrankmurphy Жыл бұрын
You have a really nice persona, and thank you for your explanation. I shall look for other explanations from you :)
@RodrigoStuchi
@RodrigoStuchi 4 жыл бұрын
very helpful, thanks 👏👌
@tejasness
@tejasness 3 жыл бұрын
Thank you so much
@sau002
@sau002 Жыл бұрын
Nice. Always wondered about this.
@mackhinastation
@mackhinastation 3 жыл бұрын
Really clean explanation! Thanks for making the video!
@BooklyCrashCourse
@BooklyCrashCourse 3 ай бұрын
Nice video!
@thomasc9036
@thomasc9036 3 жыл бұрын
How did you set your directory and prompt in two different lines? It's really cool!!!
@anthonywritescode
@anthonywritescode 3 жыл бұрын
I go over my PS1 in this video: kzfaq.info/get/bejne/pM18qtCdnr6tXX0.html
@kpsthakur
@kpsthakur 10 ай бұрын
Can they work in background as a service or a normal application? And probably run using cronjob?
@apdy27
@apdy27 4 жыл бұрын
switching to virtualenv!
@optimiserlenergie1094
@optimiserlenergie1094 3 жыл бұрын
You can have several venv activated at the same time on different folders right ?
@anthonywritescode
@anthonywritescode 3 жыл бұрын
you can have multiple on PATH but usually activating a venv by its activate script will deactivate the others
@diegoalejandrocortessuarez3758
@diegoalejandrocortessuarez3758 3 жыл бұрын
i`ve been seeing a lot of videos, could you recommend me what should i choose, a ide like jupyter, or a text editor like vscode? im starting to study seriously data science and this is an important step for me haha
@anthonywritescode
@anthonywritescode 3 жыл бұрын
whatever you're most comfortable with! they both have trade offs (and I actually don't use either of them so I can't really make a recommendation)
@diegoalejandrocortessuarez3758
@diegoalejandrocortessuarez3758 3 жыл бұрын
@@anthonywritescode what you use then?
@anthonywritescode
@anthonywritescode 3 жыл бұрын
I use my own text editor that I wrote -- though I wouldn't really recommend it hahah kzfaq.info/get/bejne/jd-CZMtyrNO2Y5s.html
4 жыл бұрын
😎 cool topic
@JJSogaard
@JJSogaard 3 жыл бұрын
By the way, you can also use Poetry to manage your environments. It works great and I think is has a relatively fast dependancy manager. And if you want you project to becoma a Pip package, Poetry makes that process extremely easy.
@anthonywritescode
@anthonywritescode 3 жыл бұрын
my 2c is that poetry is unnecessary. it doesn't add anything for libraries and it's merely a convenience for applications. it's just as much if not more work to distribute something to pypi with poetry. and maybe it's changed but last time I tried poetry I encountered 5 bugs in the first 5 minutes using it which definitely did not instill confidence
@user-wr4yl7tx3w
@user-wr4yl7tx3w Жыл бұрын
Does it make multiple copies of the packages in the directory? Is there a way to minimize that?
@anthonywritescode
@anthonywritescode Жыл бұрын
who cares, disk is functionally free in 2022
@programadordelassombras
@programadordelassombras 10 ай бұрын
Excellent! I know it's years later, but this was a very good succinct explanation! I do have some additional questions. If I built a Django project using system python packages instead of in a virtual environment, how do I move my Django project into a virtual environment to isolate it? Is it as simple as copying or moving the Django project directory into the same directory that contains the virtual env folder?
@anthonywritescode
@anthonywritescode 10 ай бұрын
you should be able to make (and activate) a virtualenv anywhere! -- I usually work on code in a ~/workspace/(repo) directory and put my virtualenv for the particular project inside the repository directory
@danielcorrea2396
@danielcorrea2396 4 жыл бұрын
@anthonywritescode 9:54 It's actually possible to create virtualenvs in other Python versions using Venv only: In windows you type in cmd: python -{version you want to create the virtualenv in} -m vevn {name of your virtualenv} for example you can say: python -3.5 -m -venv -THIS_IS_A_VIRTUALENV_IN_PYTHON35 and it'll create a virtualenv in python 3.5 (you have to add python 3.5 pip to Env Variables before) idk if that works with python 2 also, I don't use it either
@anthonywritescode
@anthonywritescode 4 жыл бұрын
that's not actually cross version, py -3.5 *is* python3.5 (and there's no venv module in python 2)
@danielcorrea2396
@danielcorrea2396 4 жыл бұрын
@@anthonywritescode Yes, Virtualenv is still more uselful, I just wanted to say that you can use different 3.x python versions with venv
@anthonywritescode
@anthonywritescode 4 жыл бұрын
you can't though, you need the venv module available in every python version
@CheapHomeTech
@CheapHomeTech 3 жыл бұрын
I'm actually quite confused. Are you to install a virtualenv for every program you write? What do you do if you want your apache server to run the script? It is not going to be using virtualenv. How do you get one program written in one virtualenv to work with another program needing a different virtualenv? How does docker integrate with it all?
@anthonywritescode
@anthonywritescode 3 жыл бұрын
yeah I generally use a separate virtualenv for every project that I set up. I install all the tools I need for that project into the project's virtualenv. As for the apache usecase, at least with mod-wsgi the recommended setup is to use `WSGIPythonHome` or `python-home` setting to point at your virtualenv. you usually don't need to talk across-virtualenvs -- usually you'd install all the tools you need for the project. docker doesn't really play into this, though I still recommend using a virtualenv in docker: kzfaq.info/get/bejne/hZlpY8KSx-DTYGw.html
@CheapHomeTech
@CheapHomeTech 3 жыл бұрын
@@anthonywritescode i was working hard learning python. It was all going well and I was happy thinking I'd be finished by now. Then things went south due to python interdependencies. So I built a new PC, installed a new os. Now always running with virtualbox. Cloning regularly. Still I'm scared of python going bad on me again. So i want everything in virtualenvs. But in the future I suspect I'll need virtualenvs talking to others. Do you have any videos showing how to package them up and talk to each other?
@anthonywritescode
@anthonywritescode 3 жыл бұрын
I've never had a use case for talking across virtualenvs so I don't even know what I'd talk about!
@tonychia3824
@tonychia3824 11 ай бұрын
Are you running windows 11 with ubuntu subsytem?
@anthonywritescode
@anthonywritescode 11 ай бұрын
I'm using a virtual machine -- there's a video on my channel of setting up virtualbox and another in the faq playlist of why I do it this way!
@Toksicboy
@Toksicboy 2 жыл бұрын
A year+ later do you still prefer virtualenv over venv?
@anthonywritescode
@anthonywritescode 2 жыл бұрын
yep!
@Toksicboy
@Toksicboy 2 жыл бұрын
@@anthonywritescode thx, was curious as I delve into this side of Python.
@philiplitmanov7531
@philiplitmanov7531 3 жыл бұрын
why don't you like conda?
@anthonywritescode
@anthonywritescode 3 жыл бұрын
it's very convenient for installing complicated sciency things, but breaks a lot of expectations for how python usually works -- especially on windows. it's also very very heavy
@RajeshSingh-jh6bl
@RajeshSingh-jh6bl 2 жыл бұрын
This video left me more confused on which one is recommended to be used.
@anthonywritescode
@anthonywritescode 2 жыл бұрын
I mean, I intentionally did not give a decision but left you to decide based on the tradeoffs -- I use virtualenv myself but there's reasons to use venv as well
@beat461
@beat461 2 жыл бұрын
this tutorial became a bit confusing because you are explaining the difference between two different tools that kind of do the same thing, and where the thing that they create is referenced by the same name as one of those tools
@anthonywritescode
@anthonywritescode 2 жыл бұрын
it's just a directory name -- and they do do the same thing
@essamgouda1609
@essamgouda1609 2 жыл бұрын
How do you access windows cmd directly from Ubuntu ?
@anthonywritescode
@anthonywritescode 2 жыл бұрын
eheh -- it's a virtual machine: kzfaq.info/get/bejne/brGUdNSdqrm1eqM.html
@essamgouda1609
@essamgouda1609 2 жыл бұрын
much appreciated
@GOZES
@GOZES 3 жыл бұрын
Though on pipenv?
@anthonywritescode
@anthonywritescode 3 жыл бұрын
it's slow and I think it's unnecessary -- and I avoid software written by the original author on principle
@talalkalai8748
@talalkalai8748 2 жыл бұрын
can u upload a video about pyenv?
@anthonywritescode
@anthonywritescode 2 жыл бұрын
I've talked a few times about pyenv on stream -- I don't recommend it personally because it is really easy to miscompile python
@talalkalai8748
@talalkalai8748 2 жыл бұрын
​@@anthonywritescode​what about pipenv?
@anthonywritescode
@anthonywritescode 2 жыл бұрын
I don't use it on principle and don't recommend others use it as well
@talalkalai8748
@talalkalai8748 2 жыл бұрын
@@anthonywritescode why
@anthonywritescode
@anthonywritescode 2 жыл бұрын
it's slow, clunky, and I won't use software by the original author unless absolutely necessary
@user-wr4yl7tx3w
@user-wr4yl7tx3w Жыл бұрын
How about pyenv?
@anthonywritescode
@anthonywritescode Жыл бұрын
pyenv is completely unrelated, and has wasted thousands of hours of my time. I do not recommend it as it's difficult to build python from source and it does not help you enough to build quality executables
@realsushi_official1116
@realsushi_official1116 Жыл бұрын
Having 2 packages managers with the very same name is soooo confusing from a beginner point of view
@RedShipsofSpainAgain
@RedShipsofSpainAgain Жыл бұрын
Tl,DR: just use virtualenv, not venv.
@monoham1
@monoham1 Жыл бұрын
but how do you use conda with 6 different versions of python at once? how does no one mention this? conda can't handle different versions of python! why doesn't it work with this!
@anthonywritescode
@anthonywritescode Жыл бұрын
easy: I don't use conda
@umuterdogan5735
@umuterdogan5735 Жыл бұрын
Hi. I guess you made a wrong statement at 9:28. You probably wanted to say. The advantage of virtualenv to venv is it works with python 2. It confuses because you started arguing about benefits of venv over virtualenv. Thx anyway for this comparison.👍
@anthonywritescode
@anthonywritescode Жыл бұрын
??? this is what's at that timestamp in the video: "the other advantage, well we saw the speed advantage before, the other advantage to virtualenv is it works with python 2"
@umuterdogan5735
@umuterdogan5735 Жыл бұрын
@@anthonywritescode OK. I guess it was my bad. The english grammar of "advantage to virtualenv" sounded wrong to me and let me misunderstood you. English prepositions are confusing me. I would have used "[...] advantage of virtualenv [...]", but I am a non-native speaker. Sorry!
@mstevensn50
@mstevensn50 Жыл бұрын
anything on microcrash is annoying
@raygllisse4915
@raygllisse4915 3 жыл бұрын
Hi, thanks for this clear video. I must be missing something about venv anyway as I still can't import google.cloud module. To install python3.10, I did: adding sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update sudo apt install python3.10 I installed venv: python3.10 -m venv venv Then in directory containing venv: . venv/bin/activate and once activated , I ran python3.10 -m pip install google.cloud and also python3.10 -m pip install google Installation of google.cloud semt ok Nevertheless when I run the following script ( venv still activated ) #!/usr/bin/python3.10 from google.cloud import bigquery # Construct a BigQuery client object. client = bigquery.Client() I get the following error message: Traceback (most recent call last): File "/home/ced/bigquery-gcloud/./survival_frequency", line 2, in from google.cloud import bigquery ModuleNotFoundError: No module named 'google' Also changed the shebang to #!/usr/bin/env python, but it doesn't solve the issue. Thanks for your help
@raygllisse4915
@raygllisse4915 3 жыл бұрын
actually, looking directly in env/lib/python3.10/site-packages/google_cloud-0.34.0.dist-info/METADATA, it is said that this package doesn't install anything after june 2018 and that it is necessary to get packages directly from other sources. On pypi, the google.cloud package supports python version
@anthonywritescode
@anthonywritescode 3 жыл бұрын
it might still work if you install it -- iirc the gcp packages were split up so you have to install the specific apis you need for whatever specific service
@raygllisse4915
@raygllisse4915 3 жыл бұрын
@@anthonywritescode Indeed, it's necessary to install separately the needed APIs, and in fact, google-cloud-bigquery 2.16.0, the latest one, supports python versions from 3.6 to 3.9 included and not python 3.10 as stated on pypi.org . Do you know other way to install it in simple way using python3.10 ?
@anthonywritescode
@anthonywritescode 3 жыл бұрын
looks like they set `python_requires` to be unnecessarily restrictive -- I'd suggest making an issue on their repository asking them to relax that (the best practice is to only have `>=` and not `
how do virtualenvs actually work (advanced) anthony explains #522
16:55
anthonywritescode
Рет қаралды 7 М.
МАМА И STANDOFF 2 😳 !FAKE GUN! #shorts
00:34
INNA SERG
Рет қаралды 2,7 МЛН
THEY WANTED TO TAKE ALL HIS GOODIES 🍫🥤🍟😂
00:17
OKUNJATA
Рет қаралды 2 МЛН
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 56 МЛН
Tom & Jerry !! 😂😂
00:59
Tibo InShape
Рет қаралды 49 МЛН
my python project setup (+ all tools) (intermediate) anthony explains #396
31:38
Python Virtualenv vs Venv - side by side comparison
0:54
Red Eyed Coder Club
Рет қаралды 7 М.
why I will never use python-poetry
9:09
anthonywritescode
Рет қаралды 54 М.
how should I organize my project? (beginner) anthony explains #506
10:02
anthonywritescode
Рет қаралды 12 М.
py-spy saved our python 3.11 rollout (intermediate) anthony explains #568
13:48
new 3.12 f-strings syntax! (intermediate) anthony explains #562
5:52
anthonywritescode
Рет қаралды 6 М.
WWDC 2024 Recap: Is Apple Intelligence Legit?
18:23
Marques Brownlee
Рет қаралды 6 МЛН
Секретный смартфон Apple без камеры для работы на АЭС
0:22
APPLE совершила РЕВОЛЮЦИЮ!
0:39
ÉЖИ АКСЁНОВ
Рет қаралды 3,6 МЛН
Мечта Каждого Геймера
0:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 1,7 МЛН
i like you subscriber ♥️♥️ #trending #iphone #apple #iphonefold
0:14