当前位置: 首页 > web >正文

初学者运行Pycharm程序可能会出现的问题,及解决办法

文章目录

  • 前言
  • 一、ModuleNotFoundError: No module named 'sklearn'
  • 二、ImportError: cannot import name 'show_config' from 'numpy' (unknown location)
  • 三、Pycharm报错:“Original error was: DLL load failed: 找不到指定的模块“ 的解决办法
  • 四、ImportError: cannot import name '_imaging' from 'PIL'ImportError: cannot import name '_imaging' from 'PIL'
  • 五、ImportError: bad magic number in 'vlib.layers': b'\x03\xf3\r\n'
  • 六、AttributeError: module ‘backend_interagg‘ has no attribute ‘FigureCanvas‘的解决办法
  • 七、WARNING: Skipping D:\1Python_text\Anaconda3\envs\jupter_huan\Lib\site-packages\numpy-1.21.6.dist-info due to invalid metadata entry 'name'
  • 八、删除路径上numpy-1.21.6.dist-info文件夹
  • 九、TypeError: warn() missing 1 required keyword-only argument: 'stacklevel'
  • 十、ImportError: cannot import name 'if_delegate_has_method' from 'sklearn.utils.metaestimators' (D:\1Python_text\Anaconda3\envs\mmd\lib\site-packages\sklearn\utils\metaestimators.py)
  • 十一、Python错误:AttributeError: module ‘tensorflow’ has no attribute ‘Session’
  • 十二、ModuleNotFoundError: No module named '_distutils_hack'
  • 十三、Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly
  • 十四、ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly
  • 十五、ERROR: Could not build wheels for opencv-python, which is required to install pyproject.toml-based projects
  • 十六、ModuleNotFoundError: No module named ‘tensorflow.contrib‘
  • 十七、AttributeError: module 'wandb' has no attribute 'init'
  • 十八、CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/win-32/current_repodata.json>
  • 十九、'tuple' object has no attribute 'size'
  • 二十、 UserWarning: CUDA initialization: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the available devices to be zero. (Triggered internally at /opt/conda/conda-bld/pytorch_1614378083779/work/c10/cuda/CUDAFunctions.cpp:109.)
  • 二十一、ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conf licts. torchaudio 2.4.1 requires torch ==2.4.1, but you have torch 2.0.0+cu118 which is incompatible. torchvision 0.19.1 requires torch ==2.4.1, but you have torch 2.0.0+cu118 which is incompatible.


前言

以下介绍初学者运行Pycharm程序可能会出现的问题,及解决办法。


一、ModuleNotFoundError: No module named ‘sklearn’

问题概括: Python 运行时提示找不到’sklearn’ 模块,说明系统未安装 scikit-learn 库。出现ModuleNotFoundError类似的错误,都是缺少库,安装引号内的库即可。部分库的名称和引号提示的名称不一致,例子的报错是’sklearn’,但安装的是scikit-learn。常见名称不一致的库如图1所示。

解决方案: 使用包管理器安装 scikit-learn,若用 pip 则执行pip install scikit-learn,若用 conda 则执行conda install scikit-learn。可在两个地方进行安装,如图2,图3。(注:安装库的前提是已经创建好虚拟环境,并把虚拟环境连接 PyCharm中。如果没进行这两步,可依次点击下面链接进行操作。)
创建虚拟环境
虚拟环境连接 PyCharm
图1

图1常见名称不一致的库

在这里插入图片描述

图2 pycharm中安装库

在这里插入图片描述

图3 Anaconda Prompt (ANaconda 3)中安装库

二、ImportError: cannot import name ‘show_config’ from ‘numpy’ (unknown location)

问题概括: 原因报错是由于Scipy与Numpy版本不兼容导致的,一般是由于Scipy版本过高,而Numpy版本过低。
Scipy 1.1.0 + Numpy 1.15.0 版本完全兼容

pip uninstall numpy
pip install numpy==1.15.0

三、Pycharm报错:“Original error was: DLL load failed: 找不到指定的模块“ 的解决办法

打开Anaconda prompt–-conda activate +你的虚拟环境名

pip uninstall -y numpy
pip uninstall -y setuptools
pip install setuptools
pip install numpy

四、ImportError: cannot import name ‘_imaging’ from 'PIL’ImportError: cannot import name ‘_imaging’ from ‘PIL’

卸载:pip uninstall Pillow
重装:pip uninstall Pillow

五、ImportError: bad magic number in ‘vlib.layers’: b’\x03\xf3\r\n’

解决办法:删除项目中所有的 .pyc 文件。

六、AttributeError: module ‘backend_interagg‘ has no attribute ‘FigureCanvas‘的解决办法

加入:

import matplotlib
matplotlib.use('TkAgg')

七、WARNING: Skipping D:\1Python_text\Anaconda3\envs\jupter_huan\Lib\site-packages\numpy-1.21.6.dist-info due to invalid metadata entry ‘name’

八、删除路径上numpy-1.21.6.dist-info文件夹

