简体   繁体   中英

Installing a Python environment with Anaconda

I have just tried to install Anaconda using Home-brew using the terminal, and receive the following message:

L-MBP:agda-stdlib le$ brew install conda 
Updating Homebrew...
Error: No available formula with the name "conda"

==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
  git -C "$(brew --repo homebrew/core)" fetch --unshallow
Error: No previously deleted formula found.

==> Searching for similarly named formulae...
Error: No similarly named formulae found.

==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.

L-MBP:agda-stdlib le$ brew install anaconda
Error: No available formula with the name "anaconda" 
Found a cask named "anaconda" instead. Try
  brew cask install anaconda``

L-MBP:agda-stdlib le$ brew cask install anaconda
==> Caveats
Cask anaconda installs files under /usr/local. The presence of such
files can cause warnings when running `brew doctor`, which is considered
to be a bug in Homebrew Cask.
...
installation finished.
==> Changing ownership of paths required by anaconda; your password may be necessary
🍺  anaconda was successfully installed!

L-MBP:agda-stdlib le$ conda create --name snakes python=3.7.2
-bash: conda: command not found
L-MBP:agda-stdlib le$ conda -bash: conda: command not found

When I try to open anaconda and when I try to make a Python environment, I receive the message ''command not found''.

What is the problem?

Install anaconda via Homebrew

Install anaconda via brew cask by executing

➜ brew cask install anaconda   (or)
➜ brew install --cask anaconda [Newer versions of Homebrew]
.
.
.
PREFIX=/usr/local/anaconda3
.
.
.
🍺  anaconda was successfully installed!

Let's run jupyter notebook

Try to executing jupyter notebook in your terminal.

It's not works … why? Because our shell doesn't know where is the anaconda folder so is, let's add that folder to our shell path.

Setup the environment path.

Insert a line below on top of your ~/.zshrc file because when you trying to execute python on terminal it'll search on folder /usr/local/anaconda3/bin first before search on default operating system path which means you can execute jupyter notebook and python.

export PATH="/usr/local/anaconda3/bin:$PATH"

Restart terminal or use source ~/.zshrc to reload your shell environment and execute jupyter notebook an output will be like this

终端

Reference: Install anaconda on macOS with Homebrew

To install Anaconda using Homebrew:

  1. Go to your terminal and type brew cask install anaconda , then hit return.
  2. Make sure that anaconda is in your PATH . You'll need to open your terminal's configuration file (usually this is ~/.zshrc on a mac) and find the line that starts PATH= . Add a line nearby that says: export PATH="/usr/local/anaconda3/bin:$PATH" . This is where Homebrew installs Anaconda.
  3. Quit and restart your terminal. This is the easiest way to make sure that the new configuration will be loaded.
  4. Test whether it's working with which conda .

You should now be able to use the conda command.

EDIT: As similar posts in this topic have pointed out, the way conda activate works has changed from version to version. If the above isn't giving you good enough results, try the following method to enable the conda activate and conda deactivate commands.

For bash or zsh, putting

export PATH="/opt/conda/bin:$PATH"

in your ~/.zshrc file puts your base environment on PATH, but doesn't necessarily actually activate that environment. Try removing that line and replacing it with

. ~/Anaconda3/etc/profile.d/conda.sh
conda activate base

as recommended in the official Anaconda 4.4.0 release notes .

Replace ~/Anaconda3 with the path where you installed Anaconda, if you put it somewhere else.

Running conda activate base puts the base environment on PATH and gives you access to the executables in the base environment.

Additional Resources:

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