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

初学者运行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

相关文章:

  • Dagster软件定义资产(SDA)完全指南:从概念到落地实践
  • 前端开发中vue的脚手架你知道是什么意思吗?
  • Java中的集合框架:List、Set、Map的使用与性能对比
  • 自动托盘搬运车是什么?它的工作逻辑如何实现物流自动化?
  • Office2019下载安装教程(2025最新永久方法)(附安装包)
  • 小程序 UI 设计,怎样在方寸间实现高效交互
  • PosterSQL日常维护
  • 免费开源的微信开发框架
  • 深度学习小项目合集之图像分割识别-视频介绍下自取
  • 【AI智能体】Coze 数据库从使用到实战操作详解
  • MySQL 8配置文件详解
  • JavaEE-发展历史
  • 使用 C++ 和 OpenCV 构建智能答题卡识别系统
  • 编程学习网站大全(C++/OpenCV/QT方向)—— 资源导航与深度评测
  • 【Lua热更新知识】学习三 XLua学习
  • JavaEE-SpringBoot
  • JavaEE-Maven
  • Leetcode-11 2 的幂
  • 解决华为云服务器无法ping通github问题
  • 智能体商业化:创建-接入-封装成小程序/网站/H5
  • 上海企业网站建设制/资源搜索引擎搜索神器网
  • 网站建设 济南/网站权重怎么看
  • 物流门户网站源码/个人网站设计图片
  • 怎么建设一个优秀的网站/优化网络培训
  • 深圳 做网站/制作自己的网站
  • 网站建设尾款催收函/杭州网站免费制作