Cython, how to include 'external' modules and compile a single library?
Asked Answered
H

0

7

I have created a plugin for a software, this plugin is written in Python and I wish to distribute it in the form of a shared library (.so) for Mac OS (only). In my code I have a number of imports to packages that may not be installed in the 'target' Macs and I want to avoid having the user to download those packages as they many not have pip on their Mac and so on...

The simplest solution would be to 'build' a shared library with all the dependencies/modules to ensure that the user just downloads it and activates the plugin in the software and everything automatically works.

Is that possible?

I have been doing a lot of searching and reading on the web, I've look at pyInstaller, but I don' want to create a stand-alone executable but a single shared library with imports from packages such as Crypto, zerconf, twisted, etc.

If not what will be the alternatives?

I have tried Cython but I only get my plugin code compiled into a library so when I try to use it in a computer without the necessary packages I get an import error.

Is there a way to 'tell' Cython to compile all the dependencies of the code into a single shared library?

As I mentioned above pyInstaller could work for a stand-alone executable but in my case it needs to be a shared library...

Many thanks!

Hibernia answered 9/2, 2017 at 23:15 Comment(4)
Possible duplicate of Compiling required external modules with cythonAgue
I know the question I've marked as a duplicate has an unsatisfactory answer, but Cython isn't designed for this and so it doesn't workAgue
Thanks @Ague - I had a look at the post which is about creating an executable and for that pyInstaller could do the trick but I must be provide a shared library...Hibernia
One thing you try is providing all the dependencies in a zip file. Python can happily import from zip files docs.python.org/3/library/zipimport.html. I couldn't tell you exactly how to do that though.Ague

© 2022 - 2024 — McMap. All rights reserved.