- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这是我的 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
pip 文档说:
setuptools allows absolute “data_files” paths, and pip honors them as absolute, when installing from sdist. This is not true when installing from wheel distributions. Wheels don’t support absolute paths, and they end up being installed relative to “site-packages”. For discussion see wheel Issue #92.
你知道如何从 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”是包含我的数据文件的包中的子目录,它们应该被安装到类似于/etc/APP_NAME 的 CONFIG_PATH 中
关于python - 如何将python包的data_files安装到主目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41328318/
运行 pip install 似乎在 /usr/local 中创建了 data_files 中指定的目录结构和文件 但是,如果我运行: import sys sys.prefix 我得到字符串 /us
我使用 pip 和 setuptools 来安装一个包。我希望 pip 将一些资源文件复制到 /etc/my_package。 我的 setup.py 看起来像这样: setup( ...
我是 distutils 的新手。我正在尝试在包中包含一些数据文件。这是我的代码。。 from distutils.core import setup setup(name='Scrapper',
对于使用“setup.py”构建安装包的开发人员来说,这应该是一个非常常见的问题,之前应该被问过,但我在任何地方都找不到合适的答案。 在 setup.py 中 from distutils.core
我正在尝试创建一个 Python 包,并且我的目录结构如下: mypkg/ ├── __init__.py ├── module1 │ ├── x.py │ ├── y.py │ └──
似乎非python资源包含在python分发包中的4种方式之一: Manifest.in 文件(我不确定何时优先于 package_data 或 data_files) package_data in
使用 setup.py(与 pip 兼容)传送 data_files 的跨平台方式是什么? 根据官方文档,需要这样写: setup(..., data_files=[('bitmaps', [
设置的 data_files 参数采用以下格式输入: setup(... data_files = [(target_directory, [list of files to be put t
我正在尝试将 data_file 添加到 setup.py 项目中。我可以使用 /tmp/ 目录中的文件,但不能使用脚本的当前目录中的文件: from setuptools import setup,
我有一个 Python 3 项目。 MKC ├── latex │ ├── macros.tex │ └── main.tex ├── mkc │ ├── cache.py │ ├──
我有一个带有 setup.py 的 Python 应用程序脚本,可以通过 Pip 或 setuptools 安装。但是,我发现这两种方法之间存在一些令人讨厌的差异,我想知道分发数据文件的正确方法。 i
我正在尝试为我的 CLI 工具提供一个用 Python 编写的 bash 完成脚本。根据Python Packaging Authority , data_files在 setup.py 中正是我需要
我试图将网络 Assets 与我试图打包的网络应用程序一起分发,但我失败得很惨。我不明白为什么我在运行 bdist、sdist 或 install 时有不同的安装文件或包列表。 项目布局 该项目在 A
我是一名优秀的程序员,十分优秀!