2016-12-26 67 views
3

這裏是我的setup.py如何Python包的data_files安裝到主目錄

setup(
    name='shipane_sdk', 

    version='1.0.0.a5', 

    # ... 

    data_files=[(os.path.join(os.path.expanduser('~'), '.shipane_sdk', 'config'), ['config/scheduler-example.ini'])], 

    # ... 
) 

包裝&上傳命令:

python setup.py sdist 
python setup.py bdist_wheel --universal 
twine upload dist/* 

安裝命令:

pip install shipane_sdk 

但是,它不會安裝config/scheduler-example.ini〜/ .shipane_sdk

畫中畫文件下稱:

setuptools的允許絕對的「data_files」路徑,和PIP榮譽它們作爲 絕對的,從sdist安裝時。從輪子分佈安裝 時,這不是真的。車輪不支持絕對路徑,並且它們最終被安裝爲相對於「站點包」。有關 的討論,請參閱第92期問題車輪。

你知道怎麼做從sdist安裝

回答

0

這個問題有多種解決方案,這些包裝工具的工作方式不一致,都令人困惑。前一段時間,我發現了以下解決方法爲我工作與sdist最好的(請注意,它不帶輪子工作!):

  1. 而不是使用data_files的,附加使用MANIFEST.in文件到您的包裹,而你的情況可能是這樣的:

    include config/scheduler-example.ini 
    
  2. 複製文件「手動」在setup.py使用這個片段選擇位置:

    if 'install' in sys.argv: 
        from pkg_resources import Requirement, resource_filename 
        import os 
        import shutil 
    
        # retrieve the temporary path where the package has been extracted to for installation 
        conf_path_temp = resource_filename(Requirement.parse(APP_NAME), "conf") 
    
        # if the config directory tree doesn't exist, create it 
        if not os.path.exists(CONFIG_PATH): 
         os.makedirs(CONFIG_PATH) 
    
        # copy every file from given location to the specified ``CONFIG_PATH`` 
        for file_name in os.listdir(conf_path_temp): 
         file_path_full = os.path.join(conf_path_temp, file_name) 
         if os.path.isfile(file_path_full): 
          shutil.copy(file_path_full, CONFIG_PATH) 
    

在我的情況下,「conf」是包含我的數據文件的包中的子目錄,它們應該被安裝到CONFIG_PATH中,類似於/ etc/APP_NAME

+0

謝謝。這已經通過使用--no-binary開關解決了。稍後我會添加一個替代答案。 – user1633272

相關問題