0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

iRICライブラリのインポートエラーに関する備忘録

Posted at

はじめに

Python 3.10がインストールされている仮想環境では、iRICライブラリのインポート時にエラーが発生しました。C/C++拡張モジュール(_iric.pyd)の依存関係を dumpbin コマンドで調べたところ、Python 3.12用にビルドされているようでした。そのため、Python 3.12用に仮想環境を構築し、iRICライブラリのインポートに必要となるDLLファイルやPythonライブラリを準備したところ、正常にiRICライブラリをインポートできるようになりました。

iRICユーザーズマニュアル

iRICライブラリのインポートエラー

Python 3.10.8がインストールされている仮想環境にて、iRICライブラリのインポートを試みた時、次の画像のようなエラーが発生しました。

iRICライブラリのインポートエラー
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\(User)\AppData\Local\miniconda3\envs\py310\lib\site-packages\iric.py", line 16, in <module>
    import _iric
ImportError: DLL load failed while importing _iric: 指定されたモジュールが見つかりません。

_iric.pydが存在しないか、依存DLLが不足しているため、このようなエラーが発生すると思われます。_iric.pydは所定のフォルダに格納されているため、依存DLLについて調査しました。なお、_iric.pydは通常、次のようなフォルダに格納されているはずです。

C:\Users\(ユーザー名)\AppData\Local\miniconda3\envs\(仮想環境名)\Lib\site-packages

依存DLLの調査

_iric.pydの依存DLLを調査するにあたって、Visual Studioの開発者コマンドプロンプトを使用しました。このプロンプトではdumpbinコマンドを使うことができます。実際に、次のようなコマンドを実行して、_iric.pydの依存関係を確認しました。

dumpbin
dumpbin /dependents _iric.pyd
dumpbinの結果
Dump of file _iric.pyd
File Type: DLL

 Image has the following dependencies:
    iriclib.dll
    python312.dll
    MSVCP140.dll
    VCRUNTIME140.dll
    VCRUNTIME140_1.dll
    api-ms-win-crt-runtime-l1-1-0.dll
    api-ms-win-crt-stdio-l1-1-0.dll
    api-ms-win-crt-heap-l1-1-0.dll
    api-ms-win-crt-string-l1-1-0.dll
    KERNEL32.dll

  Summary
        5000 .data
        2000 .pdata
       3E000 .rdata
        1000 .reloc
        1000 .rsrc
       80000 .text

依存DLLの中にpython312.dllがあります。すなわち、_iric.pydはPython 3.12用にビルドされているのではないかと考え、Python 3.12用の仮想環境を新たに作成し、再度iRICライブラリのインポートを試みました。

仮想環境の構築(Python 3.12)

Anaconda Promptにて次のコマンドを実行し、仮想環境を新規作成します。

仮想環境の作成
conda create -n py312 python=3.12
conda activate py312
# 仮想環境py312の有効化

iRICユーザーズマニュアル内、「既存の Miniconda を使った iRICソルバの実行環境の構築」を参照して、iRICやPythonのライブラリをインストールします。

なお、今回インストールしたPythonライブラリのバージョンは次の通りです。

Pythonライブラリ
ライブラリ名	バージョン	参照元との比較
numpy		1.26.4		-
numba		0.59.1		-
scipy		1.13.1		-
gdal		3.11.4		3.6.2
h5py		3.11.0		-
pandas		2.2.2		-
matplotlib	3.8.4		-
requests	2.32.2		-
beautifulsoup4	4.12.3		-	
pyproj		3.7.2		3.6.1

iRICの計算結果ファイル `Case1.cgn' があるフォルダにて、次のPythonのコマンドが問題なく動作することを確認します。

iRICライブラリインポート
from iric import *
fname = "Case1.cgn"
fid = cg_iRIC_Open(fname, CG_MODE_READ)

さいごに

iRICライブラリのインポートができず困っていたので、dumpbinの存在にかなり助けられました。

参考サイト(2025/10/30最終アクセス)

DUMPBIN リファレンス
知っておくといざというときに役に立つ優れモノ!その名は COFF/PE Dumper(dumpbin.exe)!
.pydファイルは、WindowsではDLLそのもの

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?