如何将python包的data_files安装到主目录中
这是我的setup.py
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 但是,它不会在?/ .shipane_sdk下安装config / scheduler-example.ini 点子文件说:
你知道如何从sdist安装吗? 解决方法
这个问题有多种解决方案,包装工具的不一致性非常令人困惑.前段时间我发现以下解决方法最适合我使用sdist(注意它不适用于轮子!):
>而不是使用data_files,使用MANIFEST.in将文件附加到您的包中,在您的情况下,它可能如下所示: include config/scheduler-example.ini >使用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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |