我在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! ^^^
如果我按照错误消息的指示执行操作,即在我的.zshrc文件中添加行. /Users/myusername/miniconda3/etc/profile.d/conda.sh
,则conda命令无效。例如,conda activate
给我的信息与问题开始时粘贴的conda list
相同。
编辑2
我找到了解决方案。 /Users/myusername/miniconda3/etc/profile.d/conda.sh
中的bash脚本中有一个名为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"
,我的所有问题都将解决。我不知道为什么有谁知道为什么吗?反斜杠是做什么用的?
答案 0 :(得分:0)
在〜/ .bash_profile文件中修改PATH。
您应该手动删除看起来像这样的行
export PATH="/Users/myusername/miniconda3/bin:$PATH"
上面的行应该不再位于〜/ .bash_profile文件中!
参考: