Simple ply python package breaks environment build

Hello everyone!

I was running my python scripts, then I need to add package ply or lark but the environment won’t build again, I tried several combinations, one by one, nothing, this was the idea but it doesn’t work (only when the only python package is pytz works):

{ pkgs, … }: {

Which nixpkgs channel to use.

channel = “stable-24.05”; # or “unstable”

Use NixOS Search to find packages

packages = [
# pkgs.go
# pkgs.python311
# pkgs.python311Packages.pip
# pkgs.nodejs_20
# pkgs.nodePackages.nodemon

# Define the Python interpreter WITH the desired packages
(pkgs.python312Full.withPackages (ps: [
  ps.pip
  ps.pytz
  ps.ply
  ps.lark
  ps.antlr4-python3-runtime
]))

];

please help,
thank you!

I found a way, here are the instructions for antlr with python (no need to mess with dev.nix):

Steps to Enable Importing antlr4-python3-runtime in Your Python Scripts

This process ensures that the necessary ANTLR runtime library is available within your Python environment.

  1. Add antlr4-python3-runtime to requirements.txt:

    • Open your project’s requirements.txt file.
    • Add the line: antlr4-python3-runtime
    • Save the file.
  2. Remove the old virtual environment:

    • In your terminal, run: rm -rf .venv
    • This ensures a clean install and avoids potential conflicts.
  3. Recreate the virtual environment:

    • In your terminal, navigate to your project’s root directory.
    • Run the command: python -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt
    • This will:
      • Create a new virtual environment named .venv.
      • Activate the virtual environment.
      • Install all packages listed in requirements.txt, including antlr4-python3-runtime.
  4. Verify the Installation:

    • Ensure your virtual environment is active.
    • In your terminal, run: source .venv/bin/activate && python -c "from antlr4 import *"
    • If there are no errors, antlr4-python3-runtime is correctly installed and importable.
      • This command imports all the antlr4 code.

Explanation:

These steps ensure that the ANTLR runtime is installed in your virtual environment. By adding it to requirements.txt, you make it a dependency of your project. Then, by recreating the virtual environment, you make sure that all your libraries are correctly installed.

I hope this helps someone. I used the AI. The first day it told me to mess with dev.nix (that was yesterday), today I asked again and it went to this new way that actually worked for me. Than you gemini-built-in