LoginSignup
10
8

More than 1 year has passed since last update.

Windowsにanaconda & VSCode環境を導入したら、いろいろつまづいたのでメモ

Last updated at Posted at 2022-02-27

絶対忘れるのでメモ

Anacondaを公式からインストールする

こちらからダウンロード
(画像はリンク先ページ下部にあります。)
image.png

インストーラーを起動してインストール

VSCodeを公式からインストールする

こちらからダウンロード
image.png

インストーラーを起動してインストール

pythonの拡張機能を追加
image.png

Microsoft Storeが起動するのはなぜ

コマンドプロンプトでpythonを起動

$ python

Microsoft Storeが起動!?
image.png

対処法

設定 → アプリと機能 → アプリ実行エイリアス と開き、アプリ実行エイリアスをオフにする
image.png

PATHを通す

コントロールパネル → システムとセキュリティ → システム → システムの詳細設定 → 環境変数

  • ユーザー環境変数のPathに追加
    • anaconda3までのパス
    • 使用する仮想環境までのパス (anaconda3/env/仮想環境名)
  • システム環境変数に追加
    • anaconda3配下のpython.exe

python.pythonpathなんてものはない

VSCode起動 → python.pythonpathを検索 → 設定は見つかりません!!
image.png

対処法

  1. pythonを使用するフォルダをVSCodeで開く
    image.png

  2. コマンドパレットを開く
    image.png

  3. 基本設定:ワークスペースの設定を開く(JSON)
    image.png

  4. pythonのパスを指定する
    image.png

仮想環境を使う場合
 "python.defaultinterpreterPath": "C:\\Users\\UserName\\anaconda3\\envs\\仮想環境名\\python.exe"

import numpyがエラーなる

import numpy

>>
C:\Users\UserName\anaconda3\lib\site-packages\numpy\__init__.py:143: 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
Traceback (most recent call last):
  File "C:\Users\UserName\anaconda3\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
    from . import multiarray
  File "C:\Users\UserName\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "C:\Users\UserName\anaconda3\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\UserName\Documents\python\python.py", line 2, in <module>
    import numpy as np
  File "C:\Users\UserName\anaconda3\lib\site-packages\numpy\__init__.py", line 145, in <module>
    from . import core
  File "C:\Users\UserName\anaconda3\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\UserName\anaconda3\python.exe"
  * The NumPy version is: "1.20.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:  指定されたモジュールが見つかりません

対処法1 PowerShellの設定

anaconda prompt
$ conda init powershell
windows powershell
赤字でエラーが表示される

$ Set-ExecutionPolicy RemoteSigned

実行ポリシーの変更
実行ポリシーは、信頼されていないスクリプトからの保護に役立ちます。実行ポリシーを変更すると、about_Execution_Policies のヘルプ
トピック (https://go.microsoft.com/fwlink/?LinkID=135170)
で説明されているセキュリティ上の危険にさらされる可能性があります。実行ポリシーを変更しますか?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "N"):Yを入力してENTER

対処法2 PATHを通す

コントロールパネル → システムとセキュリティ → システム → システムの詳細設定 → 環境変数

  • ユーザー環境変数のPathに追加
    • C:\Users\UserName\anaconda3\Library\bin

できた

import numpy as np

print("hello")
y = np.ndarray([1, 2])
print(y)

>>
hello
[[-1.40787682e+128 -1.48302356e+047]]

参考

【初心者】Anacondaを使ったPython環境構築-Windows
コマンドプロンプトでpythonを実行するとMicrosoft Storeが開く問題
【Anaconda】仮想環境を使ったPython環境の構築
【最新】VSCodeでAnaconda3(Python)を実行する方法(Windows)
Anaconda+VScodeの環境の作る方法を解説
vscodeでanacondaを使うとnumpyがインポートエラーになる
Anaconda v5.3 Python3.7 verの導入に手こずったのでメモ

10
8
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8