简体   繁体   English

激活anaconda并从cmd脚本启动Web服务器

[英]Activate anaconda and start a webserver from cmd script

I would like to activate Anaconda environment and start a Python server from cmd script. 我想激活Anaconda环境并从cmd脚本启动Python服务器。

Currently the script looks like this: 当前脚本如下所示:

cd "C:\Users\usmazuc\AppData\Local\Continuum\Anaconda32\Scripts"
activate my_env
cd "C:\wb"
python web_server.py

Script works for the first part - it activates anaconda environment, but it doesn't execute any command which follows activate my_env . 脚本适用于第一部分-可以激活anaconda环境,但不会执行activate my_env任何命令。

Currently I run this script from cmd console, but in the long run I would like to run it as a Windows startup script. 当前,我从cmd控制台运行此脚本,但从长远来看,我想将其作为Windows启动脚本运行。

The goal is to: 1) activate anaconda env 2) from within this environment, start the Python server 目标是:1)激活anaconda env 2)在此环境中启动Python服务器

The whole process shouldn't be visible for the user. 整个过程对用户不应该可见。 The server should be running in the background but the user should not be able to see it. 服务器应该在后台运行,但是用户应该看不到它。

In a batch script you should use call activate my_env . 在批处理脚本中,应使用call activate my_env See https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/call.mspx?mfr=true . 请参阅https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/call.mspx?mfr=true

You can also just use the full path to the environment when you call Python, like C:\\Users\\usmazuc\\AppData\\Local\\Continuum\\Anaconda32\\envs\\my_env\\python.exe web_server.py . 您也可以在调用Python时使用环境的完整路径,例如C:\\Users\\usmazuc\\AppData\\Local\\Continuum\\Anaconda32\\envs\\my_env\\python.exe web_server.py If you do this, there is no need to use activate . 如果执行此操作,则无需使用activate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM