Single command in python to install relevant modul

2019-03-14 14:19发布

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?

标签: python pip
4条回答
疯言疯语
2楼-- · 2019-03-14 14:40

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

查看更多
时光不老,我们不散
3楼-- · 2019-03-14 14:44

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

查看更多
够拽才男人
4楼-- · 2019-03-14 14:45

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

查看更多
冷血范
5楼-- · 2019-03-14 14:55

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

查看更多
登录 后发表回答