私は数時間この状態にいました。 Cygwinでgccを使ってClionでコンパイルした単純なhello-world .dllがあります。CygwinでDLLをPythonに読み込む
CygwinディレクトリにあるPycharmのanacondaインストール(インタープリタ)からPythonスクリプトを実行しています。
.dllファイル名は "cygextension_test_c.dll"です。
は、私は(すべて私は見つけることができるこのトピックに関する質問の最後の10年間で様々なソリューションそのうちの下にリストされているさまざまな構成では、Pythonのプロジェクトディレクトリへの.dllを移動し、次のコードを実行します。今日の午後は - 私は)Cコードにndarraysを送信するため、以下のwebsiteのオフに働いています:
import numpy as N
from numpy.ctypeslib import load_library
from numpyctypes import c_ndarray
import ctypes
import os
print(ctypes.windll.kernel32);
mydll = load_library('cygextension_test_c.dll',r'C:\cygwin64\home\...\extension_test_c\cmake-build-debug');
mydll = ctypes.WinDLL(r'same path, essentially--this time pointing to working directory\cygextension_test_c.dll')
mydll = ctypes.CDLL(r'ditto')
mydll = ctypes.cdll.LoadLibrary('...')
mydll = ctypes.windl.LoadLibrary('...')
myarray = N.zeros((3,13),dtype=N.double)
c_myarray = c_ndarray(myarray,dtype=N.double,ndim=2)
私はまた、コードを強化しているし、パスとファイルがアクセスなっていることに気づきました。パスを何か正しくないもの(またはファイル名など)に変更すると、チェーンの初期段階で別のエラーが発生します。これはどういうわけか.dll自体に関係しています。しかし、事実上すべての質問は、(明らかに)同じエラーが発生し、実際の.dllとは関係ありません。彼らはctypesを使って.dllをインポートする方法を切り替えるだけで、魔法の解決策を得ることができます。
だから、もう一度、私は窓のアナコンダは、(明らかに)Windowsコンピュータ上でCygwinのディレクトリにpycharm上(のpython 3.5)をインストールし使用しています。
cmake_minimum_required(VERSION 3.6)
project(extension_test_c)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -ansi -pedantic -Wall -pedantic -std=c++0x")
set(SOURCE_FILES extension_test_c.cpp extension_test_c.h ndarray.h)
add_library(extension_test_c SHARED ${SOURCE_FILES})
私は私のextension_test_c.cpp
でコンパイルしたコードは、番号をプリントアウトだけの機能である:C++コードは(上記のリンクでは指示に従って)ファイルCMakeListsで次の設定でClionでのgccを使用してコンパイルされていますストライド配列は2dのnumpyのndarrayを持ち(これはリンクのコードに関係します)、ヘッダーのコードはさらに簡単です。しかし、私はstd
行をコメントアウトしています。これは、ライブラリが他のライブラリにアクセスするかどうかに関する以前の質問の1つで、ctypesのインポートが失敗する可能性があるためです。
extension_test_c.cpp
#include "extension_test_c.h"
//#include <iostream>
#include "ndarray.h"
extern "C" {
int hello(numpyArray<double> array) {
Ndarray<double,2> a(array);
//std::cout << "shape 0: " << array.shape[0] << "; shape 1: " <<
// array.shape[1] << "; stride 0: " << array.strides[0]
// << "; strides 1: " << array.strides[1] << std::endl;
return 1;
}
}
とヘッダファイル:
#ifndef EXTENSION_TEST_C_LIBRARY_H
#define EXTENSION_TEST_C_LIBRARY_H
#include "ndarray.h"
extern "C" {
int hello(numpyArray<double> array);
}
#endif
ndarray.h
は、上記のウェブサイト上のリンクで見つけることができます。
私は何が間違っているのか分かりません。完全にアイデアがない。
Traceback (most recent call last):
File "C:/cygwin64/home/chris/CygwinMachineLearning/Assignment 1/DecisionTree/extension_test_python/wrapper.py", line 9, in <module>
mydll = load_library('cygextension_test_c.dll',r'C:\cygwin64\home\chris\CygwinMachineLearning\Assignment 1\DecisionTree\extension_test_c\cmake-build-debug');
File "C:\Anaconda3\envs\tensorflow\lib\site-packages\numpy\ctypeslib.py", line 150, in load_library
return ctypes.cdll[libpath]
File "C:\Anaconda3\envs\tensorflow\lib\ctypes\__init__.py", line 422, in __getitem__
return getattr(self, name)
File "C:\Anaconda3\envs\tensorflow\lib\ctypes\__init__.py", line 417, in __getattr__
dll = self._dlltype(name)
File "C:\Anaconda3\envs\tensorflow\lib\ctypes\__init__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
ctypes.CDLL(...)
のエラー:ここload_library
のエラーです
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3.2\helpers\pydev\pydevd.py", line 1596, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3.2\helpers\pydev\pydevd.py", line 974, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/cygwin64/home/chris/CygwinMachineLearning/Assignment 1/DecisionTree/extension_test_python/wrapper.py", line 9, in <module>
mydll = ctypes.CDLL('cygextension_test_c.dll',r'C:\cygwin64\home\chris\CygwinMachineLearning\Assignment 1\DecisionTree\extension_test_c\cmake-build-debug');
File "C:\Anaconda3\envs\tensorflow\lib\ctypes\__init__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
はまた、WinDLL
のために、それは同じです。cdll.LoadLibrary
バージョンについては
、それは別のトレースとほとんど同じ(まったく同じ最終エラー)です:ctypes.CDLLについては
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3.2\helpers\pydev\pydevd.py", line 1596, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3.2\helpers\pydev\pydevd.py", line 974, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/cygwin64/home/chris/CygwinMachineLearning/Assignment 1/DecisionTree/extension_test_python/wrapper.py", line 9, in <module>
mydll = ctypes.cdll.LoadLibrary(r'C:\cygwin64\home\chris\CygwinMachineLearning\Assignment 1\DecisionTree\extension_test_c\cmake-build-debug');
File "C:\Anaconda3\envs\tensorflow\lib\ctypes\__init__.py", line 425, in LoadLibrary
return self._dlltype(name)
File "C:\Anaconda3\envs\tensorflow\lib\ctypes\__init__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
あなたが取得しているエラーは何ですか? – griffin2000
@ griffin2000ああ、私のbの1秒 – bordeo