簡體   English   中英

使用 Anaconda 安裝 Python 環境

[英]Installing a Python environment with Anaconda

我剛剛嘗試使用終端使用 Home-brew 安裝 Anaconda,並收到以下消息:

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

當我嘗試打開 anaconda 並嘗試創建 Python 環境時,我收到消息“找不到命令”。

問題是什么?

通過 Homebrew 安裝 anaconda

通過brew cask cask 通過執行安裝 anaconda

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

讓我們運行 jupyter notebook

嘗試在終端中執行jupyter notebook

這不起作用……為什么? 因為我們的 shell 不知道 anaconda 文件夾在哪里,所以讓我們將該文件夾添加到我們的 shell 路徑中。

設置環境路徑。

~/.zshrc文件頂部下方插入一行,因為當您嘗試在終端上執行 python 時,它會先搜索文件夾 /usr/local/anaconda3/bin,然后再搜索默認操作系統路徑,這意味着您可以執行 jupyter筆記本和 python。

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

重啟終端或使用source ~/.zshrc .zshrc 重新加載你的 shell 環境並執行 jupyter notebook 一個 output 將是這樣的

終端

參考: 使用 Homebrew 在 macOS 上安裝 anaconda

使用 Homebrew 安裝 Anaconda:

  1. Go 到您的終端並輸入brew cask install anaconda ,然后按回車鍵。
  2. 確保 anaconda 在您的PATH中。 您需要打開終端的配置文件(通常是 Mac 上的~/.zshrc )並找到以PATH=開頭的行。 在附近添加一行: export PATH="/usr/local/anaconda3/bin:$PATH" 這是 Homebrew 安裝 Anaconda 的地方。
  3. 退出並重新啟動您的終端。 這是確保加載新配置的最簡單方法。
  4. 測試它是否與which conda一起工作。

您現在應該可以使用conda命令了。

編輯:正如本主題中的類似帖子所指出的, conda activate的工作方式已從版本更改為版本。 如果上述方法沒有為您提供足夠好的結果,請嘗試以下方法來啟用conda activateconda deactivate命令。

對於 bash 或 zsh,把

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

在您的 ~/.zshrc 文件中將您的基礎環境放在 PATH 上,但不一定實際激活該環境。 嘗試刪除該行並將其替換為

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

按照官方 Anaconda 4.4.0 發行說明中的建議。

~/Anaconda3替換為您安裝 Anaconda 的路徑,如果您將其放在其他位置。

運行conda activate base會將基礎環境放在 PATH 上,並允許您訪問基礎環境中的可執行文件。

其他資源:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM