我希望使用pip-tools将我的需求文件划分为开发(requirements-dev.txt)和生产(requirements.txt)。
我已经安装了pip-工具使用pipx,因为我希望它是全球性的,但孤立的。但是,这样做会使我的依赖项由pip本身的虚拟环境中的pip安装,而不是激活的虚拟环境。
我不知道这是否是一个因素,但我也使用pyenv来管理我的python版本,但只有一个(非系统)版本在全球安装。
考虑到我的环境(即用pipx安装的pip工具,由pyenv管理的python ),如何让pip-sync在激活的虚拟环境中安装依赖项?
下面是我的工作流程:
# Install pip-tools globally
pipx install pip-tools
# Create a virtual environment and activate it
python -m venv venv
source venv/bin/activate
# Create prod/dev requirement input files (see below for content)
# Autogenerate requirement files
pip-compile requirements.in
pip-compile requirements-dev.in
# Install all dependencies
pip-sync requirements.txt requirements-dev.txt
# Check what is installed (outputs nothing)
pip freeze
# Check what is installed in pip-tools virtual env
~/.local/pipx/venvs/pip-tools/bin/python -m pip freeze
# output shows flask, pytest, and their dependencies生产依赖文件
# requirements.in
flask开发依赖文件
# requirements-dev.in
-c requirements.txt
pytest发布于 2021-09-03 02:14:54
这是一个带有pip工具的已知问题。
您必须在项目的虚拟环境中安装pip工具(而不是在全局上安装pipx),或者如果使用pipx安装,可以使用以下方法来“模拟”pip同步:
# Remove all dependencies
pip freeze | xargs pip uninstall -y
# Reinstall the dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt注:pip-编译工作时,没有问题,当pip-工具安装与pipx。
发布于 2021-09-22 20:04:48
您可以使用--python-executable选项(6.2.0中的介绍)在任何环境中安装包:
pip-sync --python-executable venv/bin/python requirements.txt requirements-dev.txthttps://stackoverflow.com/questions/69024242
复制相似问题