Це відео не доступне.
Перепрошуємо.

DO NOT FORGET: 'requirements.txt' In Your Python Projects

Поділитися
Вставка
  • Опубліковано 30 січ 2023
  • In this lesson I will be showing you the benefits of providing a 'requirements.txt' file in your Python projects, and how to use it. DO NOT FORGET this simple file, it will make your code much more convenient to share!
    ▶ Become job-ready with Python:
    www.indently.io
    ▶ Follow me on Instagram:
    / indentlyreels

КОМЕНТАРІ • 41

  • @uquantum
    @uquantum 15 днів тому +1

    Clear, useful and helpful: 'pip install pipreqs' for a clean, bare-essential module installation for the project, without all the other stuff. Thanks!

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

    I've seen a lot of python tutorials over the last few years. But yours are simply the best out there!

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

      I appreciate that, thank you :)

  • @azr6767
    @azr6767 Рік тому +3

    dude i really dont know how i came across your videos...but i am glad i did. Your videos are not the standard python videos 'how to write hello world' but they are USEFUL in the real world and explain all the things that there were never explained. People like me were just forced to pick up these habits of making a requirements,txt files....or writing a main function without knowing why. Thank you so much for these niche videos and really useful packages!

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

    Sir, just want to say thank you that you save my life. I was a beginner on python and I don't know how to update the requirement.txt but your video help a lot.

  • @vietnguyen2354
    @vietnguyen2354 Рік тому +6

    Great video. I'm glad I'm not blindly copying and pasting commands anymore.

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

      Yeah, it's always such a relief and simultaneously disappointment-at-yourself every time you find out something like this which saves you a solid 10 minutes each time you download something

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

    At last someone who really put it in step by step!!! Thanks!

  • @Chalisque
    @Chalisque Рік тому +3

    Something I do on import statements for any modules not in the standard library is to add a comment with the pip command line used to install it: e.g.
    from Crypto import SHA256 # python -m pip install pycryptodome
    from colors import turnip # python -m pip install ansicolors
    and so on. Then I can recursively grep for lines matching 'import.*#' to get a list of the modules required (piped through a quick script to remove duplicates)

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

      I should add that I write a lot of self-contained convenience scripts (that is, if your total 'project' is only a few hundred lines at most, it makes sense to have it as a single self-contained script, rather than a full blown project factored into separate files with a build system and such).

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

      I suggest for getting rid of duplicates adding those lines to a txt file (or comment, as most IDEs mess up lines you don't want to, like deleting that which you don't need", or lag slightly). So for
      import x
      import y
      I'd encapsulate lines with quotes, put commas between them (use ^ and $ regexes or
      if ends of strings don't work for some reason), and add them to a set.
      With:
      "from x import y, z", you may match it with
      "(?>from (\w+) )?import (\w+)(, \w+)?(, \w+)?(, \w+)?(, \w+)?" ...
      and replace it with:
      import $1.$2

      import $1.$3

      import $1.$4

      import $1.$5

      ...
      I'm not familiar with incremented captured groups in pure regex (without using an inside Python/programming language) to capture "(?>from (\w+) )import(?>,? (\w+))*(?>\s*#.*)?" where you would write, given that we found re.findall(ptr, pos_dup_import_lines):
      lib = [] # whole library
      mods = [] # modules in a library, tho I think this is wrong naming
      for m in re.findall(ptr, pos_dup_import_lines):
      lib = m.group(1)
      mods = m.group(2)
      for mod in mods:
      import_lines = print( f"import {lib}.{mod}" )
      Must repeat this for every line. So you'd get like:
      "import my_lib_1.my_mod_1"
      "import my_lib_1.my_mod_2"
      "import my_lib_1.my_mod_3"
      As we ignored last group (with the comment) from being included in the print statement (tho I think last group is unnecessary), we'd not have comment lines producing multiple _duplicate_ import statement. What I mean is:
      "import my_lib_1.my_mod_1"
      "import my_lib_1.my_mod_1 # my_mod_1 is needed"
      are by definition two distinct strings, but for our purposes, they're practically duplicates.
      use $ regex to append a comma, make a list of those strings, add to a set, add to a list again, sort it, print it.
      Now, repeatedly, replace:
      "from (\w+) import ((?>\w+)(?>, \w+)*)

      from \1 import (\w+)"
      With:
      "from $1 import $2, $3"
      The \1 ensures we match the exact library, and not just merge lines arbitrarily.
      It seems obvious, but I hope someone finds this helpful.

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

    Hi, thanks a lot for your video! This is exactly that I tried to find for my projects setup! Awesome! Thanks!

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

    Qst: how do you handle different python versions? Do you need to have separate requirements.txt file for each python version that you use ?

  • @Badrovic-ti6pq
    @Badrovic-ti6pq 10 місяців тому

    Best video ever!!!! Thank you dude

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

    Thanks!

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

    Ahhh that was nice! Thanks!

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

    I was trying to solve the library management problem with pipreqs but as you see in the video it get different versions of the packages that "pip freeze" gets. Also we notice that with a large project, pipreqs has a weird behaviour and installs libraries that does'nt even are imported, but are part of the environment. 🤔

  • @bennguyen1313
    @bennguyen1313 18 днів тому

    Regarding venv, I understand it comes with python, but I've seen many manually install pyenv separately.. why, what's the difference between
    1) pipx
    2) venv / virtualenv
    3) pyenv (not pyvenv ) with or without the virtualenv plugin (i.e. pyenv-virtualenv)
    Can pip freeze and/or pipreqs ANALYZE my python file and determine which imports/versions are used? I'd like to get a requirements txt of ONLY the packages (and their versions) that are actually used in the code!

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

    Thanks for the great video. Exactly what I needed. Few questions if I may: Often it is recommended to do sudo apt update/upgrade. Wouldn't it destroy the version management? 2) I just got the following error when running the requirements: "ERROR: No matching distribution found for gitpython>=3.1.30" . I looked at the gitpython web and they have versions with .30/31/32. Strangely, the command returns many versions, yet all of them are below .30 . Where exactly is the install command is looking at for versions?

  • @christianlestercayabyab6296

    Hey, what's your opinion about pipenv and poetry for handling package management?

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

    Hi, what do i do if the project i'm trying to setup has conflicting requirements? I've tried pip freeze > requirements.txt and pip install -r requirements.txt --upgrade --upgrade-strategy eager, but there are a couple of conflicts still! 😢

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

    good video, however -r does not stand for requirements but recursive.

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

      wups, thanks for bringing that to my attention!

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

    Great job

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

    got an error message
    The term 'pipreqs' is not recognized as the name of a cmdlet, function, script
    file, or operable program. Check the spelling of the name, or if a path was included, verify
    that the path is correct and try again.
    At line:1 char:1
    + pipreqs --force
    + ~~~~~~~
    + CategoryInfo : ObjectNotFound: (pipreqs:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

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

    Greate

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

    I got an error: "You cannot call a method on a null-valued expression" ???

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

      PyCharm was able to figure out what I was trying to do though and eventually prompted me to load the libraries into the requirements.txt file without having to use the terminal, so that's good I guess

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

    I might be wrong, but I'm almost certain the reason pip freeze lists module you aren't using is because you actually are using them. For example I know that requests is based on urllib3 as well as cv2 is based on numpy.

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

    What about python egg?

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

    What is the program you are using I see you always using it but I can’t find it anywhere, it’s probably something I already have I just don’t know what it’s name is, I currently just do everything manually with notepad++ and cmd 😂

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

      PyCharm! Welcome to the future :)

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

      @@allo5668 thank you so much 😂

  • @aryankothari4634
    @aryankothari4634 Рік тому +13

    Poetry. Goodbye.

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

    I almost always watch and like your videos, but I had to skip this one because I can't read dark text on a black background. *Contrast* is what makes that that whole "print thing" work.

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

      I don't understand where you see dark text on a black background in this video.

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

    Hi, I got a small request. Could you do a video on explaining how to install different dependencies for python project? I am very new and a lot of time when I install the dependencies/library they conflict to each other such as "ImportError: cannot import name 'builder' from 'google.protobuf.internal'... "

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

    Guys do yourself a favor and simply use poetry...
    Simple package management
    Simple build (laugh in the face of setuptools)
    Simple publishing
    Simple installation on venvs
    Simple entry points
    Simple extras
    ...

  • @KidoKatsuragi
    @KidoKatsuragi Рік тому +2

    Nah, I'll stick to pyproject.toml and poetry. It's 2023 ffs.