-
-
Notifications
You must be signed in to change notification settings - Fork 421
Is there a way to set environment variables for each version? #263
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
Comments
Came across this post in another git issue earlier today ... it has some code that is specific to miniconda, but it seems it could work in any situation. pyenv.d hook scripts: #178 (comment) ( Hope that helps @RobRoseKnows ) ! |
Pyenv-Virtualenv doesn't actually source the It's possible to execute arbitrary code with an
your_fn_name() {
if [[ $venv == "foo" ]]; then
export magic_word="xyzzy"
fi
}
after_activate your_fn_name This script will be pyenv-virtualenv/bin/pyenv-sh-activate Line 47 in e8c8fd9
eval d at pyenv-virtualenv/bin/pyenv-sh-activate Line 305 in e8c8fd9
|
@native-api Sorry, but this is not working. After a
When I replace the last line with the direct execution of the function, a When I activate my virtual environment, no SOMETHING in my environment variables. What did I not understand ? |
Sorry. I was writing from memory. The example above would work if In-shell subcommands (and their hooks) need to print commands to execute in the user's shell rather than execute them directly. I've tested the following code to work:
set_venv_envvars() {
echo 'export magic_word="xyzzy"'
}
after_activate set_venv_envvars Now: $ pyenv activate test
(test) $ set | grep magic
magic_word=xyzzy Note that you'll probably also need a similar |
Thank you for taking the time to respond to me, it works. |
I'd like to be able to set environment variables specific to each virtualenv created by pyenv when I enter a directory. I found Issue #55 that seems to mention this and says it's not currently supported, but it's also from 2014, so I was wondering if anything has changed since then.
I tried adding
export
statements to~/.pyenv/versions/3.6.5/envs/my-env/bin/activate
(where my-env is a local 3.6.5 virtualenv set in the.python-version
file) but they didn't get set. I'm planning on trying direnv as suggested in issue #55, but I was wondering if pyenv now has native support for this, or if such support is planned in the future.The text was updated successfully, but these errors were encountered: