3

I created a python egg by running python setup.py bdist_egg from this folder:

SensorDisplay/
--- sensor_display/
----- __init__.py
----- can.py
----- sensor_display.py
----- data/
--------- sensor_param.txt
--- setup.py

in file setup.py, I have:

 package_data = {'' : ['*.txt']},
 scripts = ['sensor_display/sensor_display.py','sensor_display/can.py']

and in file sensor_display.py:

PARAM_FILE = "data/sensor_display.txt"
param_file = pkg_resources.resource_filename("sensor_display", PARAM_FILE)
f = open(param_file,"r")

I obtain then the egg file SensorDisplay-0.1-py2.7.egg in folder SensorDisplay\dist\. However, when I install the egg with easy_install and run the file C:\Python27\Scripts\sensor_display.py, I obtain the following error:

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'

It seems function resource_filename doesn't extract the egg-file because the filename returned considers the egg-file as a directory which it is not.

sarah vb
  • 149
  • 2
  • 12

2 Answers2

3

I found the problem, I replaced

PARAM_FILE = "data/sensor_display.txt"
param_file = pkg_resources.resource_filename("sensor_display", PARAM_FILE)

with

PARAM_FILE = "sensor_display/data/sensor_display.txt"
param_file = pkg_resources.resource_filename(pkg_resources.Requirement.parse("SensorDisplay"), PARAM_FILE)

see also pkg_resources.resource_filename is not extracting files

Community
  • 1
  • 1
sarah vb
  • 149
  • 2
  • 12
1

egg file is a zip archive. You can look at the contents using unzip command.

noorul
  • 1,283
  • 1
  • 8
  • 18