python运用Anaconda3设置开机启动项目
1、安装Anaconda3-5.2.0-Windows-x86_64.exe
2、利用Anaconda创建运行环境py38 使用命令,具体操作自行百度
conda create -n py38 python=3.8
3、在Anaconda3-5.2.0-Windows-x86_64.exe的安装目录下C:\ProgramData\Anaconda3\Scripts复制activate.bat文件,并重命名为activate2.bat,用记本事打开activate2.bat在最后面新增以下几行代码:
cd D:\coding\learning\python\yolov5-5.0 timeout /t 2 conda activate py38 & python dectectCamera.py timeout /t 2
其中D:\coding\learning\python\yolov5-5.0是你的项目代码路径,py38是项目运行环境,dectectCamera.py是要启动文件
完整的activate2.bat代码如下:
1 @REM Test first character and last character of %1 to see if first character is a " 2 @REM but the last character isn't. 3 @REM This was a bug as described in https://github.com/ContinuumIO/menuinst/issues/60 4 @REM When Anaconda Prompt has the form 5 @REM %windir%\system32\cmd.exe "/K" "C:\Users\builder\Miniconda3\Scripts\activate.bat" "C:\Users\builder\Miniconda3" 6 @REM Rather than the correct 7 @REM %windir%\system32\cmd.exe /K ""C:\Users\builder\Miniconda3\Scripts\activate.bat" "C:\Users\builder\Miniconda3"" 8 @REM this solution taken from https://stackoverflow.com/a/31359867 9 @set "_args1=%1" 10 @set _args1_first=%_args1:~0,1% 11 @set _args1_last=%_args1:~-1% 12 @set _args1_first=%_args1_first:"=+% 13 @set _args1_last=%_args1_last:"=+% 14 @set _args1= 15 16 @if "%_args1_first%"=="+" if NOT "%_args1_last%"=="+" ( 17 @CALL "%~dp0..\Library\bin\conda.bat" activate 18 @GOTO :End 19 ) 20 21 @CALL "%~dp0..\Library\bin\conda.bat" activate %* 22 23 :End 24 @set _args1_first= 25 @set _args1_last= 26 27 28 cd D:\coding\learning\python\yolov5-5.0 29 timeout /t 2 30 conda activate py38 & python dectectCamera.py 31 32 timeout /t 2
4、新建start.bat文件,放在系统开机启动项里面。start.bat的代码如下
start cmd /k call C:\ProgramData\Anaconda3\Scripts\activate2.bat C:\ProgramData\Anaconda3