LoginSignup
0
2

More than 3 years have passed since last update.

Ahead-of-Time コンパイル用 Numba 環境の導入 (Windows)

Last updated at Posted at 2020-08-12

はじめに

競技プログラミングの練習用に、
Ahead-of-Time (AOT) コンパイル可能な Numba 環境を導入するにあたり、
基礎知識が無さ過ぎてハマったので、備忘録を兼ね手順を以下に共有します。
実行環境は Windows です。詳細は文末に付記します。

手順1:Numba のインストール

以下の公式ドキュメントを参考にしました。
https://numba.pydata.org/numba-doc/latest/user/installing.html#installing-using-conda-on-x86-x86-64-power-platforms

当初 pip でインストールした numpy と
conda でインストールした Numba が共存していたので、
念のため、両方アンインストール後 conda で Numba をインストールしました。

ちなみに、この段階で Numba を実行すると、Microsoft C++ (MSVC) コンパイラツールセットが無い、
というエラーが出力されます。
msvc が何のことやら分からず、ここでハマりました。

error.txt
RuntimeError:
Attempted to compile AOT function without the compiler used by `numpy.distutils` present. Cannot find suitable msvc.

手順2:C コンパイラの入手

以下を参考にしました。
https://www.python.jp/install/windows/install_vstools2017.html

2020/8/12 現在、インストールしたバージョンは以下です。

・Visual Studio Build Tools 2019 16.7.1

インストール後、再起動が必要です。

Windows 以外の環境で必要なコンパイラに関しては、以下を参照ください。
https://numba.pydata.org/numba-doc/latest/user/installing.html#installing-from-source

実行確認

以下のサンプルコードを元に、my_module.xxxx-win_amd64.pyd の生成と、
他の実行ファイルによる my_module のインポートを確認しました。

おわりに

Python しかプログラミングの経験がないので、
プログラムを(一部でも)コンパイルして、実行するのが楽しいです。
拙文ですが、どなたかのお役に立てば幸いです。

参考:実行環境

system.txt
(py38) C:\Users\test>python -m numba -s
System info:
--------------------------------------------------------------------------------
略)

__OS Information__
Platform Name                                 : Windows-10-10.0.18362-SP0
Platform Release                              : 10
OS Name                                       : Windows
OS Version                                    : 10.0.18362
OS Specific Version                           : 10 10.0.18362 SP0
Libc Version                                  : ?

__Python Information__
Python Compiler                               : MSC v.1916 64 bit (AMD64)
Python Implementation                         : CPython
Python Version                                : 3.8.2
Python Locale                                 : ja_JP.cp932

略)

__Installed Packages__
Package         Version
--------------- -------------------
certifi         2020.6.20
cycler          0.10.0
icc-rt          2019.0
intel-openmp    2019.0
joblib          0.14.1
kiwisolver      1.2.0
llvmlite        0.33.0
matplotlib      3.2.1
msvc-runtime    14.27.29016
numba           0.50.1
numpy           1.19.1
pandas          1.0.3
pip             20.2.1
pycc            2.0.0
pyparsing       2.4.7
python-dateutil 2.8.1
pytz            2020.1
scikit-learn    0.23.0
scipy           1.4.1
setuptools      49.2.1.post20200807
six             1.14.0
threadpoolctl   2.0.0
wheel           0.34.2
wincertstore    0.2

略)
0
2
0

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
0
2