I wish to separate my requirement files into development (requirements-dev.txt) and production (requirements.txt) using pip-tools.
I have installed pip-tools using pipx as I want it to be globally available but isolated. However, doing so causes my dependencies to be installed by pip-tools within the virtual environment of pip-tools itself, rather than the activated virtual environment.
I don't know if it is a factor, but I am also using pyenv to manage my python versions, but only have one (non-system) version installed globally.
Given my environment (i.e. pip-tools installed with pipx, python managed by pyenv), how do I get pip-sync
to install the dependencies within the activated virtual environment?
Here is my workflow to reproduce this:
# 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
Production dependency file
# requirements.in
flask
Development dependency file
# requirements-dev.in
-c requirements.txt
pytest
You can install packages in any environment using
--python-executable
option (introduced in 6.2.0):