我正在开发一个 Flask API 项目,您可以访问该 APIhere https://mdb.in.tu-clausthal.de/assessment-models/apidocs/。我在 Debian 11 VM 上部署了该项目,该虚拟机全局运行 python 3.9,但我制作了 3.7 venv,并且由于代码中的依赖关系,我的项目在该环境中运行。
部署后,正如您所看到的,API 运行时没有任何问题,并且 apache 中也没有错误,但是当我尝试使用应用程序的任何功能时,它无法正常工作,并且 apache 错误日志中的错误向我显示:构建 scikit-learn 时出现问题。
4] ERROR:app:Exception on /login [POST]
[wsgi:error] Traceback (most recent call last):
[Wed Mar 22 09:19:15.300434 2023] [wsgi:error] File "/home/admin/decision-support-system/env3.7/lib/python3.7/site-packages/sklearn/__check_build/__init__.py", li>
[Wed Mar 22 09:19:15.300437 2023] [wsgi:error] from ._check_build import check_build # noqa
[Wed Mar 22 09:19:15.300440 2023] [wsgi:error] ModuleNotFoundError: No module named 'sklearn.__check_build._check_build'
[Wed Mar 22 09:19:15.300442 2023] [wsgi:error]
[Wed Mar 22 09:19:15.300444 2023] [wsgi:error] During handling of the above exception, another exception occurred:
[Wed Mar 22 09:19:15.300446 2023] [wsgi:error] Traceback (most recent call last):
[Wed Mar 22 09:19:15.300450 2023] [wsgi:error] File "/home/admin/decision-support-system/env3.7/lib/python3.7/site-packages/flask/app.py", line 2528, in wsgi_app
[Wed Mar 22 09:19:15.300452 2023] [wsgi:error] response = self.full_dispatch_request()
[Wed Mar 22 09:19:15.300454 2023] [wsgi:error] File "/home/admin/decision-support-system/env3.7/lib/python3.7/site-packages/flask/app.py", line 1825, in full_disp>
[Wed Mar 22 09:19:15.300457 2023] [wsgi:error] rv = self.handle_user_exception(e)
[Wed Mar 22 09:19:15.300459 2023] [wsgi:error] File "/home/admin/decision-support-system/env3.7/lib/python3.7/site-packages/flask/app.py", line 1823, in full_disp>
[Wed Mar 22 09:19:15.300461 2023] [wsgi:error] rv = self.dispatch_request()
[Wed Mar 22 09:19:15.300463 2023] [wsgi:error] File "/home/admin/decision-support-system/env3.7/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_>
[Wed Mar 22 09:19:15.300465 2023] [wsgi:error] return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
[Wed Mar 22 09:19:15.300467 2023] [wsgi:error] File "/home/admin/decision-support-system/app/api.py", line 546, in loginValidation
[Wed Mar 22 09:19:15.300469 2023] [wsgi:error] from app.structure import machine_learning as starter
[Wed Mar 22 09:19:15.300471 2023] [wsgi:error] File "/home/admin/decision-support-system/app/structure/machine_learning.py", line 8, in <module>
[Wed Mar 22 09:19:15.300473 2023] [wsgi:error] from sklearn.compose import ColumnTransformer
[Wed Mar 22 09:19:15.300476 2023] [wsgi:error] File "/home/admin/decision-support-system/env3.7/lib/python3.7/site-packages/sklearn/__init__.py", line 81, in <mod>
[Wed Mar 22 09:19:15.300478 2023] [wsgi:error] from . import __check_build # noqa: F401
[Wed Mar 22 09:19:15.300480 2023] [wsgi:error] File "/home/admin/decision-support-system/env3.7/lib/python3.7/site-packages/sklearn/__check_build/__init__.py", li>
[Wed Mar 22 09:19:15.300494 2023] [wsgi:error] raise_build_error(e)
[Wed Mar 22 09:19:15.300496 2023] [wsgi:error] File "/home/admin/decision-support-system/env3.7/lib/python3.7/site-packages/sklearn/__check_build/__init__.py", li>
[Wed Mar 22 09:19:15.300498 2023] [wsgi:error] raise ImportError(
[Wed Mar 22 09:19:15.300500 2023] [wsgi:error] ImportError: No module named 'sklearn.__check_build._check_build'
[Wed Mar 22 09:19:15.300502 2023] [wsgi:error] ___________________________________________________________________________
[Wed Mar 22 09:19:15.300504 2023] [wsgi:error] Contents of /home/admin/decision-support-system/env3.7/lib/python3.7/site-packages/sklearn/__check_build:
[Wed Mar 22 09:19:15.300507 2023] [wsgi:error] __pycache__ __init__.py setup.py
[Wed Mar 22 09:19:15.300509 2023] [wsgi:error] _check_build.cpython-37m-x86_64-linux-gnu.so
[Wed Mar 22 09:19:15.300511 2023] [wsgi:error] ___________________________________________________________________________
[Wed Mar 22 09:19:15.300513 2023] [wsgi:error] It seems that scikit-learn has not been built correctly.
[Wed Mar 22 09:19:15.300515 2023] [wsgi:error]
[Wed Mar 22 09:19:15.300516 2023] [wsgi:error] If you have installed scikit-learn from source, please do not forget
[Wed Mar 22 09:19:15.300518 2023] [wsgi:error] to build the package before using it: run `python setup.py install` or
[Wed Mar 22 09:19:15.300520 2023] [wsgi:error]`make` in the source directory.
[Wed Mar 22 09:19:15.300522 2023] [wsgi:error]
[Wed Mar 22 09:19:15.300524 2023] [wsgi:error]If you have used an installer, please check that it is suited for your
[Wed Mar 22 09:19:15.300526 2023] [wsgi:error] Python version, your operating system and your platform.
所以我尝试了所有卸载并使用 pip 重新安装或从 github 等源构建它。它永远不起作用!
我通过ssh连接在VM的终端中激活环境并尝试导入sklearn,并询问版本,这就是结果。
sklearn.show_versions()
/home/admin/decision-support-system/env3.7/lib/python3.7/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
System:
python: 3.7.7 (default, Mar 16 2023, 01:45:54) [GCC 10.2.1 20210110]
executable: /home/admin/decision-support-system/env3.7/bin/python
machine: Linux-5.10.0-21-amd64-x86_64-with-debian-11.6
Python dependencies:
pip: 23.0.1
setuptools: 67.6.0
sklearn: 1.0.2
numpy: 1.18.5
scipy: 1.7.3
Cython: None
pandas: 1.3.4
matplotlib: 3.3.2
joblib: 1.2.0
threadpoolctl: 3.1.0
Built with OpenMP: True
看来 VENV 一切都好。我还导入了下面的点列表结果:
我看到另一个帖子here https://stackoverflow.com/questions/56510280/pip-install-scikit-learn-fails-in-virtualenv-on-debian-raspberry-pi-failed-t,但我的问题是 sklearn 正在 VENV 上工作!
pip list
Package Version
---------------------- ---------
absl-py 1.4.0
aniso8601 8.0.0
appdirs 1.4.3
astor 0.8.1
astunparse 1.6.3
async-timeout 4.0.2
attrs 19.3.0
cachetools 4.2.4
certifi 2022.12.7
cffi 1.14.0
chardet 3.0.4
charset-normalizer 3.1.0
click 8.1.3
colorama 0.4.3
cryptography 2.9.2
cycler 0.10.0
distlib 0.3.0
filelock 3.0.12
fire 0.3.1
flasgger 0.9.4
Flask 2.2.3
Flask-Cors 3.0.10
flask-restplus 0.13.0
Flask-SQLAlchemy 3.0.2
flask-swagger-ui 3.25.0
gast 0.3.3
google-auth 1.35.0
google-auth-oauthlib 0.4.6
google-pasta 0.2.0
greenlet 2.0.2
grpcio 1.51.3
h5py 2.10.0
idna 3.4
importlib-metadata 6.0.0
importlib-resources 5.12.0
itsdangerous 2.1.2
Jinja2 3.0.3
joblib 1.2.0
jsonschema 3.2.0
Keras 2.4.0
Keras-Applications 1.0.8
Keras-Preprocessing 1.1.2
kiwisolver 1.2.0
Markdown 3.4.1
MarkupSafe 2.1.2
marshmallow 3.5.1
matplotlib 3.3.2
mistune 0.8.4
mohawk 1.1.0
numpy 1.18.5
oauthlib 3.2.2
opt-einsum 3.3.0
pandas 1.3.4
pathspec 0.8.0
Pillow 8.0.1
pip 23.0.1
pipdate 0.3.1
pkgutil_resolve_name 1.3.10
protobuf 4.22.1
pyasn1 0.4.8
pyasn1-modules 0.2.8
pycparser 2.20
PyJWT 1.7.1
pymongo 3.10.1
pyOpenSSL 19.1.0
pyparsing 2.4.7
pyrsistent 0.16.0
python-dateutil 2.8.1
pytz 2019.3
PyYAML 5.3.1
redis 4.5.1
repoze.lru 0.7
requests 2.28.2
requests-hawk 1.1.1
requests-oauthlib 1.3.1
Routes 2.4.1
rsa 4.9
scikit-learn 1.0.2
scipy 1.7.3
setuptools 67.6.0
six 1.16.0
SQLAlchemy 2.0.6
structure 0.1.dev16
tensorboard 2.2.2
tensorboard-plugin-wit 1.8.1
tensorflow 2.2.2
tensorflow-estimator 2.2.0
termcolor 2.2.0
Theano 1.0.4
threadpoolctl 3.1.0
tinynetrc 1.3.0
typing_extensions 4.5.0
urllib3 1.26.15
uWSGI 2.0.18
Werkzeug 2.2.3
wheel 0.40.0
wrapt 1.15.0
zipp 3.15.0
当我尝试从源构建库时,还有一些值得一提的事情,它有一些错误,其中提到了 numpy,但正如您所看到的,pip 安装工作正常,导入 sklearn 也工作正常!
是否知道这里的解决方案是什么?