I've created this template to create an isolated enviroment for developing python projects using Pycharm (Community Edition) from JetBrains.
- Uses dream2nix, to maximize reproduciblity of python packaging
- Based on the example in
examples/packages/single-language/python-project
. - Modified to move most parameter configuration to
pyproject.toml
- Based on the example in
- Published as flake
- (optional, checkout branch
direnv
) Added.envrc
to automatically load shell environment using direnv - (optional, checkout branch
pycharm
) Small bashscript to load PyCharm from the terminal, while suppressing stdout
- Fork this repo and
git checkout
- cd into the folder
- Modify
pyproject.toml
according to your project - Enable environment
$ nix run --impure
to start shell environment (will build all dependencies on first run and after any updates) - (or, optionally, instead of step 4.) Enable direnv by running
direnv allow
and auto-enable shell environment and update - Update the
lock.json
by running the command generated by dream2nix (see terminal output,bash -c /nix/...
or something similar) - (optionally, to use with PyCharm)
- (prerequisite:
pkgs.jetbrains.pycharm-community
is installed in global package space (e.g in configuration.nix or via home-manager)) - From the terminal with the environment active, run
where python
and copy the path to the python bin - un
$ ./pycharm.sh
(ensure it's executable by$ chmod +x pycharm.sh
) - (Close terminal, if you want)
- In PyCharm, add the new interpreter:
- Settings > Add New Interpreter > Virtual Environment
- Check Existing
- Paste the copied path from step 7.2
- (prerequisite:
Currently, pycharm needs to restarted after installing new python packages. I'm looking into ways to fix this, might be (very) complicated/impossible.
- Modify `pyproject.toml
- Re-enable environment (see step 4/5 above)
- Update
lock.json
(see above) - Save your work and close PyCharm
- Re-run PyCharm from the terminal
Please let me know in case something is not clear, doesn't work as described or can be improved.