Python setup.py call makefile don't include binaries

为君一笑 提交于 2019-12-01 03:52:45

问题


Some context: I have some C code that when compiled I can call in the terminal like this: ./my_excec -params It generates some files that I am using in python to generate charts, and other stuff.

I want to pack everything in a python library both the C code and the python code. The C code is not a python extension (prolly going to be in a future but right now is not).

I have a make file to compile the C code and I know I can call it from the setup.py like this: subprocess.call(['make', '-C', 'word2vec-src'])

What I want to be able to do is: pip install my_module That should call the makefile, compile the C so the user can call the binaries: my_excec -params and also be able to import the python code around it.

The problem I am having is when packaging the python package. I am using the data_files option in setup() like this:data_files=[('bin', ['bin/binary_file'])], This moves the files from bin to the installation folder (in a virtual env) and I can call them. But when packaging is also putting the compiled files in the tarball and when I call pip install my_module` is putting the compiled files from my computer.

Thanks.


回答1:


I was able to find a really easy solution.

As I said my main problem was that I was packaging the compiled files. To exclude those files form the tarball/zip just had to put this on MANIFEST.in: prune bin.

Then just need to call the makefile from setup.py:

directory = 'bin'
if not os.path.exists(directory):
    os.makedirs(directory)

subprocess.call(['make', '-C', 'src'])

With that when someone does pip install whatever is going to call the make file and put the binaries on bin (have to specify this on the make file).

Then just need to say the setup to copy those files:

setup(
...
data_files=[('bin', ['bin/binaries'])],
)

Done! Hopefuly someone find this usefull :)



来源:https://stackoverflow.com/questions/18436061/python-setup-py-call-makefile-dont-include-binaries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!