Single command in python to install relevant modules from a package.json like file
Question:
In node.js, one can do npm update --production
during deployment and all the relevant node.js modules will be installed as long as the right package.json is in place.
Is there a python equivalent command line for easy deployment? Can pip do the same thing as npm?
Answers:
You can do a
pip freeze > requirements.txt
In the local machine. And in the server,
pip install -r requirements.txt
This installs all the dependencies
Yes, you can put your packages in a simple text file requirements.txt
, e.g. (version numbers are optional)
SQLAlchemy==1.0.4
requests==2.4.3
and then do pip install -r requirements.txt
yes there is an command for doing that , once you want to deploy you can generate the package file using the following command:
pip freeze > requirements.txt
and whenever you want to install the packages from same file use:
pip install -r requirements.txt
you can find more info about freeze here
TLDR; poetry
would be equivalent to npm
.
I would use pipenv instead of pip. pipenv automatically generate Pipfile and Pipfile.lock that is far superior to requirements.txt
install pipenv and setting it for your project
pip install --user pipenv
cd yourproject
pipenv install package1 package2 ...
to install packages from Pipfile is as simple as
pipenv install
Read more: https://pipenv.kennethreitz.org/
Update: hello to poetry
I have recently moved from pipenv to poetry because poetry has everything pipenv offers and much more. It is end-to-end, as it includes building and publishing of your project to pypi.
installing poetry
curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
and set .poetry/bin in your path.
poetry new yourproject
cd yourproject
poetry add packagename
Like pipenv this generate pyproject.toml file that context all your requirements. Like Pipenv, to install your depence
poetry install
See more: https://poetry.eustace.io/docs/
See Python packaging war: Pipenv vs. Poetry for short review of these awesome packages
In node.js, one can do npm update --production
during deployment and all the relevant node.js modules will be installed as long as the right package.json is in place.
Is there a python equivalent command line for easy deployment? Can pip do the same thing as npm?
You can do a
pip freeze > requirements.txt
In the local machine. And in the server,
pip install -r requirements.txt
This installs all the dependencies
Yes, you can put your packages in a simple text file requirements.txt
, e.g. (version numbers are optional)
SQLAlchemy==1.0.4
requests==2.4.3
and then do pip install -r requirements.txt
yes there is an command for doing that , once you want to deploy you can generate the package file using the following command:
pip freeze > requirements.txt
and whenever you want to install the packages from same file use:
pip install -r requirements.txt
you can find more info about freeze here
TLDR; poetry
would be equivalent to npm
.
I would use pipenv instead of pip. pipenv automatically generate Pipfile and Pipfile.lock that is far superior to requirements.txt
install pipenv and setting it for your project
pip install --user pipenv
cd yourproject
pipenv install package1 package2 ...
to install packages from Pipfile is as simple as
pipenv install
Read more: https://pipenv.kennethreitz.org/
Update: hello to poetry
I have recently moved from pipenv to poetry because poetry has everything pipenv offers and much more. It is end-to-end, as it includes building and publishing of your project to pypi.
installing poetry
curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
and set .poetry/bin in your path.
poetry new yourproject
cd yourproject
poetry add packagename
Like pipenv this generate pyproject.toml file that context all your requirements. Like Pipenv, to install your depence
poetry install
See more: https://poetry.eustace.io/docs/
See Python packaging war: Pipenv vs. Poetry for short review of these awesome packages