Help with packaging a python application

Hi! I would like to develop an application in python, but I’m having some difficulties with understanding flakes. This is what I’m having so far:

When I try:

user@kaktus ~/G/fuujin (main)> nix run .#fuujin
error: unable to execute '/nix/store/jnjyd134y9pr0v0cncdpyz7nj6f7y0p9-python3.11-fuujin-0.1.0/bin/fuujin': No such file or directory
user@kaktus ~/G/fuujin (main) [1]>

I get an error. Can you guys help me out?

To build an application, you need buildPythonApplication, and also your pyproject.toml has to define at least one entry point as far as I remember.

This is my flake.nix:

{
  description = "";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };
        python = pkgs.python311;
      in
      {
        packages.fuujin = python.pkgs.buildPythonPackage rec {
          pname = "fuujin";
          version = "0.1.0";
#          license = pkgs.licenses.gpl;
          pyproject = true;
          src = ./fuujin;
          nativeBuildInputs = [ python.pkgs.setuptools ];
          propagatedBuildInputs = [
            python.pkgs.requests
            python.pkgs.numpy
          ];
        };
      });
}

I didn’t quite know what to put in pyproject.toml, so I left it empty…

I know how it looks like. I checked the repo. Doesn’t change what I said.

1 Like

I’m sorry, I understood that you didn’t look, because I used buildPythonPackage.

Yeah. But you need buildPythonApplication instead, and also your pyproject.toml needs to declare entry points.

f*

I could swear that I thought it’s the same… Thank you for your patience. However it still failed to execute:

user@kaktus ~/G/fuujin (main)> nix run .#fuujin
error: unable to execute '/nix/store/zb27kpxacd4xl7iz509k0dfpdcj7yvzi-fuujin-0.1.0/bin/fuujin': No such file or directory
user@kaktus ~/G/fuujin (main) [1]>

There is still no entry point.

Thank you, I didn’t understand you at that moment. After some time reading and following this guide:

I finally managed to get it working:

user@kaktus ~ (main)> tree
.
├── docs
│   └── main.md
├── flake.lock
├── flake.nix
├── fuujin
│   ├── __init__.py
│   ├── __main__.py
│   ├── master.py
│   └── __pycache__
│       └── master.cpython-311.pyc
├── fuujin.code-workspace
├── LICENSE
├── poetry.lock
├── pyproject.toml
├── README.md
├── result -> /nix/store/yh268ppq2dvglbmmaxmv9ld8xd4107cb-fuujin-0.1.0
└── TODO.md

5 directories, 13 files
user@kaktus ~ (main)>

pyproject.toml:

[project]
name = "fuujin"
version = "0.1.0"
description = ""

[tool.poetry.dependencies]
python = "^3.11"

[project.scripts]
fuujin = "fuujin.master:test"

Thank you for your help @NobbZ !