Created
December 26, 2017 21:49
-
-
Save markph0204/dd97d9d301483fcc2cf458f5e44ff25d to your computer and use it in GitHub Desktop.
direnv with pycharm
This file contains hidden or 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
| # enable direnv for python | |
| # this will enable the commandline support as well as support pycharm | |
| # 1 install direnv (Homebrew / pip) | |
| # 2 edit your .bashrc, .bash_profile or .bash_aliases | |
| function venv-here { | |
| # you could just use 'layout python' here for 2.7.x | |
| echo "layout python3" > .envrc | |
| echo "ln -s .direnv/\$(basename \$VIRTUAL_ENV)/ .env" >> .envrc | |
| } | |
| # sample | |
| # cd to any path, then run... | |
| venv-here | |
| # prompted to run direnv allow | |
| direnv allow | |
| #done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @markph0204 ! I really appreciate your reply. I didn't think you/anyone would get to it so quickly! 🥇 👍
I want to specifically understand why
.direnvis being used in this context:echo "ln -s .direnv/\$(basename \$VIRTUAL_ENV)/ .env" >> .envrcI looked all through https://direnv.net and only found references to
.direnvhere in thelayout pythonandlayout rubysections ofdirenv stdlib.So I think from that reading, that it looks like a
$PWD/.direnvfile is only created for those layout types. And since I'm usingpipenv, it will not be created.I did some testing and found that I didn't have to have anything but an empty
.envfile in my project for PyCharm to detect thepipenvvenv.So now the function can be written differently:
Thanks a lot!