首页 > 解决方案 > 如何自动安装和使用 conda 来启动 python 脚本?

问题描述

我有一个使用 streamlit 作为其 gui 的 python 项目。由于我即将从我的实验室毕业,因此我正努力使其尽可能易于使用,并通过自动化设置来确保它在一定程度上适应未来,以防实验室获得新的 PC 或笔记本电脑。什么是 Windows 自动化的最简单方法(作为批处理脚本、msi、exe 等)?它应该:

设置:

  1. 安装 anaconda/miniconda
  2. 从 requirements.txt 文件安装 pip 库

利用:

  1. 通过 miniconda/anaconda env 启动 python
  2. streamlit run myscript.py通过环境运行
  3. 允许脚本访问“输入”和“输出”文件夹以读取/存储文件

我尝试了什么:

windows.bat 批处理脚本。这非常适合启动脚本,但仍需要用户找到 conda 位置并编辑批处理文件。我想尽量减少这种情况,因为我们实验室中的一些人在技术上面临很大挑战(我不得不训练多个从资源管理器地址复制粘贴位置的人)。

@ECHO OFF

:: EDIT ME ::
:: Edit the below line to point to the anaconda directory as demonstrated below ::
CALL C:\Users\albei\anaconda3\Scripts\activate.bat C:\Users\albei\anaconda3

pip install -r requirements.txt
echo ''
echo "-------------------------------------"
echo "Starting the dynamic bike script"
echo ''
echo "Keep this window open while the script is running"
echo "-------------------------------------"

:: This line just runs the streamlit script ::
streamlit run new_bike_st.py

:: Keep the terminal open ::
PAUSE

标签: pythonwindowsbatch-file

解决方案


推荐阅读