How to Create and Use Virtual Environments in Python With Poetry

123,581
0
Published 2023-03-24
It can be tricky when different packages in Python don't play nice. The solution to this problem is to create an isolated, virtual environment. In this video, I’ll show you how to set up a virtual environment with poetry, a package manager for Python that simplifies dependency management and project packaging.

🚀 Next-Level Python Skillshare Class: skl.sh/3ZQkUEN

✍🏻 Take a quiz on this topic: www.learntail.com/quiz/kkmnju

💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.

💻 ArjanCodes Blog: www.arjancodes.com/blog

🎓 Courses:
The Software Designer Mindset: www.arjancodes.com/mindset
The Software Designer Mindset Team Packages: www.arjancodes.com/sas
The Software Architect Mindset: Pre-register now! www.arjancodes.com/architect
Next Level Python: Become a Python Expert: www.arjancodes.com/next-level-python
The 30-Day Design Challenge: www.arjancodes.com/30ddc

🛒 GEAR & RECOMMENDED BOOKS: kit.co/arjancodes.

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

💬 Discord: discord.arjan.codes/
🐦Twitter: twitter.com/arjancodes
🌍LinkedIn: www.linkedin.com/company/arjancodes
🕵Facebook: www.facebook.com/arjancodes
📱Instagram: www.instagram.com/arjancodes
♪ Tiktok: www.tiktok.com/@arjancodes

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- James Dooley
- Dale Hagglund

🎥 Video edited by Mark Bacskai: www.instagram.com/bacskaimark
💻 Code example by Henrique Branco: www.linkedin.com/in/henriqueajnb

🔖 Chapters:
0:00 Intro
1:24 Code example
2:00 Virtual environments
3:00 Tools
4:15 Why poetry?
5:20 Creating a virtual environment with poetry
8:33 Activating it
8:55 Installing dependencies
9:38 Deactivating it
10:11 Removing it
10:27 Packaging and publishing using poetry
11:58 Things to watch out for
14:18 Outro

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free co

All Comments (21)
  • @Victorinoeng
    There are some additional super useful functionally worth mentioning: 1) In the toml file, there are special characters that define/limit how to update dependencies versions (^, ~); 2) the lock file “locks” the exact versions for dependencies and transient ones. This ensures reproducibility and is a game changes for production ready code. it is possible to test updating packages and only committing the new .lock file if everything works. 3) poetry has a cli tool to auto bump the package version (major, minor, patch) which makes it even easier when managing a package 4) for some compatibility cases, it is also possible to export the dependencies into a requirements.txt file (for example, when using serverless framework to deploy an AWS Lambda function using the pip-requirements plugin)
  • @ImARichard
    Poetry is a 10/10 project tool IMO. Im glad I was able to convince my team to move over to it.
  • @PaulFWatts
    I don't think it can be underestimated what a "rabbit hole of pain 🙂" this topic can be for the python programmer who is moving beyond the basics (I know from personal experience lol). Especially compared to `cargo` in Rust. Poetry has simplified my Python development, and this is an excellent video in getting started with it. Thanks for all your great videos!
  • This has to be one of the best and most concise tutorials I've watched lately. I've been using virtualenvs and venvs with pipfiles for years, but this looks like the next logical step. Thanks!
  • @kerryw6361
    This is a great video to understand the use of poetry. After this video, I find the official Poetry documentation making a lot of sense. Thank you!!
  • @randomclimber
    I'm using pyenv to manage python versions, and then having poetry creating creating a virtual env inside the project. Really glad with this setup.
  • I've actually been using conda for this, even for non-Python projects, and it worked well for me so far
  • @DevelopXp
    Finally sounds like theres a decent python project package manager. Can’t wait to use it
  • @milandean
    So glad this video finally came out!!
  • Thanks for this!! I started playing with Poetry a little while ago and needed this video!
  • @caetanog_
    At work we started using poetry, it helped us a lot to deploy and also manage de dependencies.
  • @DarknezRocks
    Thanks Arjan, was waiting a long time for this video. Finally Poetry gets explained in a good and clear way!
  • @davidl3383
    Thank you son much exactly when I tart learning poetry😊 excellent tips to delete old env and reinstall them evently to limite size of project
  • @loic1665
    Poetry is life! Seriously it's a great tool, at word we use it all the time and for my personal projets I would use it without an hesitation too!
  • @cdgarzon1
    Good video! I've been using poetry for some time now, and recently ran into the case where you have a poetry project that uses a python version that needs to be updated, which means you have to manage multiple python version in your system and need to tell poetry to go from one version to another. That would be a really good topic for another video as I see a lot of confusing information online about pyenv and poetry working together
  • Love the videos & quality work you put into them. Could you at some point do some examples, such as: wave function collapse, etc ...?