Search code examples
pythonc++python-3.xanacondaconda

Need help compiling C++ Python project from Github for Conda environment


I'd be really saved if someone could help me on this!

I've been working with an old open source C++ project from github that has not had an official update since Python 3.4: https://github.com/Mindwerks/plate-tectonics

Using a fresh install of Python 3.10.11 I've been able to compile this project in a PyCharm venv using the included setup.py file from this folder: https://github.com/Mindwerks/plate-tectonics/blob/master/pybindings/setup.py

When I compile this, I am able to manually copy+paste the resulting *.pyd file into Pycharm's venv\Lib\site-packages folder. This package runs exactly as it should.

However, for practical reasons, I want to switch to using a conda environment. I've created this environment (python 3.10.13, possibly Cython?) and followed the same steps that worked for PyCharm: open the environment in the conda terminal, run "python setup.py build" and copy the *.pyd file it compiles into the environment's \Lib\site-packages folder.

However, now if I try and run functions from the package, python immediately crashes.

I am completely stumped on what could be the problem and how to resolve it. I don't have much experience with C++ or compiling packages, and I don't get any error messages suggesting what I might be doing wrong. I am assuming conda environments have a different behavior from Pycharm venv's, but I have been unable to find any suggestion as to what I should be doing differently.

If anyone has experience with this and knows what I can do, you'd be a huge help!!!


Solution

  • It seems the problem was in the following chunk of code from the old setup.py file:

    # 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))
    

    Specifically, the last line, which needed to be changed to:

    # 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))