我使用zsh命令,但是调用source activate时出现报错,/h… · The Chat Archive
Explore / Programming 我使用zsh命令,但是调用source activate时出现报错,/home/fl/dev-environment-setup.sh: line 1: source:… Save Share Download ▾ Report我使用zsh命令,但是调用source activate时出现报错,/home/fl/dev-environment-setup.sh: line 1: source: activate: file not found,使用bash命令时调用source activate不存在报错,可能得原因是什么
以下是dev-environment-setup.sh文件
source activate
conda deactivate
source /home/fl/switch-cuda_zsh_bash.sh 11.8
以下是我的环境变量文件vim ~/.bashrc ,
If not running interactively, don't do anything
case $- in
i ) ;;
*) return;;
esac
don't put duplicate lines or lines starting with space in the history.
See bash(1) for more options
HISTCONTROL=ignoreboth
append to the history file, don't overwrite it
shopt -s histappend
for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
check the window size after each command and, if necessary,
update the values of LINES and COLUMNS.
shopt -s checkwinsize
If set, the pattern "**" used in a pathname expansion context will
match all files and zero or more directories and subdirectories.
#shopt -s globstar
make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
set variable identifying the chroot you work in (used in the prompt below)
if [ -z "{debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot= (cat /etc/debian_chroot)
fi
set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
uncomment for a colored prompt, if the terminal has the capability; turned
off by default to not distract the user: the focus in a terminal window
should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
color_prompt=yes
else
color_prompt=
fi
fi
if [ "c o l o r p r o m p t " = y e s ] ; {debian_chroot:+( '
else
PS1=' debian_chroot)}\u@\h:\w$ '
fi
unset color_prompt force_color_prompt
Show full message · 146 lines Assistant2024-09-24 03:20 UTC Copy response
您遇到的问题主要源于 Conda 版本更新 以及 不同 Shell(zsh 和 bash)对 Conda 的初始化处理 。以下是详细的分析和解决方案:
问题原因
source activate 已被弃用 :
在较旧的 Conda 版本中,激活环境时常使用 source activate <env> 或 source activate(默认环境)。
Copy first prompt
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 1 (2 messages)
Language en
Conversation date Sep 24, 2024
Added to archive Nov 17, 2026
ID 01m7h41vbjnb9082n56jqk8kpkSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 3398d17d1ab6d7efe8b1b7ebf9ac1a4e
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
t h e n P S 1 = ′ color_prompt" = yes ]; then
PS1=' co l o r p r o m pt " = y es ] ; t h e n P S 1 = ′
debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\
{debian_chroot:+(
If this is an xterm set the title to user@host:dir case "T E R M " i n x t e r m ∗ ∣ r x v t ∗ ) P S 1 = " \[ \e ] 0 ; TERM" in
xterm*|rxvt*)
PS1="\[\e]0; T E R M " in x t er m ∗ ∣ r xv t ∗ ) P S 1 = " \[ \e ] 0 ; {debian_chroot:+(debian_chroot)}\u@\h: \w\a\] PS1"
;;
*)
;;
esac
enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "( d i r c o l o r s − b / . d i r c o l o r s ) " ∣ ∣ e v a l " (dircolors -b ~/.dircolors)" || eval " ( d i r co l or s − b /. d i r co l or s ) "∣∣ e v a l " (dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
code Copy code
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
colored GCC warnings and errors #export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
some more ls aliases alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
Add an "alert" alias for long running commands. Use like so:
sleep 10; alert alias alert='notify-send --urgency=low -i "( [ ([ ([ ? = 0 ] && echo terminal || echo error)" "(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert //''')"'
Alias definitions.
You may want to put all your additions into a separate file like
~/.bash_aliases, instead of adding them here directly.
See /usr/share/doc/bash-doc/examples in the bash-doc package. if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
enable programmable completion features (you don't need to enable
this, if it's already enabled in /etc/bash.bashrc and /etc/profile
sources /etc/bash.bashrc). if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
>>> conda initialize >>>
!! Contents within this block are managed by 'conda init' !! __conda_setup="('/home/fl/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ ? -eq 0 ]; then
eval "__conda_setup"
else
if [ -f "/home/fl/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/fl/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/fl/anaconda3/bin: PATH"
fi
fi
unset __conda_setup
<<< conda initialize <<< export LIBRARY_PATH=/usr/local/cuda-11.8/lib64/stubs:L I B R A R Y P A T H e x p o r t H F E N D P O I N T = h t t p s : / / h f − m i r r o r . c o m e x p o r t T M P D I R = / h o m e / f l / t m p e x p o r t A N A C O N D A H O M E = / h o m e / f l / . c o n d a / e n v s / d a t a p r e p e x p o r t P Y T H O N I N C L U D E = / h o m e / f l / . c o n d a / e n v s / d a t a p r e p / i n c l u d e / p y t h o n 3.10 e x p o r t P Y T H O N I N C L U D E = / h o m e / f l / . c o n d a / e n v s / d a t a p r e p / l i b / p y t h o n 3.10 / s i t e − p a c k a g e s / n u m p y / c o r e / i n c l u d e : LIBRARY_PATH
export HF_ENDPOINT=https://hf-mirror.com
export TMPDIR=/home/fl/tmp
export ANACONDA_HOME=/home/fl/.conda/envs/dataprep
export PYTHON_INCLUDE=/home/fl/.conda/envs/dataprep/include/python3.10
export PYTHON_INCLUDE=/home/fl/.conda/envs/dataprep/lib/python3.10/site-packages/numpy/core/include: L I B R A R Y P A T H e x p or t H F E N D P O I N T = PYTHON_INCLUDE
export PYTHONPATH=/data/fl/hed/caffe/python/:P Y T H O N P A T H e x p o r t P Y T H O N P A T H = / d a t a / f l / h e d / c a f f e / d i s t r i b u t e / p y t h o n / : PYTHONPATH
export PYTHONPATH=/data/fl/hed/caffe/distribute/python/: P Y T H O N P A T H e x p or tP Y T H PYTHONPATH
export PYTHONPATH=/data/fl/hed/caffe/python/:P Y T H O N P A T H e x p o r t P Y T H O N P A T H = / d a t a / f l / h e d / c a f f e / d i s t r i b u t e / p y t h o n / : PYTHONPATH
export PYTHONPATH=/data/fl/hed/caffe/distribute/python/: P Y T H O N P A T H e x p or tP Y T H PYTHONPATH
export CAFFE_ROOT=/data/fl/hed/caffe/
export PATH=/data/fl/blender-3.3.1-linux-x64:P A T H e x p o r t P A T H = / h o m e / f l / b l e n d e r / b l e n d e r − 3.3.0 − l i n u x − x 64 : PATH
export PATH=/home/fl/blender/blender-3.3.0-linux-x64: P A T H e x p or tP A T H = / h o m e / f l / b l PATH
export JAVA_HOME=/usr/bin/java
export PATH=P A T H : PATH: P A T H : JAVA_HOME/bin
export PATH=/home/fl/anaconda3/bin:$PATH
从 Conda 4.4 版本开始,推荐使用 conda activate <env>,并且 source activate 方式已经被弃用或不再推荐。
Shell 初始化问题 :
您的 .bashrc 文件中已经通过 conda init 初始化了 Conda,这主要针对 Bash。
对于 Zsh ,您需要确保 Conda 也已针对 Zsh 进行初始化,否则 Zsh 不会正确识别 conda 命令。
脚本中缺少环境名称 :
您的 dev-environment-setup.sh 脚本中使用了 source activate,但未指定具体的环境名称。这在当前的 Conda 版本中可能导致混淆或错误。
解决方案
初始化 Conda 对于 Zsh :
由于您主要使用 Zsh,确保 Conda 已针对 Zsh 进行初始化。
执行以下命令:
bash Copy code
conda init zsh
这将会修改您的 Zsh 配置文件(通常是 ~/.zshrc),添加必要的 Conda 初始化代码。
重启终端或重新加载配置 :
执行完成 conda init zsh 后,您需要重新打开终端,或者手动重新加载 Zsh 配置:
bash Copy code
source ~/.zshrc
更新 dev-environment-setup.sh 脚本 :
使用 conda activate 替代 source activate,并且明确指定您要激活的环境名称。如果您不确定环境名称,可以先使用 conda env list 查看现有环境。
例如,如果您的环境名称为 base,脚本应修改为:
bash Copy code
#!/bin/zsh
conda activate base
conda deactivate
source /home/fl/switch-cuda_zsh_bash.sh 11.8
注意事项 :
确保脚本的第一行指定了正确的 Shell(如 #!/bin/zsh)。
如果您希望激活特定的 Conda 环境,请将 base 替换为您的环境名称。
检查 Conda 安装路径 :
确保 Conda 安装路径在您的 PATH 环境变量中,并且没有冲突或冗余。例如,您在 .bashrc 中多次添加了 /home/fl/anaconda3/bin 到 PATH,这可能导致路径冲突。建议简化并确保 Conda 的路径只添加一次。
验证 Conda 基础环境 :
确认 Conda 的基础环境是否正常工作:
bash Copy code
conda activate base
conda info --envs
总结 您的错误主要是由于 source activate 命令不再适用于当前的 Conda 版本和 Shell 配置所致。通过使用 conda activate <env> 并确保 Conda 针对您使用的 Shell(如 Zsh)正确初始化,可以解决此问题。请按上述步骤操作,并根据您的具体环境名称进行调整。
如果问题依然存在,请提供更多的上下文信息,如 Conda 版本、Shell 配置文件内容等,以便进一步诊断。
Copy first response
Not yet included in a published release.
h
ttp
s
:
// h f −
mi r r or . co m e x p or tT M P D I R =
/ h o m e / f l / t m p e x p or t A N A C O N D A H O M E =
/ h o m e / f l /. co n d a / e n v s / d a t a p r e p e x p or tP Y T H O N I N C LU D E =
/ h o m e / f l /. co n d a / e n v s / d a t a p r e p / in c l u d e / p y t h o n 3.10 e x p or tP Y T H O N I N C LU D E =
/ h o m e / f l /. co n d a / e n v s / d a t a p r e p / l ib / p y t h o n 3.10/ s i t e −
p a c k a g es / n u m p y / cor e / in c l u d e :
O
N
P
A
T
H
=
/ d a t a / f l / h e d / c a f f e / d i s t r ib u t e / p y t h o n / :
O
N
P
A
T
H
=
/ d a t a / f l / h e d / c a f f e / d i s t r ib u t e / p y t h o n / :
e
n
d
er
/
b
l
e
n
d
er
−
3.3.0 −
l in ux −
x 64 :