sh19870628
@sh19870628 (sho hida)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

numpy import on vscode

わからねえ

VSCode上の一部の仮想環境でnumpyのインポートに失敗する

発生している問題・エラー

PS C:\Users\sh198\work\deep-learning-from-scratch> & C:/Users/sh198/Anaconda3/envs/rl/python.exe c:/Users/sh198/work/deep-learning-from-scratch/ch04/train_neuralnet.py
Traceback (most recent call last):
  File "C:\Users\sh198\Anaconda3\envs\rl\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
    from . import multiarray
  File "C:\Users\sh198\Anaconda3\envs\rl\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "C:\Users\sh198\Anaconda3\envs\rl\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    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\sh198\work\deep-learning-from-scratch\ch04\train_neuralnet.py", line 4, in <module>
    import numpy as np
  File "C:\Users\sh198\Anaconda3\envs\rl\lib\site-packages\numpy\__init__.py", line 150, in <module>
    from . import core
  File "C:\Users\sh198\Anaconda3\envs\rl\lib\site-packages\numpy\core\__init__.py", line 48, in <module>
    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.9 from "C:\Users\sh198\Anaconda3\envs\rl\python.exe"
  * The NumPy version is: "1.21.4"

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: 指定されたモジュールが見つかりません。
  • 問題ない仮想環境もある
  • VSCodeに代わりanaconda powershellからは問題が起こらない

この現象が起きる仮想環境の共通点

  • _multiarray_umath.cp39-win_amd64.pydが…/envs/(仮想環境名)/Lib/site-packages/numpy/coreのなかに存在する
  • pythonとnumpyのバージョンは関係なさそう

自分で試したこと

悔しいから再インストールとかしたくない
vscodeとpowershellでそれぞれ$PATHを確認する.
powershell側は…/envs/(仮想環境名)/Lib/site-packagesを含んでいるのに対して,vscode上ではそれが含まれていない.

  • vscodeの場合
    PS C:\Users\sh198\work\deep-learning-from-scratch> & C:/Users/sh198/Anaconda3/envs/ml_general/python.exe c:/Users/sh198/OneDrive/デスクトップ/test.py
    C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Python38\Scripts\;C:\Python38\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Program Files\Java\jdk-14.0.2\bin;C:\texlive\2020\bin\win32;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Vim\vim82;C:\PROGRA~1\JPKI;C:\Users\sh198\AppData\Local\Microsoft\WindowsApps;C:\Users\sh198\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\sh198\AppData\Roaming\npm;C:\Program Files (x86)\gstreamer\1.0\msvc_x86_64\bin;C:\Users\sh198\AppData\Local\atom\bin;C:\Program Files\ffmpeg-2021-12-30-git-12f21849e5-full_build\bin;
  • powershellの場合
    In [3]: os.environ.get('PATH')
    Out[3]: 'C:\\Users\\sh198\\Anaconda3\\envs\\ml_general;C:\\Users\\sh198\\Anaconda3\\envs\\ml_general\\Library\\mingw-w64\\bin;C:\\Users\\sh198\\Anaconda3\\envs\\ml_general\\Library\\usr\\bin;C:\\Users\\sh198\\Anaconda3\\envs\\ml_general\\Library\\bin;C:\\Users\\sh198\\Anaconda3\\envs\\ml_general\\Scripts;C:\\Users\\sh198\\Anaconda3\\envs\\ml_general\\bin;C:\\Users\\sh198\\Anaconda3\\condabin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Python38\\Scripts;C:\\Python38;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0;C:\\Windows\\System32\\OpenSSH;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Program Files\\nodejs;C:\\ProgramData\\chocolatey\\bin;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Java\\jdk-14.0.2\\bin;C:\\texlive\\2020\\bin\\win32;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0;C:\\WINDOWS\\System32\\OpenSSH;C:\\Program Files (x86)\\Vim\\vim82;C:\\PROGRA~1\\JPKI;C:\\Users\\sh198\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\sh198\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\sh198\\AppData\\Roaming\\npm;C:\\Program Files (x86)\\gstreamer\\1.0\\msvc_x86_64\\bin;C:\\Users\\sh198\\AppData\\Local\\atom\\bin;C:\\Program Files\\ffmpeg-2021-12-30-git-12f21849e5-full_build\\bin'
0

1Answer

Your answer might help someone💌