Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
内核在Python中导入库时冻结_Python_Anaconda_Graphviz_Pydotplus - Fatal编程技术网

内核在Python中导入库时冻结

内核在Python中导入库时冻结,python,anaconda,graphviz,pydotplus,Python,Anaconda,Graphviz,Pydotplus,我使用Anaconda、Jupyter笔记本,并安装了最新版本的Python 3.9.4 在安装Python和Anaconda(anaconda3)之后,我通过以下命令安装了一些库pip install-scikit-learn-graphviz,但是如果已经满足了要求,就没有必要了 这就是导致我出现问题的问题代码: 在[1]中: # standard libraries import pandas as pd import numpy as np import statistics impor

我使用Anaconda、Jupyter笔记本,并安装了最新版本的Python 3.9.4

在安装Python和Anaconda(anaconda3)之后,我通过以下命令安装了一些库
pip install-scikit-learn-graphviz
,但是如果已经满足了
要求,就没有必要了

这就是导致我出现问题的问题代码:

在[1]中:

# standard libraries
import pandas as pd
import numpy as np
import statistics
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import pydotplus #<---------------------------------------------ModuleNotFoundError: No module named 'pydotplus'
from sklearn.preprocessing import MinMaxScaler
from math import log
from six import StringIO 
from graphviz import Source #<----------------------------------ModuleNotFoundError: No module named 'graphviz'
import graphviz as gr #<----------------------------------------ModuleNotFoundError: No module named 'graphviz'
#from IPython.display import SVG
#from IPython.display import display
#from IPython.core.display import SVG
from IPython.display import Image

%matplotlib inline
#%pylab inline
from sklearn.feature_selection import mutual_info_classif

# pca libraries
from sklearn import decomposition
from sklearn.feature_selection import VarianceThreshold
from sklearn.preprocessing import scale
from sklearn.decomposition import PCA
#import seaborn as sb

# kfold stratification libraries
from sklearn.model_selection import StratifiedKFold

# libraries for building classifiers
from sklearn.ensemble import RandomForestClassifier        
from sklearn import tree
from sklearn.model_selection import train_test_split
  

# libraries for evaluation metrics
from sklearn.metrics import f1_score
from sklearn.metrics import accuracy_score 
from sklearn.metrics import balanced_accuracy_score
from sklearn.metrics import recall_score
from sklearn.metrics import precision_score

from sklearn.model_selection import cross_val_score
from sklearn.model_selection import cross_validate
from sklearn.metrics import confusion_matrix 

from sklearn.metrics import classification_report 

from datetime import datetime
from os import system
#from simple_colors import *

import bisect
import time 
import sys

# import warnings filter
from warnings import simplefilter
# ignore all future warnings
simplefilter(action='ignore', category=FutureWarning)

# elimination of the conversion warning
import warnings
from sklearn.exceptions import DataConversionWarning
simplefilter(action='ignore', category=DataConversionWarning)
warnings.filterwarnings('error')
起初,出于某种荒谬的原因,在代码的第一部分,在箭头的对应关系中,我得到了这些错误:

ModuleNotFoundError: No module named 'pydotplus'
尽管已经安装了必要的库。为了进一步验证,我从终端运行了以下命令:

pip install graphviz
正如我已经预料到的,我已经满足了
要求

尽管如此,我仍然试图在错误处对代码进行注释,但是当我尝试执行第一部分(以及后来的第二部分)时,我的内核冻结,在[*]中显示

如何解决这种情况

更新


如果它能帮助人们找到解决方案并解决问题,我意识到内核只有在运行导入后才会冻结,这只是第一块代码。但是,这个问题仍然没有解决,因为我需要导入这些库以使代码正常工作(并且不要让内核冻结)。

这可能是由于您的默认pip安装与jupyter使用的不同。以下脚本应在jupyter中运行,并将生成和执行一个命令,该命令可用于安装具有正确版本的pip的软件包

import sys
import os

executable_path = sys.executable
print(executable_path)
command = f'"{executable_path}" -m pip install pandas scikit-learn graphviz pydotplus'
print(command)
# Uncomment the following line if you prefer to run the command yourself
# exit()
exit_code = os.system(command)
if exit_code == 0:
    print("success!")
else:
    print("failure!")

首先从此站点安装Graphviz:

将Graphviz添加到环境变量“Path”:

  • 转到
    Computer>Properties>Advanced system settings>Environment Variables
    ,然后在系统变量框中找到“Path”。单击路径并单击编辑
  • 追加
    ;C:\Program Files(x86)\Graphviz2.38\bin
    到路径中已存在的许多路径的末尾。注意,Graphviz的路径可能与您的不同,因此请确保放置正确的路径。文件夹“bin”应包含许多文件,包括dot.exe应用程序
  • 要检查安装,请转到命令提示符并输入:
    dot-V
    这将返回安装的Graphviz版本。例如,
    dot-graphviz版本2.38.0
    。如果这不起作用,请输入set并查找Graphviz路径
在此之后,打开Anaconda提示符并使用命令重新安装Graphviz
pip install——强制重新安装Graphviz
可能的解决方案:

  • 到目前为止,Anaconda似乎只支持python3.8: ,因此我怀疑您首先安装的python3.9与您安装的最新anaconda和python存在某种冲突,并且有些内容已损坏。 Soln:我建议您卸载anaconda,从
    C:\Users\your\u user\u name\Anaconda3
    路径中删除Anaconda3文件夹,现在也完全卸载python3.9,也从环境变量中删除它们2>现在,只需从上述url下载最新的anaconda,当它在安装过程中询问您是否要将python3.8添加到您的路径时,请选中复选框3>接下来在anaconda3命令提示符下从conda安装所需的软件包
  • 我已经检查过了,看起来graphviz的pip版本有问题。请检查这里的答案:他们似乎找到了另一个名为
    python-graphviz
    的包

  • 希望这些有助于解决您的问题。

    可能又是一个路径问题,我认为python找不到点会有很多关于这类问题的问题。我读过关于路径问题的文章,但在安装此版本时,它没有要求我禁用路径长度限制。我也试着下载旧版本,但是这个功能已经被删除了。可能是说一些不同的东西,我说的是系统路径。您重新启动了终端吗?当然,但没有任何变化。考虑到您已经安装了Anaconda,我建议您使用
    conda
    安装软件包,以避免许多安装和依赖性问题。
    pip install graphviz
    
    pip install pydotplus
    
    import sys
    import os
    
    executable_path = sys.executable
    print(executable_path)
    command = f'"{executable_path}" -m pip install pandas scikit-learn graphviz pydotplus'
    print(command)
    # Uncomment the following line if you prefer to run the command yourself
    # exit()
    exit_code = os.system(command)
    if exit_code == 0:
        print("success!")
    else:
        print("failure!")