После активации любой среды conda команды conda перестают работать

Я сделал новую установку miniconda на своем Mac. Если я запускаю 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 снова будут работать, как и раньше, когда я запускал `sourceactivatemyenv``

Мне интересно, что может быть причиной этой проблемы и как ее исправить.

Возможно, стоит упомянуть, что я добавил export PATH=/Users/myusername/miniconda3/bin:$PATH в свой файл .zshrc при запуске zshell.

Изменить 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 в мой файл .zshrc, то команды conda не будут работать. Например, conda activateвыдает то же сообщение, что и для conda list, которое я вставил в начале своего вопроса.

Редактировать 2 Я нашел решение. В сценарии bash, расположенном в /Users/myusername/miniconda3/etc/profile.d/conda.shthere, есть функция conda, которая выглядит так:

    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", все мои проблемы будут решены. Я не знаю почему. У кого-нибудь есть идеи, почему? что делает эта обратная косая черта?


person Joakim    schedule 04.01.2019    source источник
comment
Я думаю, вам понадобится /Users/myusername/miniconda3/bin в вашем пути, иначе он может искать этот двоичный файл явно, а не каталог двоичных файлов в этом пути к папке.   -  person C.Nivs    schedule 04.01.2019
comment
Извините, но я написал неправильный путь в своем вопросе, я обновил его. Я уже использую путь, который вы предложили.   -  person Joakim    schedule 04.01.2019
comment
Вы получаете подобное поведение при активации через conda activate myenv? Изменения для активации были представлены в 4.4, в том числе больше не рекомендуется добавлять miniconda3/bin к PATH.   -  person merv    schedule 04.01.2019
comment
Я обновил свой вопрос, я попытался удалить miniconda3/bin из своего пути и вместо этого добавить . /Users/myusername/miniconda3/etc/profile.d/conda.sh   -  person Joakim    schedule 07.01.2019


Ответы (1)


Измените PATH в файле ~/.bash_profile.

Вы должны вручную удалить строку, которая выглядит как

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

Приведенная выше строка НЕ ​​ДОЛЖНА БОЛЬШЕ находиться в вашем файле ~/.bash_profile!

Ссылка:

  1. https://github.com/conda/conda/issues/7980
person DataFramed    schedule 20.05.2019