赞
踩
解决bash: streamlit: command not found,ModuleNotFoundError: No module named ‘_bz2’.
[root@323d4422c260 ChatGLM3]# python38
Python 3.8.3 (default, Feb 1 2024, 02:15:10)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import streamlit
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python3/lib/python3.8/site-packages/streamlit/__init__.py", line 56, in <module>
from streamlit.delta_generator import DeltaGenerator as _DeltaGenerator
File "/usr/local/python3/lib/python3.8/site-packages/streamlit/delta_generator.py", line 37, in <module>
from streamlit import config, cursor, env_util, logger, runtime, type_util, util
File "/usr/local/python3/lib/python3.8/site-packages/streamlit/cursor.py", line 18, in <module>
from streamlit.runtime.scriptrunner import get_script_run_ctx
File "/usr/local/python3/lib/python3.8/site-packages/streamlit/runtime/__init__.py", line 15, in <module>
from streamlit.runtime.runtime import Runtime, RuntimeConfig, RuntimeState
File "/usr/local/python3/lib/python3.8/site-packages/streamlit/runtime/runtime.py", line 30, in <module>
from streamlit.runtime.app_session import AppSession
File "/usr/local/python3/lib/python3.8/site-packages/streamlit/runtime/app_session.py", line 36, in <module>
from streamlit.runtime import caching, legacy_caching
File "/usr/local/python3/lib/python3.8/site-packages/streamlit/runtime/caching/__init__.py", line 21, in <module>
from streamlit.runtime.caching.cache_data_api import (
File "/usr/local/python3/lib/python3.8/site-packages/streamlit/runtime/caching/cache_data_api.py", line 32, in <module>
from streamlit.runtime.caching.cache_errors import CacheError, CacheKeyNotFoundError
File "/usr/local/python3/lib/python3.8/site-packages/streamlit/runtime/caching/cache_errors.py", line 18, in <module>
from streamlit import type_util
File "/usr/local/python3/lib/python3.8/site-packages/streamlit/type_util.py", line 44, in <module>
from pandas import DataFrame, Index, MultiIndex, Series
File "/usr/local/python3/lib/python3.8/site-packages/pandas/__init__.py", line 22, in <module>
from pandas.compat import is_numpy_dev as _is_numpy_dev # pyright: ignore # noqa:F401
File "/usr/local/python3/lib/python3.8/site-packages/pandas/compat/__init__.py", line 24, in <module>
import pandas.compat.compressors
File "/usr/local/python3/lib/python3.8/site-packages/pandas/compat/compressors.py", line 7, in <module>
import bz2
File "/usr/local/python3/lib/python3.8/bz2.py", line 19, in <module>
from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'
>>>
1.确保安装了 对应的库
// ubuntu安装命令
sudo apt-get install bzip2-devel
// centos安装命令
sudo yum install bzip2-devel
2.找到对应的 bzip2 的 .so 文件 _bz2.cpython-36m-x86_64-linux-gnu.so,可以用以下方法找,比如:
在python3.6环境下安装,位置在:/usr/lib/python3.6/lib-dynload/ 下
或者 在python3.6环境下安装,位置在: /usr/lib64/python3.6/lib-dynload/ 下
或者 如果找不到就用命令查找: find / -name _bz2.cpython
3.将该动态库的存入你安装的python的lib-dynload目录下,这个目录,一般是
/usr/lib/python3.6/lib-dynload/
或者
/usr/lib64/python3.6/lib-dynload/
或者自定义的python安装目录下:
./lib/python3.6/lib-dynload/
或
./lib64/python3.6/lib-dynload/
命令如下:
cp /usr/lib64/python3.6/lib-dynload/_bz2.cpython-36m-x86_64-linux-gnu.so /usr/local/python3/lib/python3.8/lib-dynload/_bz2.cpython-38m-x86_64-linux-gnu.so
需要注意的是python版本对应的名称。
之后再把python 重新编译一下,软连接可以不用重新弄。
或者把python卸载了重新安装一下。
[root@323d4422c260 ChatGLM3]# python38
Python 3.8.3 (default, Feb 1 2024, 10:01:16)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import streamlit
>>> streamlit.__file__
'/usr/local/python3/lib/python3.8/site-packages/streamlit/__init__.py'
>>>
完全正常了。
[root@323d4422c260 Python-3.8.3]# python38 -m streamlit hello
Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.
Welcome to Streamlit. Check out our demo in your browser.
Network URL: http://172.17.0.2:8501
External URL: http://103.114.158.1:8501
Ready to create your own Python apps super quickly?
Head over to https://docs.streamlit.io
May you create awesome apps!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。