为什么conda init错误地更新了我的.bash_profile? [英] Why is conda init updating my .bash_profile incorrectly?

查看:1295
本文介绍了为什么conda init错误地更新了我的.bash_profile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照这些步骤并安装conda之后,似乎conda init由于某些原因错误地更新了我的.bash_profile.它在运行.bashrc之后添加了它的内容,因此当bash启动时,由于某种原因,我的所有conda东西都无法正确启动.我最终不得不手动更改.bash_profile来使其看起来像这样:

After following these steps and installing conda it seems that conda init updates my .bash_profile incorrectly for some reason. It adds it's content AFTER running .bashrc and thus when bash gets started all my conda stuff does not get initiated correctly for some reason. I ended up having to change the .bash_profile manually to look like this:

(automl) brandBrandoParetoopareto~ $ cat .bash_profile
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/brandBrandoParetoopareto/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/brandBrandoParetoopareto/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/brandBrandoParetoopareto/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/brandBrandoParetoopareto/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

我安装它的方式是使用我认为是官方安装:

The way I installed it was using what I thought was the official installation:

sh Anaconda3-2020.02-MacOSX-x86_64.sh

,但这似乎引起问题(例如conda init bash没在正确的位置添加内容到.bash_profile.出于某些原因,图形/dmg安装程序甚至在~/opt处安装了东西).我在此处概述了适用于我的hacky解决方案,但我认为这样做不是正确的方法.

but that seems to be causing issues (e.g. conda init bash not adding the stuff in the right place to .bash_profile. The graphical/dmg installer even installs things at ~/opt for some reason). I outlined the hacky solution that worked for me here but I assume that is not the right way to be doing things.

是什么导致我的问题以及如何解决?

What is causing my problems and how do I fix it?

推荐答案

正如chepner的评论所说,正如我最终发现的那样,conda init由于某些原因(例如,如果不是修改.bash_profile,很明显,用户将在其中的.bashrc文件中运行该文件,因此它应该在此之前正确添加其内容,或者至少在imho中添加).无论如何,这是一个工作文件的示例:

As the comment by chepner says as I discovered on my own eventually is that conda init doesn't work out of the box for some reason (e.g. if it modifies .bash_profile it's obvious the user will run their .bashrc file somewhere there so it should add it's contents correctly before that, or at least in imho). Anyway this is an example of a working file:

(automl) brandBrandoParetoopareto~/automl-meta-learning $ cat ~/.bash_profile 
echo ----Running .bash_profile

conda -V
python -V
echo $PATH
echo $PATH | tr ":" "\n"

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/brandBrandoParetoopareto/anaconda3/envs/automl/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/brandBrandoParetoopareto/anaconda3/envs/automl/etc/profile.d/conda.sh" ]; then
        . "/Users/brandBrandoParetoopareto/anaconda3/envs/automl/etc/profile.d/conda.sh"
    else
        export PATH="/Users/brandBrandoParetoopareto/anaconda3/envs/automl/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

echo ----Completed running .bash_profile

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

在我手动更改它之后.

我不会猜到我需要自己修改这些内容.也许我不应该信任命令/安装程序等,而查看输出到其终端的频率更高.

I would have not guessed I needed to modify these things myself. Perhaps I should not trust commands/installers etc and see what the output to their terminal is more often.

此外,如果像我一样在vscode中使用集成终端,情况会更糟.为此,请阅读以下内容以避免错误/奇怪的行为: https://code.visualstudio.com/updates/v1_36#_launch-terminals-with-clean-environments

Also, things are worse if your using the integrated terminal in vscode like I was. For that read this to avoid errors/strange behaviours: https://code.visualstudio.com/updates/v1_36#_launch-terminals-with-clean-environments

启动具有干净环境的终端VS中的集成终端 代码的行为始终与普通终端有所不同, 特别是在Linux和macOS上.原因是环境 总是从VS Code的窗口(实例)和VS继承而来 删除了与代码/电子相关的环境变量,而 普通终端通常会从Dock/Start菜单中启动 并使用系统环境.这可能会导致某些问题 场景,例如Python虚拟环境被破坏是因为 如何使用$ PATH变量.

Launch terminals with clean environments The Integrated Terminal in VS Code has always acted a little differently to normal terminals, particularly on Linux and macOS. The reason is that the environment was always inherited from VS Code's window (instance) and VS Code/Electron-related environment variables were removed, whereas a normal terminal would typically be launched from the Dock/Start menu and use the system environment. This could cause issues in certain scenarios, for example Python virtual environments were broken because of how they use the $PATH variable.

有一个新的预览选项,terminal.integrated.inheritEnv,该选项 如果为false,则导致终端不使用VS Code的环境.

There's a new preview option, terminal.integrated.inheritEnv, that when false causes the terminal to not use VS Code's environment.

相反,取决于平台,它将执行以下操作:

Instead, depending on the platform, it will do the following:

Linux:获取和使用VS父进程的环境 代码的主要过程". macOS:拉一些重要的环境 当前环境中的变量,仅包含它们. 最终,我们希望macOS的行为与Linux相同,但在那里 当前在获取环境方面存在问题. Windows:目前 此设置不会影响Windows.的主要可见结果 将InheritEnv设置为false是现在应该将$ SHLVL(shell级别)设置为 1和$ PATH不应包含重复的路径,但前提是您必须启动 脚本没有故意包含它们.

Linux: Fetch and use the environment of the parent process of VS Code's "main process". macOS: Pull a handful of important environment variables off the current environment and only include them. Eventually we would like macOS to behave the same as Linux but there are currently issues with fetching environments. Windows: Currently this setting does not affect Windows. The main visible result of setting inheritEnv to false is that $SHLVL (shell level) should now be 1 and $PATH should not include duplicate paths, provided your launch scripts don't intentionally include them.

terminal.integrated.inheritEnv的默认值为true,即 以前的行为,但我们可能会将值切换为false 将来.

The default value for terminal.integrated.inheritEnv is true, which is the previous behavior, but we will probably switch the value to false in the future.

完全关闭和打开vscode似乎很有帮助.

希望这将节省人们改变bash文件以及重新安装和卸载一堆东西的日子.

Hopefully, this will save people's days of changing bash files around and re-installing and uninstalling a bunch of things.

另一个有用的提示是,在vscode的左上方显示code,然后单击它,然后转到首选项,然后进行设置.然后,您可以通过取消选择terminal.integrated.inheritEnv将其更改为false.

Another helpful tip is to go the top left of vscode where it says code click it then go to preferences and then settings. Then you can change the terminal.integrated.inheritEnv to false by unclicking/selecting it.

这篇关于为什么conda init错误地更新了我的.bash_profile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