简体   繁体   中英

Anaconda Select Environments Mac OS

I'm running Anaconda 3 with Python 3.6 on MacOS 10.12.

I created an environment using python 2.7 and opencv using conda create --name my-env python=2.7 anaconda (eg here) . I activated the environment using source activate my-env and installed opencv . Both creation and activation seem to have worked: the anaconda3/envs/my-env folder exists and my terminal says (my-env) bob:~ alice '.

But how do I get Anaconda to use the new environment?

I tried:

  • starting the default Anaconda-Navigator.app , this just uses the default python path
  • changing the path in my ~/.bash-profile , but Anaconda still tries the default python path
  • starting the Anaconda-Navigator.app located in the my-env folder, fails with the OS error message "cannot be opened"
  • starting from terminal exits with the error message: FSPathMakeRef(~/anaconda3/envs/my-env/Anaconda-Navigator) failed with error -43.

Because I read somewhere that Anaconda 3 might not play nicely with Python 2.7, I tried the same workflow again, but creating an environment using python 3.5.4. Again to no avail.

What am I missing?

there a two possibilities to run a program in an env once the env has been created with conda:

  1. Through default anaconda-navigator (the GUI of anaconda), there should be a menu on the left, with the following options: Home, Environments, Projects(beta),...
    Simply klick on environments and choose/create a new one(see screenshot)

在此处输入图片说明

The "Applications on base(root)" can also be changed. If it does not display these options I recommend you to update conda.

  1. Via terminal: activate the env as you mentioned earlier and then simply run the program you want, for example spyder, it should then use the right py version.

My default version of anaconda, the "root(base)" runs with python 2, therefore I added a few lines in my .bash_profile file to easily run python/spyder in either a default env or a specific one. maybe you can use something similar.

NONE='\033[00m'
YELLOW='\033[01;33m'

spy() {
    if [[ "${1}" == "" ]]
    then
        ENV="py36env"
    else 
        ENV=${1}
    fi

    source activate ${ENV} #enter env
    echo -e "${YELLOW}CURRENT ENVIRONMENT: ${ENV} ${NONE}"  
    spyder               #open spyder
    echo -e "${YELLOW}EXIT ${ENV} ${NONE}"
    source deactivate    #exit env when spyder is quitted
}

You can now run spyder in the env "XXX" by entering "spy XXX" in the terminal. Or the default one by typing in "spy".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM