自己做了个 python 应用,因为依赖相对复杂,所以使用 WSL(-ubuntu)的方式部署。
在配置服务随 Windows 系统自动化启动的时候遇到问题。
因为需要切换环境,所以在使用以下语句,执行启动脚本时:
wsl -d ubuntu-18.04 -u chen "/etc/init.d/start-script"
最直接的想法,使用 start-script 脚本内容如下:
#! /bin/bashconda activate env_namecd /mnt/e/path/to/scriptpython test.py
但是,在使用 conda activate 命令切换环境,会因为 conda 环境没有初始化的问题,无法进入相应环境。
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are: - bash - fish - tcsh - xonsh - zsh - powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
这时候使用下面语句切换环境即可:
source /home/user_name/miniconda3/bin/activate env_name# 或者source /home/user_name/anaconda3/bin/activate env_name
修改后的启动脚本为:
#! /bin/bashsource /home/user_name/miniconda3/bin/activate env_namecd /mnt/e/path/to/scriptpython test.py
参考