I've seen solutions which automatically install requirements.txt but nothing that says why Python doesn't have a feature for this.
As far as I know the requirements.txt
file format has not much to do with Python itself. I believe it has been created by pip and for pip, which is a piece of software independent from Python.
If you search for requirements.txt
in Python's documentation you will find only a couple of occurrences, all of them directly associated with pip. Even though pip is somehow bundled in with distributions of Python , pip is an external project.
In short: Python doesn't know anything about requirements.txt
, some 3rd party tools do.
You have to do it like this
pip install -r /path/to/requirements.txt
From your comment
So what I'm asking is why can't Python see a requirements.txt file next to the script I'm running and automatically install it?
This is because Python doesn't implement this feature, which makes sense because
It's not hard to implement it yourself, by the way
alias python="if [ -f requirements.txt ]; then pip install -r requirements.txt; fi; python"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.