Jupyter Notebook出错提示An error occurred while retrieving package information解决办法

出错日志信息:

   To access the notebook, open this file in a browser:
        file:///C:/Users/colda/AppData/Roaming/jupyter/runtime/nbserver-14564-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=3c0113e5da07c0b8b8c9de74ffb453c50470ac8cee429bff
     or http://127.0.0.1:8888/?token=3c0113e5da07c0b8b8c9de74ffb453c50470ac8cee429bff
[E 13:39:33.298 NotebookApp] Uncaught exception GET /conda/packages/available?_=1710567542007 (::1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/conda/packages/available?_=1710567542007', version='HTTP/1.1', remote_ip='::1')
    Traceback (most recent call last):
      File "D:\Miniconda\envs\jupyter\lib\site-packages\tornado\web.py", line 1784, in _execute
        result = method(*self.path_args, **self.path_kwargs)
      File "D:\Miniconda\envs\jupyter\lib\site-packages\tornado\web.py", line 3290, in wrapper
        return method(self, *args, **kwargs)
      File "D:\Miniconda\envs\jupyter\lib\site-packages\notebook\base\handlers.py", line 782, in wrapper
        return method(self, *args, **kwargs)
      File "D:\Miniconda\envs\jupyter\lib\site-packages\nb_conda\handlers.py", line 230, in get
        data = searcher.list_available(self)
      File "D:\Miniconda\envs\jupyter\lib\site-packages\nb_conda\handlers.py", line 197, in list_available
        version = parse_version(entry.get('version', ''))
      File "D:\Miniconda\envs\jupyter\lib\site-packages\pkg_resources\_vendor\packaging\version.py", line 198, in __init__
        raise InvalidVersion(f"Invalid version: '{version}'")
    pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: 'custom'
[W 13:39:33.314 NotebookApp] Unhandled error
[E 13:39:33.314 NotebookApp] {
      "Host": "localhost:8888",
      "Accept": "application/json, text/javascript, */*; q=0.01",
      "Referer": "http://localhost:8888/tree",
      "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0"
    }
[E 13:39:33.314 NotebookApp] 500 GET /conda/packages/available?_=1710567542007 (::1) 501.660000ms referer=http://localhost:8888/tree

分析是package版本解析时遇到了问题了

解决方法:

将这个路径下的 handlers.py 代码进行修改,各人的安装路径不同,对照自己的路径找一下

D:\Miniconda\pkgs\nb_conda-2.2.1-py38_1\Lib\site-packages\nb_conda\handlers.py

修改前

                for entries in data.values():
                    max_version = None
                    max_version_entry = None

                    for entry in entries:
                        version = parse_version(entry.get('version', ''))

                        if max_version is None or version > max_version:
                            max_version = version
                            max_version_entry = entry

                    packages.append(max_version_entry)

                return sorted(packages, key=lambda entry: entry.get('name'))

修改后

              for entries in data.values():
                    max_version = None
                    max_version_entry = None

                    for entry in entries:
                        try:
                            version = parse_version(entry.get('version', ''))
                        except Exception as e:
                        #    print(entry.get('name'))
                            continue

                        if max_version is None or version > max_version:
                            max_version = version
                            max_version_entry = entry

                    if max_version_entry:
                        packages.append(max_version_entry)

                return sorted(packages, key=lambda entry: entry.get('name'))

经过测试,成功解决问题

相关推荐
温柔的男孩像海洋丶19 分钟前
vscode的keil assistant 中搜索不到全局变量
ide·vscode·单片机
Auc2444 分钟前
使用scrapy框架爬取微博热搜榜
开发语言·python
梦想画家1 小时前
Python Polars快速入门指南:LazyFrames
python·数据分析·polars
程序猿000001号1 小时前
使用Python的Seaborn库进行数据可视化
开发语言·python·信息可视化
API快乐传递者1 小时前
Python爬虫获取淘宝详情接口详细解析
开发语言·爬虫·python
公众号Codewar原创作者1 小时前
R数据分析:工具变量回归的做法和解释,实例解析
开发语言·人工智能·python
FL16238631291 小时前
python版本的Selenium的下载及chrome环境搭建和简单使用
chrome·python·selenium
巫师不要去魔法部乱说2 小时前
PyCharm专项训练5 最短路径算法
python·算法·pycharm
Chloe.Zz2 小时前
Python基础知识回顾
python
骑个小蜗牛2 小时前
Python 标准库:random——随机数
python