如果更改了目标make install,如何才能运行requirements.txt?
我不想每次做make install 时都升级软件包
我通过创建假文件_requirements.txt.pyc找到了一些解决办法,但它是、丑陋的和脏的。它将第二次拒绝安装pip要求,因为requirements.txt没有任何更改。
$ make install-pip-requirements
make: Nothing to be done for 'install-pip-requirements'.但我的目标是:
# first time,
$ make install # create virtual environment, install requirements
# second time
$ make install # detected and skipping creating virtual env,
# detect that requirements.txt have no changes
# and skipping installing again all python packages
make: Nothing to be done for 'install'.Python包如下所示:
.
├── Makefile
├── README.rst
├── lambda_handler.py
└── requirements.txt我正在使用文件Makefile来实现python中的一些自动化:
/opt/virtual_env:
# create virtual env if folder not exists
python -m venv /opt/virtual_env
virtual: /opt/virtual_env
# if requirements.txt is modified than execute pip install
_requirements.txt.pyc: requirements.txt
/opt/virtual_env/bin/pip install -r --upgrade requirements.txt
echo > _requirements.txt.pyc
requirements: SOME MAGIG OR SOME make flags
pip install -r requirements.txt
install-pip-requirements: _requirements.txt.pyc
install: virtual requirements我相信
一定是个更好的方法
(要这样做;)
发布于 2017-05-09 08:00:00
现在不确定它会回答你的问题。更好的方法是使用成熟的Python项目模板。
它有一个Makefile,它不会不断地重新安装所有的依赖项,并且它使用Python毒物,它允许在不同的python中自动运行项目测试。您仍然可以在dev virtualenv中进行开发,但是我们只在添加新包时更新它,其他的都是由tox处理的。
但是,到目前为止,您所展示的是从零开始编写Python构建,这是用许多项目模板完成的。如果您真的想了解发生了什么,您可以分析这些模板。
如下所示:因为您希望它可以使用makefile,所以我建议从pip命令中移除--upgrade标志。我怀疑您的需求不包括项目工作所需的版本。我们做了一个经验,不把版本在那里可能会严重刹车的东西。因此,我们的requirements.txt看起来是:
configure==0.5
falcon==0.3.0
futures==3.0.5
gevent==1.1.1
greenlet==0.4.9
gunicorn==19.4.5
hiredis==0.2.0
python-mimeparse==1.5.2
PyYAML==3.11
redis==2.10.5
six==1.10.0
eventlet==0.18.4在不使用--upgrade的情况下使用需求会导致pip,只需验证虚拟环境中的内容和不存在的内容。满足所需版本的所有内容都将被跳过(不下载)。您还可以在这样的需求中引用git版本:
-e git+http://some-url-here/path-to/repository.git@branch-name-OR-commit-id#egg=package-name-how-to-appear-in-pip-freeze发布于 2017-08-17 12:59:03
@Andrei.Danciuc,make只需要比较两个文件;您可以使用运行pip install的任何输出文件。
例如,我通常使用一个"vendored“文件夹,这样我就可以将路径化名为"vendored”文件夹,而不是使用一个虚拟文件。
# Only run install if requirements.txt is newer than vendored folder
vendored-folder := vendored
.PHONY: install
install: $(vendored-folder)
$(vendored-folder): requirements.txt
rm -rf $(vendored-folder)
pip install -r requirements.txt -t $(vendored-folder)如果您不使用一个独立的文件夹,下面的代码应该可以同时用于虚拟和全局设置。
# Only run install if requirements.txt is newer than SITE_PACKAGES location
.PHONY: install
SITE_PACKAGES := $(shell pip show pip | grep '^Location' | cut -f2 -d':')
install: $(SITE_PACKAGES)
$(SITE_PACKAGES): requirements.txt
pip install -r requirements.txthttps://stackoverflow.com/questions/43856980
复制相似问题