Sanity checks
如果您在运行Streamlit应用程序时遇到问题,这里有一些可以尝试的方法。
Check #0: Are you using a Streamlit-supported version of Python?
Streamlit 将尽可能保持与早期 Python 版本的向后兼容性,确保至少与 Python 3 的最后三个次要版本兼容。
随着Python新版本的发布,我们将尽快尝试与新版本兼容,尽管我们经常依赖于其他Python包来支持这些新版本。
Streamlit 目前支持 Python 的 3.9、3.10、3.11、3.12 和 3.13 版本。
Check #1: Is Streamlit running?
在Mac或Linux机器上,在终端中输入以下内容:
ps -Al | grep streamlit
如果你在输出中没有看到streamlit run
(或者streamlit hello
,如果你运行的是这个命令),那么Streamlit服务器没有运行。所以重新运行你的命令,看看问题是否消失。
Check #2: Is this an already-fixed Streamlit bug?
我们尝试快速修复错误,因此很多时候当你升级Streamlit时,问题就会消失。所以遇到问题时,首先要尝试的是升级到最新版本的Streamlit:
pip install --upgrade streamlit
streamlit version
...然后验证打印的版本号是否与PyPI上显示的版本号一致。
现在尝试重现问题。 如果问题未解决,请继续阅读。
Check #3: Are you running the correct Streamlit binary?
让我们检查一下您的Python环境是否设置正确。编辑您遇到问题的Streamlit脚本,注释掉所有内容,并添加以下行:
import streamlit as st
st.write(st.__version__)
...然后在你的脚本上调用streamlit run
,并确保它显示的版本与上述相同。如果版本不同,请查看这些说明以获取一些确保设置环境的方法。
Check #4: Is your browser caching your app too aggressively?
有两种简单的方法可以检查这一点:
-
在浏览器中加载您的应用程序,然后按
Ctrl-Shift-R
或⌘-Shift-R
进行硬刷新(Chrome/Firefox)。 -
作为测试,在另一个端口上运行Streamlit。这样浏览器会使用全新的缓存启动页面。为此,在命令行中向Streamlit传递
--server.port
参数:streamlit run my_app.py --server.port=9876
Check #5: Is this a Streamlit regression?
如果您已经升级到最新版本的Streamlit,但功能无法正常工作,您可以随时使用以下命令降级:
pip install --upgrade streamlit==1.0.0
...其中 1.0.0
是您想要降级到的版本。请参阅
发布说明 以获取 Streamlit 版本的完整列表。
Check #6 [Windows]: Is Python added to your PATH?
当通过从python.org下载安装时,Python不会自动添加到Windows系统PATH中。因此,您可能会收到如下错误信息:
命令提示符:
C:\Users\streamlit> streamlit hello
'streamlit' is not recognized as an internal or external command,
operable program or batch file.
PowerShell:
PS C:\Users\streamlit> streamlit hello
streamlit : The term 'streamlit' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At line:1 char:1
+ streamlit hello
+ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (streamlit:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
要解决此问题,请将Python添加到Windows系统PATH。
将Python添加到您的Windows PATH后,您应该能够按照我们Get Started部分中的说明进行操作。
Check #7 [Windows]: Do you need Build Tools for Visual Studio installed?
Streamlit 包含 pyarrow 作为安装依赖项。有时,当尝试从 PyPI 安装 Streamlit 时,您可能会看到如下错误:
Using cached pyarrow-1.0.1.tar.gz (1.3 MB)
Installing build dependencies ... error
ERROR: Command errored out with exit status 1:
command: 'c:\users\streamlit\appdata\local\programs\python\python38-32\python.exe' 'c:\users\streamlit\appdata\local\programs\python\python38-32\lib\site-packages\pip' install --ignore-installed --no-user --prefix 'C:\Users\streamlit\AppData\Local\Temp\pip-build-env-s7owjrle\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'cython >= 0.29' 'numpy==1.14.5; python_version<'"'"'3.9'"'"'' 'numpy==1.16.0; python_version>='"'"'3.9'"'"'' setuptools setuptools_scm wheel
cwd: None
Complete output (319 lines):
Running setup.py install for numpy: finished with status 'error'
ERROR: Command errored out with exit status 1:
# <truncated for brevity> #
building library "npymath" sources
No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\streamlit\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\streamlit\\AppData\\Local\\Temp\\pip-install-0jwfwx_u\\numpy\\setup.py'"'"'; __file__='"'"'C:\\Users\\streamlit\\AppData\\Local\\Temp\\pip-install-0jwfwx_u\\numpy\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\streamlit\AppData\Local\Temp\pip-record-eys4l2gc\install-record.txt' --single-version-externally-managed --prefix 'C:\Users\streamlit\AppData\Local\Temp\pip-build-env-s7owjrle\overlay' --compile --install-headers 'C:\Users\streamlit\AppData\Local\Temp\pip-build-env-s7owjrle\overlay\Include\numpy' Check the logs for full command output.
----------------------------------------
此错误表明Python在安装过程中尝试编译某些库,但在您的系统上找不到合适的编译器,
如代码行error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio"
所示。
安装Build Tools for Visual Studio应该可以解决这个问题。
还有问题吗?
我们的 论坛 充满了有用的信息和Streamlit专家。