Hey Everyone Interested to know how do you guys manage your requirements.txt file to reproduce the same environment. What tools do you prefer to keep the requirements.txt file updated
Basically i want to create a requirements.txt file for my project but for some reason no matter what method i am trying i am just missing out on many dependencies
so there exists a command
uv pip compile requirements.in --universal --output-file requirements.txtBut this assumes that requirements.in is already present.
or you can copy your existing requirements.txt
into a requiremements.in
and compile them that way
Let me explain you the scenario
So i started building an application and I forgot to create any kind of requirements.txt file or requirements.in file .
Then I used tools like pip
pip freezeThis simply dumps all the top level and sub packages in the requirements.txt file for some reason i did not found this very optimal.
kedro-datasets[pandas-csvdataset] kedro-datasets[ibis] kedro-kubeflow==0.8.0 ibis-framework==9.0.0 s3fs==2024.9.0 psycopg2-binary==2.9.9
you're on the right path. either you add your dependencies to a requirements.in
, or to the [project.dependencies]
table of pyproject.toml
(we in Kedro are moving towards the latter)
ok but what is the standard way while developing any application . Like the best way I was aware of till now is to manually add the dependency along-with the version. But is that how people do it ? because there are high chances of people forgetting to add dependencies manually.
I want to know the workflow to manage dependencies either to requirements.in
or pyproject.toml
.
so you mean whenever we want to make use of a new python package in the application we simply do uv add and it takes care of logging the package along with version somewhere like requirements.txt and we never miss out on anything
just for my understanding pip compile is needed if we want to publish our project as a python project and people can simply pip install and use it in their projects ?
So if 2 packages have the common dependency(say X), pip compile will find the version of X which is compatible for both the packages?
I was just comparing uv with poetry looks like poetry also does the same thing . Any thoughts ?
So you can do uv pip install -r requirements.txt
but the more modern way is to do uv add
as you go along
getting into an issue
Resolved 147 packages in 922ms
error: Failed to prepare distributions
Caused by: Failed to fetch wheel: psycopg2-binary==2.9.9
Caused by: Build backend failed to determine requirements with `build_wheel()` (exit status: 1)
Oh I bet you're talking to different python installations . If you type which python
what shows up
which python
nothing shows up
So basically what i was really doing is I am trying to setup a kedro project in my new laptop. I simply cloned the project from github and ran
uv pip compile requirements.in --universal --output-file requirements.txtAfter that I did
uv init
- got some error saying that project already initialised and pyproject.toml
already exists , So i deleted the default one created by kedro init
and reran uv unit . It published a minimal pyproject.toml
[project] name = "warehouse-pipeline" version = "0.1.0" description = "Add your description here" readme = "README.md" requires-python = ">=3.13" dependencies = []and a uv.lock file
version = 1 requires-python = ">=3.13" [[package]] name = "warehouse-pipeline" version = "0.1.0" source = { virtual = "." }
I think i was doing some mistake .
venv --python 3.9
in the kedro project folder.uv init
Now I have proper python version declared in pyproject.toml earlier for some reason it took default latest pythonuv pip install -r requirements.txt
Some quick Questions
You actually may want to combine the two pyproject tomls, its important if you want to package your kedro project but you can prob get away without if you don't
so yeaah no need to package it as it will be running like an application instead of getting used by other applications
But i want to move all dependencies to pyproject from requirements.txt and get rid of it.
uv sync
actually removes all the installed packages from requirements.txt becuase it actually trying to sync with dependencies defined in pyproject.toml
or uv.lock
which is empty for me currently 😛
sorry for such big threads but i learned fundamentals of using a dependency management tool like uv and later explored poetry as well.
haha no worries! it was not a criticism. I'm happy that we helped you untangle some of these packaging tricks. what would be your main takeaways?
poetry add
or uv add
, they both are backed by powerful dependency resolution algorithms.pyproject.toml
pip
, pipreqs
, pip-tools
. One thing to note here is tools like poetry and uv does not just do dependency resolution but it manages for you and it does it really well.btw uv is on its way to surpass Poetry in weekly downloads 😱 https://clickpy.clickhouse.com/dashboard/uv