Running Conda Command-Line Scripts on Windows
I needed to remotely update website content from my Windows machine at home, and while I have Conda installed on Windows, I found I couldn’t directly write and run scripts. I could only launch Conda from the Start menu and type commands line by line.
After some searching and learning, I finally found a solution.
The reason you can’t directly write and run .bat batch files for Conda commands (which use various Python libraries from Conda) is that the default cmd.exe doesn’t activate the Conda environment. Once you add the environment activation command, your scripts will run. You can refer to the original English explanation here: https://stackoverflow.com/questions/46305569/how-to-make-batch-files-run-in-anaconda-prompt.
The final batch-file structure can look like this:
call "G:\conda\Scripts\activate.bat"
call conda activate base
scrapy crawl dou
python tupian.py
python post.py
If you want to run the script inside a specific environment instead of base, just replace the environment name:
call conda activate myenv
If the batch file still says that conda or python cannot be found, check these first:
- Whether the
activate.batpath matches your real Anaconda or Miniconda installation path - Whether the batch file is being run in a normal
cmdcontext rather than through another tool that rewrites environment variables
- 原文作者:春江暮客
- 原文链接:https://www.bobobk.com/en/297.html
- 版权声明:本作品采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。