conda postactivate hook?

330 views
Skip to first unread message

steve...@gmail.com

unread,
Jul 17, 2014, 8:56:18 PM7/17/14
to anac...@continuum.io
Is there a conda equivalent of virtualenv's postactivate hook? e.g. I'd like to export PATH differently for every conda env. 

Thanks!

Aaron Meurer

unread,
Jul 18, 2014, 11:53:13 AM7/18/14
to anaconda
No there isn't presently.

Aaron Meurer
> --
> Anaconda Community Support Group Brought to you by Continuum Analytics
> ---
> You received this message because you are subscribed to the Google Groups
> "Anaconda - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to anaconda+u...@continuum.io.
> To post to this group, send email to anac...@continuum.io.
> Visit this group at http://groups.google.com/a/continuum.io/group/anaconda/.

Sebastian M Cheung

unread,
Mar 1, 2015, 4:24:35 PM3/1/15
to anac...@continuum.io
This tutorial also assumes there is PostActivate file created by virtualenv but as pointed out,
there is none when created by conda create.

https://realpython.com/blog/python/flask-by-example-part-1-project-setup/

Travis Swicegood

unread,
Mar 2, 2015, 1:30:35 PM3/2/15
to anac...@continuum.io
There is one as of Conda v3.8 though we haven't updated the documentation to reflect it yet (lots of new features in that release and we haven't gotten around to documenting them all yet). 

There are two scripts to work with: activate and deactivate scripts.  On OS X and Linux they go in the following directories:

    $PREFIX/etc/conda/activate.d/anything.sh
    $PREFIX/etc/conda/deactivate.d/anything.sh

Replace $PREFIX with the path to your environment.  Any file with the extension ".sh" will be sourced, so you can use that execute commands, set environment variables, and so on.  Best practice for environment variables (like those referenced in the blog post) is to add a counter deactivate.d script that calls `unset MY_VARIABLE` for each variable you set.

The same is available for Windows, except they're .bat files and they're executed.

Fun side fact, those files can be inside a conda package so if you have activation scripts that need to be shared across an entire team, you can add those files to a conda package and make it one of your requirements.

Reply all
Reply to author
Forward
0 new messages