Skip to content

Instantly share code, notes, and snippets.

@mdipierro
Created January 23, 2024 06:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdipierro/8a7f7d55df6330f776d45ed2bbcdb6c1 to your computer and use it in GitHub Desktop.
Save mdipierro/8a7f7d55df6330f776d45ed2bbcdb6c1 to your computer and use it in GitHub Desktop.
Python script that makes its own nix-shell
#! /usr/bin/bash
"""":
# if Nix not installed, install it, then rerun this script with nix-shell
[ -f /etc/nix/nix.conf ] || curl -L https://nixos.org/nix/install | sh -s -- --daemon
exec nix-shell --command "python $0 $@" \
-p python311 \
-p python3Packages.numpy
# add any package you want above and they will be added to the shell
exit 1
""" #"
import numpy
print(numpy.array([1,2,3]))
@villares
Copy link

villares commented Feb 1, 2024

Thanks for sharing! In your example, a new Python 3.11 interpreter is installed? Also, you show that packages can be installed (like numpy in the example). Where are those things installed? Are they persistent between runs of the script (saving execution time) or they have to be reinstalled each time (saving disk space)?

@mdipierro
Copy link
Author

mdipierro commented Feb 1, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment