• python 深度学习 解决遇到的报错问题6


    目录

    一、解决报错'HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/resolve/main/vocab.txt (Caused by ConnectTimeoutError(, 'Connection to huggingface.co

    如何从huggingface官网下载模型

    二、nx.draw if cf._axstack() is None: TypeError: '_AxesStack' object is not callable

    三、pandas读取表格解决遇到的问题

    解决ValueError: Excel file format cannot be determined, you must specify an engine manually.

    查找两个列表中相同的元素

    解决but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details

    解决MatplotlibDeprecationWarning: Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later.


    一、解决报错'HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/resolve/main/vocab.txt (Caused by ConnectTimeoutError(, 'Connection to huggingface.co

    问题

    原因:出现此问题的原因是运行程序的服务器没有网络,却使用了未下载的bert-base-cased模型。若该服务器没有网络,则可将bert-base-cased模型,从huggingface.co官网下载下来。将其放在相应的文件夹即可。

    如何从huggingface官网下载模型

    (1)首先打开huggingface官网Hugging Face – The AI community building the future.,进入官网之后,点击“Models",

    如果想要下载数据集,则同样的操作方法,点击”Datasets“。

    (2)进入”Models“,之后,在搜索框,输入想要download的模型名称。本文示例是:bert-base-cased,

    找到想要下载的模型,点击进入,出现下面的画面,

    点击”Files and versions“,找到自己想要下载的文件即可。

    本文的示例可根据实际需求,下载黄色框框的四个文件。也可把Files and versions文件下的文件都下载。


    (3)将下载的文件,存放倒一个文件夹,建议文件夹命名为:bert-base-cased

     至此,在HUggingface官网下载模型步骤完成。

    二、nx.draw if cf._axstack() is None: TypeError: '_AxesStack' object is not callable

    报错:nx.draw报错 ‘_AxesStack‘ object is not callable

    可能的原因

    这个错误是由于在绘制图形时调用了一个不可调用的对象 _AxesStack,通常这与与变量或函数名冲突有关。检查你的代码是否有其他地方使用了名为 plt 或 ax 的变量或函数,导致了该错误。

    以下是可能导致问题的一些常见原因和解决方法:

    • 确保 plt 是 Matplotlib 的 pyplot 对象,并且没有在其他地方被重新定义。在使用 plt 之前,可以尝试在代码的开头添加 import matplotlib.pyplot as plt。
    • 确保没有将变量名 ax 分配为 Axes 对象。Axes 对象是由 plt.subplots() 或 plt.add_axes() 等函数返回的,因此如果使用 ax 作为一个普通变量,可能会导致冲突。
    • 可能是代码中的其他部分修改了 Matplotlib 的默认行为,导致 AxesStack 不可调用。请检查在绘制图形之前是否有任何涉及 Matplotlib 的自定义设置或修改。

    在确认以上问题之后,可以尝试修改代码,并确保绘图部分没有与之前提到的问题冲突,从而避免该错误的出现。

    解决方法:这是原来的代码,

    1. pos = nx.spring_layout(G1) # 必须设定一个统一的布局,保证下面分步绘制的图的统一性,而且分步绘制时pos是一个必须参数
    2. plt.figure(figsize=(9, 9))
    3. plt.title('SD pair: ' + str((path[0], path[-1])) + ', Time slot: ' + str(slot) + ', #paths: ' + str(len(paths)))
    4. nx.draw(G1, pos, with_labels=True, node_color=color_map, width=color_edge, node_size=150, font_size=12, alpha=0.6, ax=ax)

    我遇到的是第二个原因:因为与 Matplotlib 的 Axes 对象(ax)冲突。

    为了解决这个问题,尝试在绘制图形时明确指定 Axes 对象。在 plt.subplots() 中创建一个新的 Axes 对象,然后将其传递给 nx.draw() 函数。

    1. pos = nx.spring_layout(G1) # 必须设定一个统一的布局,保证下面分步绘制的图的统一性,而且分步绘制时pos是一个必须参数
    2. fig, ax = plt.subplots(figsize=(10, 8))
    3. # plt.figure(figsize=(9, 9))
    4. # plt.title('SD pair: ' + str((path[0], path[-1])) + ', Time slot: ' + str(slot) + ', #paths: ' + str(len(paths)))
    5. nx.draw(G1, pos, with_labels=True, node_color=color_map, width=color_edge, node_size=150, font_size=12, alpha=0.6, ax=ax)
    6. ax.set_title('SD pair: ' + str((path[0], path[-1])) + ', Time slot: ' + str(slot) + ', #paths: ' + str(len(paths)))

    三、pandas读取表格解决遇到的问题

    解决ValueError: Excel file format cannot be determined, you must specify an engine manually.

    报错:我在使用python的pandas读取表格的数据,但是报错了,

    1. import pandas as pd
    2. file_path = 'intersection.xlsx' # r对路径进行转义,windows需要
    3. df = pd.read_excel(file_path, header=0, usecols=[0]) # header=0表示第一行是表头,就自动去除了, 指定读取第1列
    4. print(df)
    wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

    问题:问题在于原表格格式可能有些问题。

    解决:最直接的办法就是把表格的内容复制到一个自己新建的表格中,然后改成之前表格的路径,

    然后再安装这个openpyxl第三方库。

     pip install openpyxl
    

    重新运行代码,

    ok,问题解决。

    查找两个列表中相同的元素

    解决:查找两个列表中相同的元素,可以把列表转为元祖/集合,进行交运算。

    1. import pandas as pd
    2. file_path = r'int.xlsx' # r对路径进行转义,windows需要
    3. df = pd.read_excel(file_path, header=0, usecols=[3, 4]) # header=0表示第一行是表头,就自动去除了, 指定读取第3和4列
    4. i, o = list(df['i']), list(df['o'])
    5. in_links, out_links = [], []
    6. a = set(in_links) # 转成元祖
    7. b = set(out_links)
    8. c = (a & b) # 集合c和b中都包含了的元素
    9. print(a, '\n', b)
    10. print('两个列表中相同的元素是:', list(c))
    wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

    解决but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details

    报错

    but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details

    问题:xxx文件里有中文字符。

    解决:在py文件的代码第一行 加上,

    #  -*-coding:utf8 -*-

    解决MatplotlibDeprecationWarning: Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later.

    报错:在使用pandas读取文件时,显示错误。

    MatplotlibDeprecationWarning: Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later.

    问题:matplotlib3.2以后就把mpl-data分离出去了 。

    解决:卸载原来的版本,安装3.1版本。

    1. pip uninstall matplotlib # 卸载原来的版本
    2. pip install matplotlib==3.1.1 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com # 安装3.1版本
    wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==
  • 相关阅读:
    解决navicat premium连接数据库自动断开问题
    egrep扩展正则表达式
    MySQL的游标遍历
    Java之~反射,String类型模板匹配类属性方法
    数字化转型的“支点”是什么?
    虚拟机安装 | 远程连接服务器
    Ubuntu22.04(非虚拟机)安装教程(2023最新最详细)
    Java面试八股文 2021年最新Java面试题及答案汇总
    【数据结构与算法】- 图(算法)
    2022身份识别技术大会 | 安全证件 | 可信身份认证 | 生物识别 | 公共安全安防身份技术展览会
  • 原文地址:https://blog.csdn.net/qq_45956730/article/details/131426385