python3.8中关于sklearn问题(win10)
作者:哇哈哈与哇哈哈
python3.8中sklearn问题(win10)及pip 安装sklearn
小编在第一次装sklearn库时,发生了
import error cannot import name ‘__check_build’ from partially initialized module 'sklear的报错
在网上也找了很多答案,发现都不是很适合自己。
反而越搞越麻烦,下面小编来介绍一下本小编的解决办法。(小编的操作环境是win10,python3.8)
解决办法
1、在cmd中一个一个删除python中的numpy、scipy、matplotlib、sklearn、scikit-learn库。
操作办法如下。
pip uninstall numpy pip uninstall scipy pip uninstall matplotlib pip uninstall sklearn pip uninstall scikit-learn
在cmd中操作(有Anaconda3的就在Anaconda Prompt中进行),要一个一个来,不要急。
2、然后再重新装numpy、scipy、matplotlib、sklearn、scikit-learn库。
安装顺序最好和小编一样。
一般不用当心版本问题,因为3.8是目前最新的,他回给你自动装适合你版本的。
不用你去https://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn
中去找sklearn等等库,并且那里下载速度如龟爬,如果你有VPN的话结果可能就不一样。
pip install --index-url https://mirrors.aliyun.com/pypi/simple/ numpy pip install --index-url https://mirrors.aliyun.com/pypi/simple/ scipy pip install --index-url https://mirrors.aliyun.com/pypi/simple/ matplotlib pip install --index-url https://mirrors.aliyun.com/pypi/simple/ sklearn
如果直接用pip install numpy 的办法,很容易出现time out的时间超时报错并且速度又慢,我这里是用阿里云的镜像,速度刚刚的。
3、就这样就ok了,你可以重启一下编辑器试试看。
一个sklearn和tensorflow的bug
bug如下
“/usr/local/lib/python3.8/site-packages/sklearn/__check_build/init.py”, line 44, in
from ._check_build import check_build # noqa
ImportError: dlopen: cannot load any more object with static TLSDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “CNN-meme-motifs.py”, line 5, in
import lib.graphprot_dataloader
File “/home/RNAonGraph/lib/graphprot_dataloader.py”, line 7, in
from sklearn.model_selection import KFold
File “/usr/local/lib/python3.8/site-packages/sklearn/init.py”, line 81, in
from . import __check_build # noqa: F401
File “/usr/local/lib/python3.8/site-packages/sklearn/__check_build/init.py”, line 46, in
raise_build_error(e)
File “/usr/local/lib/python3.8/site-packages/sklearn/__check_build/init.py”, line 31, in raise_build_error
raise ImportError("""%s
ImportError: dlopen: cannot load any more object with static TLSContents of /usr/local/lib/python3.8/site-packages/sklearn/_check_build:
check_build.cpython-38-x86_64-linux-gnu.so__pycache init.py
setup.pyIt 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.
源代码
import os os.environ[‘TF_CPP_MIN_LOG_LEVEL'] = ‘3' import numpy as np import tensorflow as tf import lib.graphprot_dataloader from Model.Joint_MRT import JMRT from lib.general_utils import Pool import multiprocessing as mp import matplotlib.pyplot as plt import subprocess
bug原因及修复
原因暂时难以解释,解决办法是调整tensorflow和sklearn的import顺序
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。