簡體   English   中英

激活任何conda環境后,conda命令停止工作

[英]After activating any conda environment conda commands stop working

我已經在Mac上重新安裝了miniconda。 如果我跑type conda在我的終端,我得到/Users/myusername/miniconda3/bin/conda 我可以創建一個conda環境,然后使用source activate myenv激活它。 執行此命令后,conda命令將給出此響應

(myenv) ➜  ~ conda list
local:3: command not found: any-json
usage: conda [-h] [-V] command ...

conda is a tool for managing and deploying applications, environments and packages.

Options:

positional arguments:
  command
    clean        Remove unused packages and caches.
    config       Modify configuration values in .condarc. This is modeled
                 after the git config command. Writes to the user .condarc
                 file (/Users/myusername/.condarc) by default.
    create       Create a new conda environment from a list of specified
                 packages.
    help         Displays a list of available conda commands and their help
                 strings.
    info         Display information about current conda install.
    install      Installs a list of packages into a specified conda
                 environment.
    list         List linked packages in a conda environment.
    package      Low-level conda package utility. (EXPERIMENTAL)
    remove       Remove a list of packages from a specified conda environment.
    uninstall    Alias for conda remove. See conda remove --help.
    search       Search for packages and display associated information. The
                 input is a MatchSpec, a query language for conda packages.
                 See examples below.
    update       Updates conda packages to the latest compatible version. This
                 command accepts a list of package names and updates them to
                 the latest versions that are compatible with all other
                 packages in the environment. Conda attempts to install the
                 newest versions of the requested packages. To accomplish
                 this, it may update some packages that are already installed,
                 or install additional packages. To prevent existing packages
                 from updating, use the --no-update-deps option. This may
                 force conda to install older versions of the requested
                 packages, and it does not prevent additional dependency
                 packages from being installed. If you wish to skip dependency
                 checking altogether, use the '--force' option. This may
                 result in an environment with incompatible packages, so this
                 option must be used with great caution.
    upgrade      Alias for conda update. See conda update --help.

optional arguments:
  -h, --help     Show this help message and exit.
  -V, --version  Show the conda version number and exit.

現在,如果我再次運行type conda ,我會得到conda is a shell function from /Users/myusername/miniconda3/etc/profile.d/conda.sh作為響應。 如果我打開一個新的終端,conda命令將再次運行,就像我之前運行`source activate myenv``一樣。

我想知道是什么引起了這個問題以及如何解決它。

也許值得一提的是,我在運行zshell時,已將export PATH=/Users/myusername/miniconda3/bin:$PATH到我的.zshrc文件中。

編輯1

使用conda activate給我以下錯誤

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If your shell is Bash or a Bourne variant, enable conda for the current user with

    $ echo ". /Users/myusername/miniconda3/etc/profile.d/conda.sh" >> ~/.bash_profile

or, for all users, enable conda with

    $ sudo ln -s /Users/myusername/miniconda3/etc/profile.d/conda.sh /etc/profile.d/conda.sh

The options above will permanently enable the 'conda' command, but they do NOT
put conda's base (root) environment on PATH.  To do so, run

    $ conda activate

in your terminal, or to put the base environment on PATH permanently, run

    $ echo "conda activate" >> ~/.bash_profile

Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bash_profile file.  You should manually remove the line that looks like

    export PATH="/Users/myusername/miniconda3/bin:$PATH"

^^^ The above line should NO LONGER be in your ~/.bash_profile file! ^^^

如果我按照錯誤消息告訴我的方式去做,那就在添加行. /Users/myusername/miniconda3/etc/profile.d/conda.sh . /Users/myusername/miniconda3/etc/profile.d/conda.sh到我的. /Users/myusername/miniconda3/etc/profile.d/conda.sh文件,那么conda命令不起作用。 例如, conda activate給我的信息與我在問題開頭粘貼的conda list相同。

編輯2我找到了解決方案。 /Users/myusername/miniconda3/etc/profile.d/conda.sh的bash腳本中,有一個名為/Users/myusername/miniconda3/etc/profile.d/conda.sh的函數,看起來像這樣

    conda() {
        if [ "$#" -lt 1 ]; then
            $_CONDA_EXE
        else
            /local cmd="$1"
            shift
            case "$cmd" in
                activate)
                    _conda_activate "$@"
                    ;;
                deactivate)
                    _conda_deactivate "$@"
                    ;;
                install|update|uninstall|remove)


           $_CONDA_EXE "$cmd" "$@" && _conda_reactivate
                ;;
            *)
                $_CONDA_EXE "$cmd" "$@"
                ;;
        esac
    fi
}

調試此功能時,我注意到cmd變量為空。 但是,如果將行/local cmd="$1"更改為local cmd="$1"我的所有問題都會解決。 我不知道為什么 有誰知道為什么嗎? 這個反斜杠是做什么的?

在〜/ .bash_profile文件中修改PATH。

您應該手動刪除看起來像這樣的行

export PATH="/Users/myusername/miniconda3/bin:$PATH"

上面的行應該不再位於〜/ .bash_profile文件中!

參考:

  1. https://github.com/conda/conda/issues/7980

暫無
暫無

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

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