-
-
Save AshyIsMe/7d61a5ef6c7198b4fb6f14c26451bf8d to your computer and use it in GitHub Desktop.
nix-shell python venv workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with import <nixpkgs> { }; | |
let | |
pythonPackages = python38Packages; | |
in pkgs.mkShell rec { | |
name = "impurePythonEnv"; | |
venvDir = "./.venv"; | |
buildInputs = [ | |
# A python interpreter including the 'venv' module is required to bootstrap | |
# the environment. | |
pythonPackages.python | |
# This execute some shell code to initialize a venv in $venvDir before | |
# dropping into the shell | |
pythonPackages.venvShellHook | |
# Those are dependencies that we would like to use from nixpkgs, which will | |
# add them to PYTHONPATH and thus make them accessible from within the venv. | |
pythonPackages.beautifulsoup4 | |
pythonPackages.chardet | |
pythonPackages.h5py | |
pythonPackages.matplotlib | |
pythonPackages.numpy | |
pythonPackages.pandas | |
pythonPackages.pip | |
pythonPackages.pylint | |
pythonPackages.pyodbc | |
pythonPackages.sqlalchemy | |
# In this particular example, in order to compile any binary extensions they may | |
# require, the python modules listed in the hypothetical requirements.txt need | |
# the following packages to be installed locally: | |
#taglib | |
#openssl | |
#git | |
#libxml2 | |
#libxslt | |
#libzip | |
#zlib | |
]; | |
# Now we can execute any commands within the virtual environment. | |
# This is optional and can be left out to run pip manually. | |
postShellHook = '' | |
python3 -m pip install -r requirements.txt | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment