This project uses Nix Flakes to provide a reproducible development environment with Python and virtual environment support.
-
Install Nix (if not already installed):
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
-
Enable Nix Flakes (if not already enabled):
- The Determinate Nix installer enables flakes by default
- If using the official Nix installer, add to
~/.config/nix/nix.conf:experimental-features = nix-command flakes
nix developThis will automatically:
- Download and set up Python 3.11
- Create a Python virtual environment (
.venv) if it doesn't exist - Activate the virtual environment
- Display helpful instructions
Option A: From requirements.txt
pip install -r requirements.txtOption B: Install packages individually
pip install opencv-python numpy pillowOption C: Install deep learning frameworks
# For PyTorch
pip install torch torchvision
# For TensorFlow
pip install tensorflow.
├── flake.nix # Nix flake configuration
├── .gitignore # Git ignore patterns
├── requirements.txt # Python dependencies
├── README.md # This file
└── .venv/ # Python virtual environment (created by you)
# Enter Nix shell (automatically creates and activates venv)
nix develop
# Work on your project...
# The virtual environment is already activated!
# Exit when done (this also deactivates the venv)
exit# The venv is already activated when you run 'nix develop'
# Just install packages directly:
pip install <package-name>
# Update requirements.txt
pip freeze > requirements.txt# Update all packages
pip install --upgrade -r requirements.txt
# Update specific package
pip install --upgrade <package-name>Edit flake.nix and add packages to the buildInputs list:
buildInputs = with pkgs; [
python311
python311Packages.pip
# Add more packages here
ffmpeg
imagemagick
];In flake.nix, replace python311 with your desired version:
python39for Python 3.9python310for Python 3.10python312for Python 3.12
- Make sure Nix is installed and your shell has been restarted
- Enable flakes in your Nix configuration (see Prerequisites)
- The Nix shell automatically creates and activates the venv
- If you see issues, try deleting
.venvand runnix developagain - Check that the shellHook in
flake.nixis properly configured
- Ensure the virtual environment is activated
- Verify the package is installed:
pip list
- The virtual environment is automatically activated when you run
nix develop - Keep
requirements.txtupdated for reproducibility - Use
pip freeze > requirements.txtto capture exact versions - The
.gitignorefile excludes the.venvdirectory from Git
- Create your Python scripts in the project directory
- Import your dependencies
- Build your computer vision project!
Happy coding! 🚀