PyStanプロジェクトの モジュールで、具体的にはpystan.model
モジュールに関連するコードが見つかりました。これは本質的に必要なものです。私は後世のためにここにコード断片を入れます。以下ではCython拡張も扱いますが、必要がない場合はCython依存関係を簡単に削除することができます。
from distutils.core import Extension
import Cython
from Cython.Build.Inline import _get_build_extension
from Cython.Build.Dependencies import cythonize
# you can add include_dirs= and extra_compile_args= here
extension = Extension(name='mymodule', language='c++', sources=[srcfile])
build_extension = _get_build_extension()
build_extension.extensions = cythonize([extension],
include_path=[],
quiet=False)
build_extension.build_temp = os.path.dirname(srcfile)
build_extension.build_lib = build_dir # where you want the output
build_extension.run()
はコンパイルしたら、パスにそれを入れて(またはsys.path
へのパスを追加)とimportlib.import_module()
を呼び出すことにより、モジュールをロードすることができます。
出典
2017-08-29 09:05:17
cfh