项目场景:
UserWarning: mkl-service package failed to import, therefore Intel® 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
Traceback (most recent call last):
File "F:\miniconda\envs\demo\lib\site-packages\numpy\core_init.py", line 23, in
from . import multiarray
File “F:\miniconda\envs\demo\lib\site-packages\numpy\core\multiarray.py”, line 10, in
from . import overrides
File “F:\miniconda\envs\demo\lib\site-packages\numpy\core\overrides.py”, line 6, in
from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\Administrator\Desktop\demo_project\main.py”, line 6, in
import torch.cuda
File “F:\miniconda\envs\demo\lib\site-packages\torch_init_.py”, line 613, in
C.initExtension(manager_path())
File "F:\miniconda\envs\demo\lib\site-packages\torch\cuda_init.py", line 685, in
from . import amp
File "F:\miniconda\envs\demo\lib\site-packages\torch\cuda\amp_init.py", line 1, in
from .autocast_mode import autocast, custom_fwd, custom_bwd # noqa: F401
File “F:\miniconda\envs\demo\lib\site-packages\torch\cuda\amp\autocast_mode.py”, line 5, in
import numpy as np
File “F:\miniconda\envs\demo\lib\site-packages\numpy_init_.py”, line 141, in
from . import core
File “F:\miniconda\envs\demo\lib\site-packages\numpy\core_init_.py”, line 49, in
raise ImportError(msg)
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 “F:\miniconda\envs\demo\python.exe”
- The NumPy version is: “1.24.3”
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: 找不到指定的模块。
问题描述
import torch.cuda
import random
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# print(cv2.version)
print(torch.cuda.is_available())
# 测试随机抽样
List = ['R', 'G', 'B']
Samples = random.choices(List, weights=[2, 5, 3], k=100)
print(Samples)
解决方案:
打开编辑配置,修改环境变量添加如下代码
Path=F:\miniconda\envs\demo\Library\bin
结果: