QQ扫一扫联系
使用git拉完项目,为了和其他项目环境隔离,一般我们会创建一个虚拟环境,创建完成虚拟环境后激活虚拟环境、安装项目的依赖
下面是一个简单的脚本 install.ps1 ,使用Python3.10创建一个名为venv的虚拟环境:
# PowerShell script equivalent to the batch commands # Stop the script on any error $ErrorActionPreference = "Stop" # Navigate to the virtual environment directory and activate it # Assuming the script is run from the directory where 'venv' is located try { conda create --prefix venv python=3.10 conda activate .\venv pip install -r requirements.txt } catch { Write-Error "Failed to activate the virtual environment. Please check if the virtual environment exists or if there are permission issues." exit } # Pause at the end Read-Host -Prompt "Press Enter to continue..."
把这个脚本放到项目的根目录,和 requirements.txt 同级,如果不同级,就要修改路径。
如下面的运行脚本:
# PowerShell script equivalent to the batch commands # Stop the script on any error $ErrorActionPreference = "Stop" # Navigate to the virtual environment directory and activate it # Assuming the script is run from the directory where 'venv' is located try { conda activate .\Langchain-Chatchat\venv } catch { Write-Error "Failed to activate the virtual environment. Please check if the virtual environment exists or if there are permission issues." exit } # Run the Python script try { cd Langchain-Chatchat # python init_database.py --recreate-vs python startup.py -a } catch { Write-Error "An error occurred while running the Python script. Please check the script and try again." exit } # Pause at the end Read-Host -Prompt "Press Enter to continue..."
不同级的有个问题,就是这段代码
cd Langchain-Chatchat # python init_database.py --recreate-vs python startup.py -a
换成
python .\Langchain-Chatchat\startup.py -a
执行会有问题,所以写成上面的。不知道为啥。