0

我刚刚安装了 Canopy Express 并想测试它的虚拟环境集成。我发现当我停用虚拟环境时,我的系统 Python 恢复为默认安装:

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

除了对 Canopy 不熟悉之外,我对 OS X 也是新手。我怀疑这个问题与我的.bash_profile.profile文件有关,但我似乎看不到如何让它们相互协作。这是我目前的.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

这是我目前的.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
    }

其中一些条目来自我之前在没有 Canopy 的情况下安装 IPython 的尝试,所以我可能搞砸了 Canopy 的预期。如何配置这些文件以始终保留 Canopy Python?

4

1 回答 1

1

在您为 ProjectX 停用 venv 后,您可以简单地~/.bash_profile获取您的资源,以取回 Canopy 的 Python 作为默认 Python。

activate脚本在运行时默认为 s -- 查看--deactivate中的第 38 行。此行删除了有关 Canopy Python 被设置为默认 Python 的所有旧信息。在获取文件之前,您可以注释掉这一行。但是,我认为在调用 deactivate 之后运行是一个更简单的解决方法。~/Projects/ProjectX/myvenv/bin/activatedeactivate nondestructivesource ~/.bash_profile

于 2013-08-02T03:16:56.030 回答