我通过在这个文件夹中运行 python setup.py bdist_egg
命令创建了一个 Python egg 文件:
SensorDisplay/
--- sensor_display/
----- __init__.py
----- can.py
----- sensor_display.py
----- data/
--------- sensor_param.txt
--- setup.py
在文件setup.py
中,我有以下内容:
package_data = {'' : ['*.txt']},
scripts = ['sensor_display/sensor_display.py','sensor_display/can.py']
并且在文件 sensor_display.py
中:
PARAM_FILE = "data/sensor_display.txt"
param_file = pkg_resources.resource_filename("sensor_display", PARAM_FILE)
f = open(param_file,"r")
我在文件夹SensorDisplay\dist\
下找到了名为SensorDisplay-0.1-py2.7.egg
的文件。但是当我使用easy_install安装这个egg文件并运行文件C:\Python27\Scripts\sensor_display.py
时,我遇到了以下错误:
IOError: [Errno 2] No such file or directory: 'C:\\Python27\\lib\\site-packages\
\sensordisplay-0.1-py2.7.egg\\EGG-INFO\\scripts\\data\\sensor_param.txt'
似乎函数
resource_filename
没有提取蛋文件,因为返回的文件名将蛋文件视为目录,而它不是。