赞
踩
安装gpu版本的pytorch之后,在pycharm上测试没出现问题而在jupyter notebook却出现问题
import torch
E:\Miniconda3\envs\d2l\lib\site-packages\numpy\__init__.py:148: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service from . import _distributor_init --------------------------------------------------------------------------- ImportError Traceback (most recent call last) File E:\Miniconda3\envs\d2l\lib\site-packages\numpy\core\__init__.py:22, in <module> 21 try: ---> 22 from . import multiarray 23 except ImportError as exc: File E:\Miniconda3\envs\d2l\lib\site-packages\numpy\core\multiarray.py:12, in <module> 10 import warnings ---> 12 from . import overrides 13 from . import _multiarray_umath File E:\Miniconda3\envs\d2l\lib\site-packages\numpy\core\overrides.py:7, in <module> 5 import textwrap ----> 7 from numpy.core._multiarray_umath import ( 8 add_docstring, implement_array_function, _get_implementing_args) 9 from numpy.compat._inspect import getargspec ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的模块。 During handling of the above exception, another exception occurred: ImportError Traceback (most recent call last) Input In [1], in <cell line: 1>() ----> 1 import torch File E:\Miniconda3\envs\d2l\lib\site-packages\torch\__init__.py:721, in <module> 718 from .autocast_mode import autocast 720 # Shared memory manager needs to know the exact location of manager executable --> 721 _C._initExtension(manager_path()) 722 del manager_path 724 # Appease the type checker: it can't deal with direct setting of globals(). 725 # Note that we will see "too many" functions when reexporting this way; there 726 # is not a good way to fix this problem. Perhaps, try to redesign VariableFunctions 727 # so that this import is good enough File E:\Miniconda3\envs\d2l\lib\site-packages\torch\cuda\__init__.py:759, in <module> 757 from . import profiler 758 from . import nvtx --> 759 from . import amp File E:\Miniconda3\envs\d2l\lib\site-packages\torch\cuda\amp\__init__.py:1, in <module> ----> 1 from .autocast_mode import autocast, custom_fwd, custom_bwd # noqa: F401 2 from .grad_scaler import GradScaler File E:\Miniconda3\envs\d2l\lib\site-packages\torch\cuda\amp\autocast_mode.py:5, in <module> 3 import collections 4 try: ----> 5 import numpy as np 6 HAS_NUMPY = True 7 except ModuleNotFoundError: File E:\Miniconda3\envs\d2l\lib\site-packages\numpy\__init__.py:150, in <module> 147 # Allow distributors to run custom init code 148 from . import _distributor_init --> 150 from . import core 151 from .core import * 152 from . import compat File E:\Miniconda3\envs\d2l\lib\site-packages\numpy\core\__init__.py:48, in <module> 24 import sys 25 msg = """ 26 27 IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! (...) 46 """ % (sys.version_info[0], sys.version_info[1], sys.executable, 47 __version__, exc) ---> 48 raise ImportError(msg) 49 finally: 50 for envkey in env_added: ImportError: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed. We have compiled some common reasons and troubleshooting tips at: https://numpy.org/devdocs/user/troubleshooting-importerror.html Please note and check the following: * The Python version is: Python3.8 from "E:\Miniconda3\envs\d2l\python.exe" * The NumPy version is: "1.21.5" and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help. Original error was: DLL load failed while importing _multiarray_umath: 找不到指定的模块。
切换到pytorch环境,安装jupyter
conda install jupyter -y
然后将pytorch环境添加到jupyter
python -m ipykernel install --user --name=环境名 --display-name "Python (环境名)"
(需ipykernel)
使用pycharm是没问题的,但强迫症的我非要在jupyter上运行,浪费不少时间,但结果还是不错的。
网上查了大量资料,有说jupyter需要Cython,安装之后还是报错;有说重启kernel,结果怎么重启都未能解决。
一个小问题搞了一晚上,终于解决
参考:https://blog.csdn.net/BILL_Apple/article/details/122937160
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。