如果有人能帮助我,我就真的得救了!
我一直在使用 github 上的一个旧的开源 C++ 项目,该项目自 Python 3.4 以来一直没有官方更新:https://github.com/Mindwerks/plate-tectonics
使用全新安装的 Python 3.10.11,我已经能够使用此文件夹中包含的 setup.py 文件在 PyCharm venv 中编译此项目:https://github.com/Mindwerks/plate-tectonics/blob /master/pybindings/setup.py
当我编译它时,我可以手动将生成的 *.pyd 文件复制+粘贴到 Pycharm 的 venv\Lib\site-packages 文件夹中。这个包完全按照它应该的方式运行。
但是,出于实际原因,我想切换到使用 conda 环境。我创建了这个环境(python 3.10.13,可能是 Cython?),并遵循与 PyCharm 相同的步骤:在 conda 终端中打开环境,运行“python setup.py build”并复制 *.pyd 文件编译到环境的 \Lib\site-packages 文件夹中。
但是,现在如果我尝试运行包中的函数,Python 会立即崩溃。
我完全不知道可能是什么问题以及如何解决它。我在 C++ 或编译包方面没有太多经验,并且我没有收到任何错误消息表明我可能做错了什么。我假设 conda 环境与 Pycharm venv 的行为不同,但我找不到任何关于我应该做什么不同的建议。
如果有人有这方面的经验并且知道我能做什么,你将会提供巨大的帮助!!!
问题似乎出在旧
setup.py
文件中的以下代码块中:
# We add all .cpp files to the sources
sources = [ 'platec_src/platecmodule.cpp']
for f in os.listdir(cpp_src_dir):
if f.endswith(".cpp"):
sources.append("%s/%s" % (cpp_src_dir, f))
具体来说,最后一行需要更改为:
# We add all .cpp files to the sources
sources = [ 'platec_src/platecmodule.cpp']
for f in os.listdir(cpp_src_dir):
if f.endswith(".cpp"):
sources.append(os.path.join(cpp_src_dir, f))