[英]Cython openMP in OSX... no build
我現在正在戰斗 3 天來設置我的 venv ......我需要 cython、openmp......我的 IDE 是 macOS 中的 PyCharm Prof......我已經嘗試了很多解決方案但沒有結果......
當我嘗試使用 PyCharm 構建時……構建結果是:
UserWarning: Unknown distribution option: 'cmd_class' warnings.warn(msg)
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
error: no commands supplied
所以,當我嘗試使用: python setup.py install build_ext --inplace
沒有再次構建......錯誤如下:
ld: warning: directory not found for option '-L/install/prefix/lib'
ld: warning: -L path '/usr/local/Cellar/llvm/9.0.1/lib/libomp.dylib' is not a directory
ld: warning: directory not found for option '-L/install/prefix/lib'
ld: warning: directory not found for option '-L/usr/local/Cellar/gcc/9/gcc/x86_64-apple-darwin19/9.3.0/include/omp.h'
ld: library not found for -lomp
clang-9: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/local/opt/llvm/bin/clang++' failed with exit status 1
我已經安裝: brew install llvm
brew install libomp
clang version 9.0.1
Target: x86_64-apple-darwin19.3.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
setup.py 是根據https://cython.readthedocs.io/en/latest/src/userguide/parallelism.html但我嘗試了很多不同的 mods ......我現在正在嘗試設置 3 天。 ..
最后...我知道編譯完成時有錯誤。 雖然如果我嘗試運行它......我有以下結果......也許它有幫助......
ImportError: dlopen(myfile.pyx, 2): Symbol not found: _omp_get_num_threads
Referenced from: myfile.pyx
Expected in: flat namespace
in myfile.pyx.cpython-36m-darwin.so
我在某處讀到過使用 openMP 無法在 OSX Cython-App 中實現,但我仍然相信有辦法......我的系統是 macOS Catalina 10.15.3 ......我需要你的幫助! !
最后我找到了解決方案......
pip install Cython setuptools
$ mdfind gcc | grep gcc
將整個 gcc 目錄放在項目的 venv 中。 (路徑: /My_Project/venv/gcc )
和setup.py應該如下......(路徑: /My_Project/package/setup.py )
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import os
os.environ["CC"]="../venv/gcc/9.3.0/bin/gcc-9"
os.environ["CXX"]="../venv/gcc/9.3.0/bin/gcc-9"
ext_modules = [Extension(
"filename",
["filename.pyx"],
language='c',
extra_compile_args=['-fopenmp',"-Os",],
extra_link_args=['-fopenmp', ],
)
]
setup(
name='filename',
cmd_class = {'build_ext': build_ext},
ext_modules= cythonize(ext_modules),
)
# distutils: extra_compile_args = -fopenmp
# distutils: extra_link_args = -fopenmp
$ python setup.py build_ext -i
import filename
filename.myCythonFunc()
以上給出了 OSX-10.15.3 macOS Catalina 的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.