Thank you very much for your input here!
With your help, I was able to make the minimum example run after adapting the nix file and renaming it to “default.nix”.
Then I started to adapt my more complex shell script example, which is using shell variables and more CLI parameters.
Somehow, there seems to be an issue with a missing dependency.
I hope that I was able to extend the minimum example so that you can duplicate the error I get:
Example invocation with the dependency error visible:
2del % ./test.sh
+ which python
/usr/bin/python
+ python -V
Python 3.12.7
+ poetry --version
Poetry (version 1.8.4)
+ echo '=========> example Python call:'
=========> example Python call:
+ python minimal.py
Traceback (most recent call last):
File "/home/vk/tmp/2del/2del/minimal.py", line 1, in <module>
from jinja2 import Environment, FileSystemLoader
ModuleNotFoundError: No module named 'jinja2'
+ echo '=========> end'
=========> end
2del %
All the required files
test.sh
The slightly extended test script that now calls the minimal.py script:
#!/usr/bin/env nix-shell
#!nix-shell -i bash
poetry-env -c "
set -x
which python
python -V
poetry --version
# poetry install ## optionally enabled or not, doesn't matter
echo \"=========> example Python call:\"
python minimal.py
echo \"=========> end\"
"
I also tried to invoke poetry install
within the poetry-env
section with not having an effect on the error:
2del % ./test.sh
+ which python
/usr/bin/python
+ python -V
Python 3.12.7
+ poetry --version
Poetry (version 1.8.4)
+ poetry install
Installing dependencies from lock file
No dependencies to install or update
Installing the current project: gematik_afo_vergleich (0.1.0)
Warning: The current project could not be installed: No file/folder found for package gematik-afo-vergleich
If you do not want to install the current project use --no-root.
If you want to use Poetry only for dependency management but not for packaging, you can disable package mode by setting package-mode = false in your pyproject.toml file.
In a future version of Poetry this warning will become an error!
+ echo '=========> example Python call:'
=========> example Python call:
+ python minimal.py
Traceback (most recent call last):
File "/home/vk/tmp/2del/2del/minimal.py", line 1, in <module>
from jinja2 import Environment, FileSystemLoader
ModuleNotFoundError: No module named 'jinja2'
+ echo '=========> end'
=========> end
2del %
Moving the poetry install
above the poetry-env
call and execute it beforehand didn’t resolve the issue as well.
default.nix
This is exactly your version from above:
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell { # a normal nix shell, no FHS magic yet
buildInputs = [
# this puts an executable 'poetry-env' into the PATH
# which executed by itself yeets you into the FHS environment,
# but it also accepts a -c 'command-to-run' flag
(pkgs.buildFHSEnv {
name = "poetry-env";
multiPkgs = pkgs: (with pkgs; [ python3 poetry libz ]);
})
];
}
minimal.py
This example Python script is loading jinja2:
from jinja2 import Environment, FileSystemLoader
print('Testoutput')
pyproject.toml
Here, the jinja2 dependency is defined:
[tool.poetry]
name = "foo"
version = "0.1.0"
description = "foo"
authors = ["foo"]
[tool.poetry.dependencies]
python = "^3.10"
jinja2 = "^3.1.4"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"