-
Notifications
You must be signed in to change notification settings - Fork 624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Configuring direnv using .envrc #331
Comments
direnv gets executed before every prompt line in your shell once it's hooked into your shell. when it's executed it looks for the If the If the This is basically the core of how direnv works and which allows to have dynamic environment variables depending on the current directory. To answer your question more specifically: create a new has three levels of functionality: stdlib, direnvrc and envrc. The |
Thanks for explaining the direnv workflow. But is this module https://github.com/direnv/direnv/wiki/Python#-virtualenv the only way to activate virtualenvs ? The docs say it will automatically create a virtualenv here Thanks |
Sure. "activating" a virtualenv is basically doing two things, so you can add those in your export VIRTUAL_ENV=path/to/your/virtualenv
PATH_add "$VIRTUAL_ENV/bin" If you are tired of copying those around, make a function in your activate_virtualenv() {
export VIRTUAL_ENV=$1
PATH_add "$VIRTUAL_ENV/bin"
} and then in your .envrc: activate_virtualenv path/to/virtualenv |
Thanks for the quick reply. I should probably read up on bash scripting. ex : |
Yeah I guess direnv is best suited to you if you know a little of bash. virtualenv also sets the PS1 environment variable in the activate script. PS1 is on the direnv blacklist because of a bug in bash 3.x on macOS so you would have to implement it yourself. I don't have an example at hand but it's possible to change the prompt depending on if |
@pydo did you learn how to change PS1 in fish shell when using direnv to activate a virtual environment? Thanks. |
@mals14 I just use a fish theme that does it auto-magically for me https://github.com/oh-my-fish/oh-my-fish/blob/master/docs/Themes.md#lambda . |
Thanks for the reply. For some reason lambda prompt works very well for me until I am in a normal directory. Once I enter into a virtual environment directory, then the prompt simply changes to ">". Must be something with my settings somewhere. Bobthefish theme seems to work. Although I like lambda for its two line and full display path. But lambda does not work. I have fish 3.0, and latest stable omf and lambda theme. :( |
@zimbatm a question if you can help. I create virtual environment using And if my understanding is right, then would this second approach that you advised earlier in the thread help avoid the creation of venv by direnv. For the Fish shell: Create a function like so in functions directory function activate_virtualenv
set -x VIRTUAL_ENV $argv
set PATH "$VIRTUAL_ENV/bin" $PATH
end And then .envrc be activate_virtualenv /Users/smalani/Documents/scripts-programming/python-code/analyze-keywords-in-logs.py Sounds like to me that using the second approach avoids the need to have the function Which one do you advise? Thanks. |
Issue description
I want to use
direnv
to automatically activate python-virtualenvs when Icd
into a directory containing one.I have a few questions after going through the docs.
From what I read I need to create
.envrc
. What I don't understand is where to put this file, does it go in my$HOME
dir or do I have to create one per project repo?Does the
.direnvrc
serve the same purpose as the.envrc
?I looked at the virtualenv examples here https://github.com/direnv/direnv/wiki/Python#-virtualenv
but it isn't clear to me what direnv is doing.
The text was updated successfully, but these errors were encountered: