文章目录
前言
在NVIDIA JETSON AGX XAVIER上使用Pycharm运行python程序
最开始(失败)python版本:python3.8 安装的sklearn库版本:scikit-learn1.3.2
最后(成功)python版本:python3.9,sklearn:scikit-learn1.4.1.post1**
一、运行python程序报错:
'sklearn.__check_build._check_build’问题
如下图所示
完整报错如下
Traceback (most recent call last):
File "/xx/python3.8/site-packages/sklearn/__check_build/__init__.py", line 48, in <module>
from ._check_build import check_build # noqa
ImportError: /xx/python3.8/site-packages/sklearn/__check_build/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0: cannot allocate memory in static TLS block
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/xx/lstm_train_2.py", line 20, in <module>
from sklearn import preprocessing
File "/xx/python3.8/site-packages/sklearn/__init__.py", line 81, in <module>
from . import __check_build # noqa: F401
File "/xx/python3.8/site-packages/sklearn/__check_build/__init__.py", line 50, in <module>
raise_build_error(e)
File "/xx/python3.8/site-packages/sklearn/__check_build/__init__.py", line 31, in raise_build_error
raise ImportError(
ImportError: /xx/python3.8/site-packages/sklearn/__check_build/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0: cannot allocate memory in static TLS block
___________________________________________________________________________
Contents of /xx/python3.8/site-packages/sklearn/__check_build:
setup.py __init__.py _check_build.cpython-38-aarch64-linux-gnu.so
__pycache__
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform
分析问题:sklearn库安装问题,需重新正确安装sklearn库
1.使用conda安装sklearn
首先卸载sklearn:
使用pip或者conda卸载sklearn
pip uninstall sklearn
或
conda uninstall sklearn
然后使用conda安装sklearn
conda install sklearn
这种方法安装好sklearn后可能会出现TLS静态存储问题(我就是这样)
详情见本博客(# 二、运行程序报错: /xxx/libgomp.so.1: cannot allocate memory in static TLS block)
2.pip卸载与sklearn相关的包并重装
步骤如下:
首先要卸载numpy,scipy,matplotlib,scikit-learn
分别在终端运行以下命令
pip uninstall numpy
pip uninstall scipy
pip uninstall matplotlib
pip uninstall scikit-learn
卸载完后重新安装
pip install numpy
pip install scipy
pip install matplotlib
pip install -U scikit-learn -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
安装过程中可能会有报错,可以忽略,安装后成功解决No module named 'sklearn.__check_build._check_build’问题。
二、运行程序报错: /xxx/libgomp.so.1: cannot allocate memory in static TLS block
'TLS’静态存储问题
如下图所示
完整报错如下:
Traceback (most recent call last):
File "/xx/lstm_train_2.py", line 20, in <module>
from sklearn import preprocessing
File "/xx/python3.8/site-packages/sklearn/__init__.py", line 84, in <module>
from .utils._show_versions import show_versions
File "/xx/python3.8/site-packages/sklearn/utils/_show_versions.py", line 13, in <module>
from ._openmp_helpers import _openmp_parallelism_enabled
ImportError: /xx/lib/libgomp.so.1: cannot allocate memory in static TLS block
分析问题:sklearn库安装问题,需重新正确安装sklearn库
解决方法
1.尝试安装最新版本sklearn
python版本不同,所能够安装的sklearn版本也不同
`python3.8中scikit-learn的最高版本为1.3.2 `
`python3.9中scikit-learn的最高版本为1.4.1.post1 `
输入以下命令安装
pip install sklearn
已经安装好可以输入以下命令更新sklearn版本:
pip install -U sklearn
2.尝试本博客中的方法 (一、2.pip卸载与sklearn相关的包并重装)
一步一步卸载numpy,scipy,matplotlib,scikit-learn,卸载完后重新安装
3.python版本问题
因为python版本不同,所能够安装的sklearn的最新版本也不同,所以我选择使用python3.9(原来是python3.8)进行安装解决了问题。详情请见 本博客(# 三、我遇到的问题和解决过程。)
三、我遇到的问题和解决过程
本节将记录我在使用sklearn库过程中遇到的问题,目前使用的是python3.8,scikit-learn1.3.2
1.'sklearn.__check_build._check_build’问题
因为程序需要使用sklearn库,直接输入命令安装
pip install sklearn
安装完成后运行程序报错:'sklearn.__check_build._check_build’问题
如下图所示
然后我一个朋友说是pip原因,需要用conda环境下载sklearn,他是用conda下载的
将他的NVIDIA JETSON AGX Orin上下载好的sklearn和scikit-learn包复制到Xavier上后报错:'TLS’静态存储问题
如下图所示
他也遇到相同的问题,我们两个都是python3.8,考虑可能是python版本问题
尝试在个人笔记本(win11)上跑相同的程序,win11上python版本:python3.9,scikit-learn版本1.4.1.post1
能够成功跑通,尝试将win11上这些sklearn相关包复制到Xavier板子上,测试报错如下
from ctypes import WinDLL
ImportError: cannot import name 'WinDLL' from 'ctypes' (/xx/python3.8/ctypes/__init__.py)”
这里找不到原图了,简单说明一下,就是windows下的包与linux下的包不兼容
反复安装sklearn并尝试各种方法无果后,选择使用python3.9版本重新下载所有包
一步一步安装numpy,scipy,matplotlib,scikit-learn
pip install numpy
pip install scipy
pip install matplotlib
pip install -U scikit-learn -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
成功解决了之前所有的报错问题。目前python版本:python3.9,sklearn:scikit-learn1.4.1.post1
总结
功夫不负有心人,大家在使用sklearn遇到问题都可以尝试更新版本来解决问题,scikit-learn更新到最新版,如果还不能解决问题,则尝试更新python版本。