感谢@pmrowla和@Ruslan-kuprieiev的反馈.
首先,我将dvc
版本更新为3.14.0版.然后我发现,在我的 case 中,一个问题实际上是,使用Streamlittapp.py
文件中的一个简单的Shell脚本dvc pull
,无法成功地访问从requirements.txt
文件安装到Streamlitt服务器中的正确的可执行文件dvc
.
在下面,我只是引用我从ChatGPT 4得到的答案,供您参考.报价中的代码解决了我的问题,我的Google Drive中的.csv
数据文件成功加载.
要在Streamlight共享上部署的Streamlight应用程序中运行dvc pull
(或任何其他需要在虚拟环境中安装Python包的命令),您需要执行几个步骤.
Install the Required Packages:
确保在GitHub存储库的requirements.txt
文件中列出了dvc
个.当你在Streamlight共享上部署该应用程序时,它将自动安装requirements.txt
中列出的程序包.
Use Python's 100:
您可以使用Pythonsys.executable
来获取到Python解释器的路径.这将有助于确保您调用的是安装了dvc
的正确的Python环境.
Run the Command from Python:
使用subprocess
从您的Streamlight应用程序中运行dvc pull
命令.
下面是一个例子:
import sys
import subprocess
import streamlit as st
def pull_data_with_dvc():
cmd = [sys.executable, "-m", "dvc", "pull"]
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0:
st.write("Data pulled successfully!")
st.write(result.stdout)
else:
st.write("Error pulling data!")
st.write(result.stderr)
# Use this function somewhere in your Streamlit app.
pull_data_with_dvc()
记住:
- 确保已正确设置DVC遥控器.
- 如果DVC需要身份验证,您将需要提供必要的凭据,这可能会涉及更多,特别是如果您想要保证凭据的安全.
- 此方法假定DVC安装为一个Python模块(而不是独立的系统二进制文件).
最后,请注意Streamlight共享在存储和资源方面存在一些限制.如果您要提取大量数据,则可能会达到这些限制.请务必查看Streamlitt的文档和限制,以了解最新的详细信息.