You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
841 B
44 lines
841 B
5 months ago
|
#!/bin/bash
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#!/bin/bash
|
||
|
|
||
|
# 创建一个目录用于存放虚拟环境
|
||
|
env_dir="myenv"
|
||
|
|
||
|
# 检查是否已经存在虚拟环境目录
|
||
|
if [ -d "$env_dir" ]; then
|
||
|
echo "虚拟环境目录 $env_dir 已存在,跳过创建步骤。"
|
||
|
else
|
||
|
# 创建虚拟环境
|
||
|
python3 -m venv $env_dir
|
||
|
echo "虚拟环境已创建在 $env_dir"
|
||
|
fi
|
||
|
|
||
|
# 激活虚拟环境
|
||
|
source $env_dir/bin/activate
|
||
|
|
||
|
# 检查是否成功激活虚拟环境
|
||
|
if [ "$VIRTUAL_ENV" != "" ]; then
|
||
|
echo "虚拟环境已激活"
|
||
|
else
|
||
|
echo "虚拟环境激活失败"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# 安装 paho-mqtt 库
|
||
|
pip install paho-mqtt
|
||
|
|
||
|
# 验证安装
|
||
|
if python -c "import paho.mqtt.client" &> /dev/null; then
|
||
|
echo "paho-mqtt 安装成功"
|
||
|
else
|
||
|
echo "paho-mqtt 安装失败"
|
||
|
fi
|
||
|
|
||
|
# 提示如何退出虚拟环境
|
||
|
echo "要退出虚拟环境,请运行 'deactivate'"
|
||
|
|