問題描述
按照 這些步驟 并安裝 conda 后,似乎 conda init
更新了我的 .bash_profile
由于某種原因不正確.它在運行 .bashrc
之后添加它的內(nèi)容,因此當(dāng) bash
啟動時,由于某種原因,我的所有 conda 內(nèi)容都沒有正確啟動.我最終不得不手動將 .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
但這似乎會導(dǎo)致問題(例如,conda init bash
沒有將內(nèi)容添加到 .bash_profile
的正確位置.圖形/dmg 安裝程序甚至將內(nèi)容安裝在~/opt
出于某種原因).我概述了對我有用的 hacky 解決方案here,但我認為這不是正確的做事方式.
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.
是什么導(dǎo)致了我的問題,我該如何解決?
What is causing my problems and how do I fix it?
推薦答案
正如 chepner 的評論所說,正如我自己最終發(fā)現(xiàn)的那樣,conda init
不能開箱即用某些原因(例如,如果它修改了 .bash_profile
很明顯用戶將在某處運行他們的 .bashrc
文件,因此它應(yīng)該在此之前正確添加它的內(nèi)容,或者至少在恕我直言).無論如何,這是一個工作文件的例子:
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 ":" "
"
# >>> 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
在我手動更改后.
我沒想到我需要自己修改這些東西.也許我不應(yīng)該信任命令/安裝程序等,而是更頻繁地查看他們終端的輸出.
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 中使用集成終端,情況會更糟.為此,請閱讀此內(nèi)容以避免錯誤/奇怪的行為: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
在干凈的環(huán)境中啟動終端 VS 中的集成終端代碼的行為總是與普通終端略有不同,特別是在 Linux 和 macOS 上.原因是環(huán)境總是繼承自 VS Code 的窗口(實例)和 VS代碼/電子相關(guān)的環(huán)境變量被刪除,而普通終端通常會從 Dock/Start 菜單啟動并使用系統(tǒng)環(huán)境.這可能會導(dǎo)致某些問題場景,例如 Python 虛擬環(huán)境被破壞,因為他們?nèi)绾问褂?$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.
有一個新的預(yù)覽選項,terminal.integrated.inheritEnv,它當(dāng) false 導(dǎo)致終端不使用 VS Code 的環(huán)境.
There's a new preview option, terminal.integrated.inheritEnv, that when false causes the terminal to not use VS Code's environment.
相反,根據(jù)平臺,它將執(zhí)行以下操作:
Instead, depending on the platform, it will do the following:
Linux:獲取和使用VS的父進程的環(huán)境代碼的主要過程".macOS:拉一把重要的環(huán)境當(dāng)前環(huán)境中的變量,僅包含它們.最終我們希望 macOS 的行為與 Linux 相同,但目前是獲取環(huán)境的問題.窗戶:目前此設(shè)置不影響 Windows.主要可見結(jié)果將 inheritEnv 設(shè)置為 false 是 $SHLVL(shell 級別)現(xiàn)在應(yīng)該是1 和 $PATH 不應(yīng)包含重復(fù)的路徑,前提是您的啟動腳本不會有意包含它們.
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.
完全關(guān)閉和打開 vscode 似乎也很有幫助.
希望這將節(jié)省人們更改 bash 文件以及重新安裝和卸載一堆東西的日子.
Hopefully, this will save people's days of changing bash files around and re-installing and uninstalling a bunch of things.
另一個有用的提示是轉(zhuǎn)到 vscode 左上角的 code
點擊它然后轉(zhuǎn)到首選項然后設(shè)置.然后您可以通過取消單擊/選擇將 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.
這篇關(guān)于為什么 conda init 錯誤地更新了我的 .bash_profile?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!