How to Create and Use Virtual Environments in Python With Poetry

preview_player
Показать описание
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.

🎓 Courses:

👍 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!

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

🔖 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 content each week!
Рекомендации по теме
Комментарии
Автор

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)

Victorinoeng
Автор

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!

Автор

Poetry is a 10/10 project tool IMO. Im glad I was able to convince my team to move over to it.

ImARichard
Автор

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

kerryw
Автор

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!

PaulFWatts
Автор

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.

randomclimber
Автор

I've actually been using conda for this, even for non-Python projects, and it worked well for me so far

archibald-ycle
Автор

Finally sounds like theres a decent python project package manager. Can’t wait to use it

DevelopXp
Автор

At work we started using poetry, it helped us a lot to deploy and also manage de dependencies.

caetanog_
Автор

Love the videos & quality work you put into them. Could you at some point do some examples, such as: wave function collapse, etc ...?

daineminton
Автор

Thanks Arjan, was waiting a long time for this video. Finally Poetry gets explained in a good and clear way!

DarknezRocks
Автор

Thanks for this!! I started playing with Poetry a little while ago and needed this video!

EvanYoung-xokd
Автор

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!

loic
Автор

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

davidl
Автор

Thank for the video Arjan, I think some medieval emperors would be interested in the practical applications of a language like Python, such as its ability to automate tasks and process large amounts of data. They would appreciate its ability to create visualizations and simulations, which could be useful for military planning or other strategic purposes.

FollowPathfinder
Автор

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

cdgarzon
Автор

I love poetry + pyenv. It allows me to define the dependencies exactly so that anybody that clones my repo can get the exact experience I get.

blanketfish
Автор

Thanks, before watching the video I struggled at quite some points. Now it is very clear to me and I see the advantages of using Poetry :)

ln
Автор

Thanks for the video. If I recall correctly, Poetry also allows to have multiple sets of dependencies, for example a dev set where you put all your tests dependancies (like pytest), and a prod set for the app dependencies.

neobrandsainclair
Автор

That .venv tip can be handy for people using VSCode's dev containers feature. If you need to rebuild the dev container you end up trashing its filesystem usually, along with any Poetry virtualenvs that may have been created in the container filesystem. By using .venv within your repo's source directory (probably want to .gitignore it), you can rebuild the dev container without wiping your venv, saving you from doing poetry install repeatedly.

thebrigandier