应该是numpy的包出现问题,需要重新安装numpy+mkl

九、TypeError: warn() missing 1 required keyword-only argument: ‘stacklevel’

pip uninstall traitlets
pip install traitlets==5.9.0

十、ImportError: cannot import name ‘if_delegate_has_method’ from ‘sklearn.utils.metaestimators’ (D:\1Python_text\Anaconda3\envs\mmd\lib\site-packages\sklearn\utils\metaestimators.py)

pip install --user scikit-learn==0.23.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

十一、Python错误:AttributeError: module ‘tensorflow’ has no attribute ‘Session’

import tensorflow.compat.v1 as tf

十二、ModuleNotFoundError: No module named ‘_distutils_hack’

使用记事本或者sublime Text等软件打开/home/user/anaconda3/envs/SWINTS/lib/python3.8/site-packages/distutils-precedence.pth这个文件,在该文件的import os;后边敲击一个回车键,然后保存即可。

十三、Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly

conda install py-opencv

十四、ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly

pip install --upgrade pip

十五、ERROR: Could not build wheels for opencv-python, which is required to install pyproject.toml-based projects

pip install -i https://pypi.douban.com/simple/ pip install opencv-python==4.3.0.38

十六、ModuleNotFoundError: No module named ‘tensorflow.contrib‘

出现 “ModuleNotFoundError: No module named ‘tensorflow.contrib’” 错误通常是因为在 TensorFlow 2.0 版本中,tensorflow.contrib 模块已被移除。使用tensorfolw.1.xhttps://blog.csdn.net/weixin_

十七、AttributeError: module ‘wandb’ has no attribute ‘init’

pip install wandb

十八、CondaHTTPError: HTTP 000 CONNECTION FAILED for url https://repo.anaconda.com/pkgs/main/win-32/current_repodata.json

Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.

If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.

SSLError(MaxRetryError(‘HTTPSConnectionPool(host=‘repo.anaconda.com’, port=443): Max retries exceeded with url: /pkgs/main/win-32/current_repodata.json (Caused by SSLError(SSLError(“bad handshake: Error([(‘SSL routines’, ‘ssl3_
get_server_certificate’, ‘certificate verify failed’)],)”,),))’,),)

解决方法参考

十九、‘tuple’ object has no attribute ‘size’

pip install torch-summary

二十、 UserWarning: CUDA initialization: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the available devices to be zero. (Triggered internally at /opt/conda/conda-bld/pytorch_1614378083779/work/c10/cuda/CUDAFunctions.cpp:109.)

win+r打开运行,输入devmgmt.msc打开设备管理器
向下拉直到展开显示适配器,右键单击第二项
点击启用设备即可打开GPU

二十一、ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conf licts. torchaudio 2.4.1 requires torch ==2.4.1, but you have torch 2.0.0+cu118 which is incompatible. torchvision 0.19.1 requires torch ==2.4.1, but you have torch 2.0.0+cu118 which is incompatible.

解决PyTorch相关库的版本冲突问题
即torch版本高,而torchvision torchaudio低的问题,安装制定版本的

pip install torchvision == 0.15.1  torchaudio ==2.0.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
http://www.xdnf.cn/news/13476.html

相关文章:

  • CMO增加人工智能投资:数据表明了什么
  • 软件架构期末复习
  • 7.路由汇聚及更新
  • Docker安装mysql数据库后显示时间问题
  • 3 mnist gan小试牛刀
  • 有多少小于当前数字的数字
  • 巨好用的提示词优化工具 Prompt IDE
  • React删除评论逻辑:1、客户端立即更新UI(乐观更新)2、后台调用删除评论API
  • 【测试专栏】自动化测试——云存储项目
  • 【源码】研学报名小程序开发功能分析案例
  • 网络安全之框架安全漏洞分析
  • 【网页端数字人开发】基于babylonjs+mediapipe实现视频驱动数字人姿态生成
  • .NET 的IOC框架Unity代码示例
  • LangGraph基础知识(MemorySaver/SqliteSaver )(三)
  • Qt::QueuedConnection详解
  • 告别 NullPointerException!深入探索 Java Optional 的最佳实践
  • P1216 [IOI 1994] 数字三角形 Number Triangles
  • C++之前向声明
  • QT绘制会动的蚂蚁线
  • [灵感源于算法] 链表类问题技巧总结
  • 【大模型训练】中短序列attention 和MOE层并行方式(二)
  • 如何在多任务环境中设定清晰的项目优先级?
  • 多面体基准测试集PolyBench
  • 前端~三维地图(cesium)点位聚合
  • 从零打造前沿Web聊天组件:从设计到交互
  • TikTok在英国用户量达3000万
  • 增强自注意力机制CeAtt,增强局部细节!
  • Scrapy爬虫框架:数据采集的瑞士军刀(附实战避坑指南)!!!
  • 如何开始HarmonyOS 5与Godot引擎融合开发?
  • 代码随想录训练营二十六天| 654.最大二叉树 617.合并二叉树 700.二叉搜索树的搜索 98.验证二叉搜索树