問題描述
嘗試通過 Windows NT 上的 cygwin 界面使用 anaconda 設置環境,但失敗了.
Trying to set up environments with anaconda through the cygwin interface on Windows NT, and failing.
創建環境(conda create -n test_env
)工作正常.但是 activate test_env
失敗.
Creating environments (conda create -n test_env
) works fine. But activate test_env
fails.
我嘗試用以下方法破解它:
I tried hacking it with:
export PATH=/cygdrive/c/users/nick/anaconda3/envs/test:$PATH
這修正了一些行為(which python
指向正確的 python).但是如果我然后執行conda install"命令,它會安裝到根 anaconda 目錄中,而不是環境中.也許導出是 bash 會話的本地導出,并且 conda 調用了不同版本的 PATH?有沒有辦法讓PATH全局修改?
This fixes some behavior (which python
points to the right python). But if I then do a "conda install" command, it installs into the root anaconda directory, not the environment. Perhaps the export is local to the bash session, and conda calls a different version of PATH? There a way to make the modification of PATH global?
推薦答案
在與這個問題搏斗了一段時間后,我想我已經實現了一個合理可行的方法,將 Anaconda 的 python(和相關環境)集成到 Cygwin 中.假設您有 Cygwin 和 Anaconda 獨立工作,要從 Cygwin 訪問所有 Anaconda 工具,.bash_profile
中的以下設置似乎可以解決問題.(我只包含了那些與集成相關的 .bash_profile
部分......希望我不會無意中遺漏一些東西.)
After wrestling with the problem for quite some time, I think I've achieved a reasonable and workable method to integrate Anaconda's python (and associated environments) into Cygwin. Assuming you have both Cygwin and Anaconda working independently, to access all of the Anaconda tools from Cygwin, the following setup in .bash_profile
seems to do the trick. (I have only included those portions of .bash_profile
relevant to the integration... hoping I did not miss something inadvertently.)
這個設置基本上做了三件事.首先,用戶需要將目錄 $CONDA_BASE_DIR
顯式設置為 conda/anaconda/miniconda 基礎環境的安裝位置.其次,.bash_profile
中有一個功能,可以使用 shell 變量 $CONDA_DEFAULT_ENV
來跟蹤當前的 conda 環境.最后,我們定義一個別名 cyg-conda
和一個函數 cyg-activate
用作標準 conda
和 的替換命令>激活
命令.請注意,變量名 $CONDA_DEFAULT_ENV
是特殊的,由實際的 conda
命令在內部使用.
This setup essentially does three things. First, the user needs to explicitly set the directory $CONDA_BASE_DIR
to be the location where the base environment for conda/anaconda/miniconda was installed. Second, there is a functionality in .bash_profile
to keep track of the current conda environment using a shell variable $CONDA_DEFAULT_ENV
. And finally, we define an alias cyg-conda
and a function cyg-activate
to be used as replacement commands for the standard conda
and activate
commands. Please note that the variable name $CONDA_DEFAULT_ENV
is special, and used internally by the actual conda
command.
使用此設置,我可以像通常使用 conda
一樣使用 cyg-conda
和 cyg-activate
和activate
在 Anaconda 命令提示符處,同時使環境可用于我的 Cygwin bash shell.
Using this setup, I am able to use cyg-conda
and cyg-activate
in the same way I would typically use conda
and activate
at the Anaconda command prompt, while making the environments available to my Cygwin bash shell.
當然愿意接受改進等方面的建議.
Certainly open to suggestions for improvements, etc.
###############################################################################
# Anaconda Environment Selection - Plese set CONDA_BASE_DIR to the directory
# containing the base installation of anaconda/miniconda.
export CONDA_BASE_DIR=/cygdrive/c/Users/Patrick/Miniconda3
# Proxy Servers & Network Setup (if needed)
export HTTP_PROXY=
export HTTPS_PROXY=
# IMPORTANT - Ignore carriage returns when using a Cygwin environment.
export SHELLOPTS
set -o igncr
###############################################################################
# Manage conda environments for Python. We check the environment variable
# $CONDA_DEFAULT_ENV to see which environment is desired. The default (root)
# environment will be chosen if nothing is specified. Note that this variable
# will be explicitly managed by the cyg-activate ( ) function we have defined
# below, specifically for the purpose of changing environments. The root
# environment is also handled slightly different from the others when it comes
# to setting the CONDA_DEFAULT_ENV variable.
if [ ${CONDA_DEFAULT_ENV} ] && [ ${CONDA_DEFAULT_ENV} != 'root' ]
then
# SELECT ONE OF THE NON-DEFAULT ENVIRONMENTS
export CONDA_PREFIX=${CONDA_BASE_DIR}/envs/${CONDA_DEFAULT_ENV}
else
# SELECT THE DEFAULT ENVIRONMENT (and set CONDA_DEFAULT_ENV full path)
export CONDA_DEFAULT_ENV=root
export CONDA_PREFIX=${CONDA_BASE_DIR}
fi
###############################################################################
# Define cyg-conda and cyg-activate to facilitate management of conda.
alias cyg-conda=${CONDA_BASE_DIR}/Scripts/conda.exe
cyg-activate() {
export CONDA_DEFAULT_ENV=$1
source ~/.bash_profile
cyg-conda info --envs
}
###############################################################################
# PATH - ALl of the anaconda/miniconda path entries appear first.
PATH=
PATH=$PATH:$CONDA_PREFIX
PATH=$PATH:$CONDA_PREFIX/Library/mingw-w64/bin
PATH=$PATH:$CONDA_PREFIX/Library/usr/bin
PATH=$PATH:$CONDA_PREFIX/Library/bin
PATH=$PATH:$CONDA_PREFIX/Scripts
PATH=$PATH:$HOME/scripts
PATH=$PATH:$HOME/local/bin
PATH=$PATH:/usr/local/bin
PATH=$PATH:/usr/bin
export PATH
###############################################################################
這篇關于在 Windows 上使用帶有 cygwin 的 anaconda 環境的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!