Howard
Howard

Reputation: 3848

How to build cython build_ext for linux on mac?

I built my cython modules to so file on macOS and it works fine. Is it possible to build so file for linux specific on macOS as well?

My current solution is to run a python container with necessary modules installed. Then mount current folder to the working directory in container, execute the compilation inside container. It works fine so far, but I'm looking for a easier solution which is to compile linux specific so files directly on macOS.

Upvotes: 1

Views: 1105

Answers (2)

Roy2012
Roy2012

Reputation: 12493

What you're trying to do is 'cross-compiling'. This post tries to answer the question of the best way to do cross-compiling from Mac to Linux, with links to some (outdated) tools. In short - it's not easy, and I wouldn't go that way unless there's a really compelling reason to do so.

There are two tools that claim to make this process (somewhat?) easier:

But again, I'm not sure it's worth the effort.

Upvotes: 1

Howard
Howard

Reputation: 3848

It seems that very few requirement like what I'm doing for this use case. Here post a solution what I'm doing right now and hope it could help some one who run into the same issue.

Generally, I run into a docker container with a volume mounted on my disk, the python code is placed there. Then I can compile my python files in container and I can also get my compiled .so files on my local file.

One command will do the trick.

docker run -it -v $(pwd):/dist python:3.8-buster bash -c "pip3 install Cython==0.29.17 && cythonize -3 -i [YOUR PYTHON CODE ROOT Folder]/*.py" 

Upvotes: 1

Related Questions