Python package setup script install binary executable

一笑奈何 提交于 2019-12-05 15:41:10

I just ran into this issue myself. My solution was three-fold.

  1. I added the program, e.g. awesometool, to my package structure so I could add it via the package_data keyword: package_data={'awesomepkg': ['awesometool']}. This causes it to actually be copied into the same folder as the main init.py during installation.

  2. I made a python script similar to your step 2. However, instead of the relative path, I first import awesomepkg and use awesomepkg.__path__ to get the absolute path to the installation folder for the package. This would look like:

    import awesomepkg
    import subprocess as sp
    import sys
    
    path = awesomepkg.__path__[0]
    command = path + "/awesometool"
    sp.call([command] + sys.argv)
    

    I also used subprocess instead of system, but the result should be the same.

  3. I added this script to the scripts keyword of setup()

From within a package can use

import os
command = os.path.join(os.path.dirname(__file__), "awesometool")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!