文章目錄
- 前言
- 一、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'
- 八、AttributeError: 'NoneType' object has no attribute 'split'
- 九、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
二、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文件夾
八、AttributeError: ‘NoneType’ object has no attribute ‘split’
應該是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