Question

I just installed Canopy Express and wanted to test its virtual environment integration. I find that when I deactivate a virtual environment, my system Python reverts to the default installation:

Mímisbrunnr:~ me$ which python
/Users/me/Library/Enthought/Canopy_64bit/User/bin/python
Mímisbrunnr:~ me$ venv ~/Projects/ProjectX/myvenv
Mímisbrunnr:~ me$ source ~/Projects/ProjectX/myvenv/bin/activate
(myvenv) Mímisbrunnr:~ me$ deactivate
Mímisbrunnr:~ me$ which python
/usr/bin/python

In addition to being new to Canopy, I am new to OS X. I suspect this problem has to do with my .bash_profile and .profile files, but I can't seem to see how to make them cooperate with each other. Here is my current .profile:

# OS X looks in here first, but aliases in here won't work in xterm, screen, etc., so we port it over
echo 'source ~/.profile' >> ~/.bash_profile


# Added by Canopy installer on 2013-08-01
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
#VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/me/Library/Enthought/Canopy_64bit/User/bin/activate

and here is my current .bash_profile:

# set architecture flags to let compiler know it should assume 64 bits
export ARCHFLAGS="-arch x86_64"

# Added by Canopy installer on 2013-08-01
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/me/Library/Enthought/Canopy_64bit/User/bin/activate

# ensure user-installed binaries take precedence
#export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

# alias to start Canopy
alias canopy='open /Applications/Canopy.app'

# alias to combine cd & ls
function cdl () {
    cd "$@" && ls
    }

Some of these entries are from my earlier attempts to install IPython without Canopy, so I may have screwed up in terms of what Canopy expects. How do I configure these files to keep the Canopy Python at all times?

Was it helpful?

Solution

You can simply source your ~/.bash_profile after you have deactivated your venv for ProjectX to get back Canopy's Python as the default Python.

The activate script by default deactivates when it is run -- Look at line #38 in ~/Projects/ProjectX/myvenv/bin/activate -- deactivate nondestructive. This line removes all the old information about Canopy Python being set as your default Python. You could possibly comment out this line, before sourcing the file. But, I think running source ~/.bash_profile after calling deactivate, is a much simpler work around.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top