virtualenv vs. venv (beginner - intermediate) anthony explains

Поділитися
Вставка
  • Опубліковано 26 тра 2020
  • 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 2 роки тому +2

    always wondered whats the difference and thank you so much for this video, very informative

  • @jamescowling4559
    @jamescowling4559 3 роки тому +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.

  • @Tech-Dev
    @Tech-Dev 2 роки тому

    Cheers Anthony for the clarification - virtualenv & venv.

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

    DUDE!! I WAS SOO CONFUSED BEFORE WATCHING THIS!! THANK YOU MY MAN!! YOU GOT A SUB!

  • @bgable7707
    @bgable7707 3 роки тому +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.

  • @jamesmunroe6558
    @jamesmunroe6558 Рік тому

    Thanks for this, Anthony... another great video.

  • @SouhaibD
    @SouhaibD 3 роки тому +1

    Perfect explanation man. Thanks!

  • @brpawankumariyengar4227
    @brpawankumariyengar4227 3 роки тому +1

    Awesome video ....Thank you very much for posting

  • @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 :)

  • @kylespanish2es
    @kylespanish2es 3 роки тому +9

    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 роки тому +11

      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: ua-cam.com/video/OXmYKh0eTQ8/v-deo.html ua-cam.com/video/O390_abzo08/v-deo.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 роки тому +2

      @@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 :)

  • @RodrigoStuchi
    @RodrigoStuchi 4 роки тому +1

    very helpful, thanks 👏👌

  • @tejasness
    @tejasness 3 роки тому +2

    Thank you so much

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

    Nice video!

  • @sau002
    @sau002 Рік тому

    Nice. Always wondered about this.

  • @mackhinastation
    @mackhinastation 3 роки тому +1

    Really clean explanation! Thanks for making the video!

  • @kpsthakur
    @kpsthakur Рік тому

    Can they work in background as a service or a normal application? And probably run using cronjob?

  • @JJSogaard
    @JJSogaard 3 роки тому +4

    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 роки тому +1

      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

  •  4 роки тому +2

    😎 cool topic

  • @optimiserlenergie1094
    @optimiserlenergie1094 3 роки тому +3

    You can have several venv activated at the same time on different folders right ?

    • @anthonywritescode
      @anthonywritescode  3 роки тому +1

      you can have multiple on PATH but usually activating a venv by its activate script will deactivate the others

  • @apdy27
    @apdy27 4 роки тому +3

    switching to virtualenv!

  • @programadordelassombras
    @programadordelassombras 11 місяців тому

    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  11 місяців тому +1

      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

  • @thomasc9036
    @thomasc9036 3 роки тому +1

    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: ua-cam.com/video/ngLwml9XI-I/v-deo.html

  • @user-wr4yl7tx3w
    @user-wr4yl7tx3w Рік тому

    Does it make multiple copies of the packages in the directory? Is there a way to minimize that?

  • @danielcorrea2396
    @danielcorrea2396 4 роки тому +1

    @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 роки тому +1

      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 роки тому +2

      you can't though, you need the venv module available in every python version

  • @diegoalejandrocortessuarez3758
    @diegoalejandrocortessuarez3758 3 роки тому +1

    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 роки тому +1

      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 роки тому +1

      I use my own text editor that I wrote -- though I wouldn't really recommend it hahah ua-cam.com/video/WyR1hAGmR3g/v-deo.html

  • @CheapHomeTech
    @CheapHomeTech 3 роки тому +2

    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 роки тому +2

      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: ua-cam.com/video/O390_abzo08/v-deo.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 роки тому +2

      I've never had a use case for talking across virtualenvs so I don't even know what I'd talk about!

  • @essamgouda1609
    @essamgouda1609 2 роки тому +1

    How do you access windows cmd directly from Ubuntu ?

  • @philiplitmanov7531
    @philiplitmanov7531 3 роки тому +5

    why don't you like conda?

    • @anthonywritescode
      @anthonywritescode  3 роки тому +7

      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 роки тому +1

    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

  • @tonychia3824
    @tonychia3824 Рік тому

    Are you running windows 11 with ubuntu subsytem?

    • @anthonywritescode
      @anthonywritescode  Рік тому

      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 3 роки тому +1

    A year+ later do you still prefer virtualenv over venv?

    • @anthonywritescode
      @anthonywritescode  3 роки тому +3

      yep!

    • @Toksicboy
      @Toksicboy 3 роки тому

      @@anthonywritescode thx, was curious as I delve into this side of Python.

  • @GOZES
    @GOZES 3 роки тому +1

    Though on pipenv?

    • @anthonywritescode
      @anthonywritescode  3 роки тому +1

      it's slow and I think it's unnecessary -- and I avoid software written by the original author on principle

  • @beat461
    @beat461 2 роки тому +1

    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 роки тому +1

      it's just a directory name -- and they do do the same thing

  • @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

  • @talalkalai8748
    @talalkalai8748 2 роки тому +1

    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

  • @realsushi_official1116
    @realsushi_official1116 Рік тому

    Having 2 packages managers with the very same name is soooo confusing from a beginner point of view

  • @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!

  • @RedShipsofSpainAgain
    @RedShipsofSpainAgain Рік тому +1

    Tl,DR: just use virtualenv, not venv.

  • @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 роки тому +1

    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 `