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

文章目录

  • 前言
  • [一、ModuleNotFoundError: No module named 'sklearn'](#一、ModuleNotFoundError: No module named 'sklearn')
  • [二、ImportError: cannot import name 'show_config' from 'numpy' (unknown location)](#二、ImportError: cannot import name 'show_config' from 'numpy' (unknown location))
  • [三、Pycharm报错:"Original error was: DLL load failed: 找不到指定的模块" 的解决办法](#三、Pycharm报错:“Original error was: DLL load failed: 找不到指定的模块“ 的解决办法)
  • [四、ImportError: cannot import name '_imaging' from 'PIL'ImportError: cannot import name '_imaging' from 'PIL'](#四、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'](#五、ImportError: bad magic number in 'vlib.layers': b'\x03\xf3\r\n')
  • [六、AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'的解决办法](#六、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'](#七、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'](#九、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)](#十、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'](#十一、Python错误:AttributeError: module ‘tensorflow’ has no attribute ‘Session’)
  • [十二、ModuleNotFoundError: No module named '_distutils_hack'](#十二、ModuleNotFoundError: No module named '_distutils_hack')
  • [十三、Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly](#十三、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 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](#十五、ERROR: Could not build wheels for opencv-python, which is required to install pyproject.toml-based projects)
  • [十六、ModuleNotFoundError: No module named 'tensorflow.contrib'](#十六、ModuleNotFoundError: No module named ‘tensorflow.contrib‘)
  • [十七、AttributeError: module 'wandb' has no attribute 'init'](#十七、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\>](#十八、CondaHTTPError: HTTP 000 CONNECTION FAILED for url https://repo.anaconda.com/pkgs/main/win-32/current_repodata.json)
  • [十九、'tuple' object has no attribute 'size'](#十九、'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.)](#二十、 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.](#二十一、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常见名称不一致的库


图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 版本完全兼容

c 复制代码
pip uninstall numpy
pip install numpy==1.15.0

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

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

c 复制代码
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'的解决办法

加入:

c 复制代码
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'

c 复制代码
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)

c 复制代码
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

c 复制代码
conda install py-opencv

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

c 复制代码
pip install --upgrade pip

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

c 复制代码
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'

c 复制代码
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'

c 复制代码
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低的问题,安装制定版本的

c 复制代码
pip install torchvision == 0.15.1  torchaudio ==2.0.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
相关推荐
jz_ddk4 分钟前
[python] 使用python设计滤波器
开发语言·python·学习·算法
墨城之左14 分钟前
OpenSSL 无法验证 DevSidecar 的自签名证书
python
layneyao19 分钟前
Python+TensorFlow:30分钟快速入门AI开发
人工智能·python·tensorflow
import_random28 分钟前
[python]random模块(介绍+使用)
python
fydw_71529 分钟前
Jinja2 模板在 Python 和 LLM 提示词编辑器中的应用
开发语言·python·编辑器
赵谨言38 分钟前
基于mapreduce的气候分析系统设计与实现
经验分享·python·毕业设计
Fighting_199742 分钟前
VSCode占C盘内存太大,如何处理
c语言·ide·vscode
yzx9910131 小时前
Python开发功能项目
服务器·开发语言·人工智能·python·深度学习
HINOTOR_1 小时前
DAY 29 复习日:类的装饰器
开发语言·python
Gyoku Mint2 小时前
机器学习×第七卷:正则化与过拟合——她开始学会收敛,不再贴得太满
人工智能·python·算法·chatgpt·线性回归·ai编程