对于使用“setup.py”构建安装包的开发人员来说,这应该是一个非常常见的问题,之前应该问过这个问题,但我在任何地方都找不到正确的答案。
在 setup.py
from distutils.core import setup
setup(
....,
....,
data_files=[('MyApp/CBV', ['myapp/data/CBV/training.cbv', 'myapp/data/CBV/test.cbv'])],
....,
....,
)
sudo python setup.py install 的结果
running install
running build
running build_py
running build_scripts
running install_lib
running install_scripts
changing mode of /usr/local/bin/MyApp_trainer to 755
changing mode of /usr/local/bin/MyApp_reference_updater to 755
changing mode of /usr/local/bin/MyApp_predictor to 755
changing mode of /usr/local/bin/reference_updater to 755
running install_data
creating /usr/local/MyApp/CBV
copying MyApp/data/CBV/training.cbv -> /usr/local/MyApp/CBV
copying MyApp/data/CBV/test.cbv -> /usr/local/MyApp/CBV
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/MyApp-0.1.0.egg-info
Writing /usr/local/lib/python2.7/dist-packages/MyApp-0.1.0.egg-info
使用上面的结果观察,“/usr/local”是“data_files”根目录。除了硬编码之外,是否有任何 Python 函数可以给我这个“data_files”根目录?