Single command in python to install relevant modul

2019-03-14 14:37发布

问题:

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?

回答1:

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



回答2:

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://docs.pipenv.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



回答3:

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



回答4:

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



标签: python pip