How to use python packages to install packages locally, e.g. npm

Say I have a project called Foo , and I want to install the requests package locally for this project. What I expect is a structure like this:

Foo/
|-main.py
|-requirements.txt
|-README.md
|-python_modules/
|-|-requests
...

And I can do this with pip install -r requirments.txt -t ./python_modules/ , however this does not work properly because in python_modules/ there is no __init__.py , so programs will not automatically import all the packages into python_modules .

npm install , on the other hand, does this very well.

So my question is: how does pip work just like npm does?

PS: I know there are other conventions using virtualenv or pythonbrew , but I still want to ask this question.

+6
source share

Source: https://habr.com/ru/post/944280/


All Articles