deepspring
April 10th, 2009, 09:13 AM
Hi Guys,
I've got a strange problem with Python 2.6 distutils.core.setup ignoring sys.prefix and sys.exec_prefix when installing applications.
Lets say I have application to setup, and the module includes extra files needed to be run. I create a setup.py file like so:
import sys, os
from distutils.core import setup
# define search paths to look for data files in constants.py
const_file = open(os.path.join('MyApp', "constants.py"), 'w')
const_file.write("MYAPP_UI = '%s/share/MyApp/'\n" % sys.prefix)
const_file.write("USER_DATA = '~/.MyApp/'\n")
const_file.close()
# Read in myapp.desktop.in template file
infile = open(os.path.join('data', 'MyApp', 'MyApp.desktop.in'))
# Replace all @PREFIX@ with prefix defined by sys.prefix
data = infile.read().replace('@PREFIX@', sys.prefix)
infile.close()
# Create the updated myapp.desktop file
outfile = open(os.path.join('data', 'MyApp', 'MyApp.desktop'), 'w')
outfile.write(data)
outfile.close()
setup(name = "MyApp",
version = "0.0.1",
description = "Ground breaking, earth shatteringly important application",
author = "deepspring",
author_email = "me@nospam.org",
url = "http://somesite.com/MyApp",
packages = ['MyApp'],
scripts = ['myapp'],
license = "GNU GPL Version 3",
data_files=[('data/MyApp', ['share/MyApp/MyApp.glade']),
('data/MyApp', ['share/MyApp/icon.svg']),
('data/MyApp', ['share/applications/MyApp.desktop'])]
)
Under Ubuntu 8.10 (w/ Python 2.5), distutils.core.setup obeys the prefixes set by sys.prefix (set to '/usr') and sys.exec_prefix (set to '/usr'), and the application would be installed like so:
The script "myapp" gets installed to sys.prefix + "/bin/"
The package "MyApp" (module) gets installed to sys.prefix + "/lib/python2.5/site-packages/"
The data files "MyApp.glade" and "icon.svg" get installed to sys.prefix + "/share/MyApp/"
The data file "MyApp.desktop" gets installed to sys.prefix + "/share/applications"
The application works perfectly.
But, when I install the same application under Ubuntu 9.04 (w/ Python 2.6), sys.prefix (set to '/usr') and sys.exec_prefix(set to '/usr') are ignored and the application is setup with the prefix "/usr/local" like so:
The script "myapp" gets installed to "/usr/local/bin/"
The package "MyApp" (module) gets installed "/usr/local/lib/python2.6/dist-packages/"
The data files "MyApp.glade" and "icon.svg" get installed to "/usr/local/share/MyApp/"
The data file "MyApp.desktop" gets installed to "/usr/local/share/applications"
The application breaks.
If I force a prefix of "/usr/local" in Python2.6, the package gets installed to "/usr/local/lib/python2.6/site-packages" which is ignored by Python.
Is there any sane way to correct this problem so the application remains backwards compatible? as not eveyone uses the latest version of Ubuntu.
Edit: here is the is the output of sys.path on Ubuntu 9.04 (Python 2.6):
['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/var/lib/python-support/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/var/lib/python-support/python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist-packages']
I've got a strange problem with Python 2.6 distutils.core.setup ignoring sys.prefix and sys.exec_prefix when installing applications.
Lets say I have application to setup, and the module includes extra files needed to be run. I create a setup.py file like so:
import sys, os
from distutils.core import setup
# define search paths to look for data files in constants.py
const_file = open(os.path.join('MyApp', "constants.py"), 'w')
const_file.write("MYAPP_UI = '%s/share/MyApp/'\n" % sys.prefix)
const_file.write("USER_DATA = '~/.MyApp/'\n")
const_file.close()
# Read in myapp.desktop.in template file
infile = open(os.path.join('data', 'MyApp', 'MyApp.desktop.in'))
# Replace all @PREFIX@ with prefix defined by sys.prefix
data = infile.read().replace('@PREFIX@', sys.prefix)
infile.close()
# Create the updated myapp.desktop file
outfile = open(os.path.join('data', 'MyApp', 'MyApp.desktop'), 'w')
outfile.write(data)
outfile.close()
setup(name = "MyApp",
version = "0.0.1",
description = "Ground breaking, earth shatteringly important application",
author = "deepspring",
author_email = "me@nospam.org",
url = "http://somesite.com/MyApp",
packages = ['MyApp'],
scripts = ['myapp'],
license = "GNU GPL Version 3",
data_files=[('data/MyApp', ['share/MyApp/MyApp.glade']),
('data/MyApp', ['share/MyApp/icon.svg']),
('data/MyApp', ['share/applications/MyApp.desktop'])]
)
Under Ubuntu 8.10 (w/ Python 2.5), distutils.core.setup obeys the prefixes set by sys.prefix (set to '/usr') and sys.exec_prefix (set to '/usr'), and the application would be installed like so:
The script "myapp" gets installed to sys.prefix + "/bin/"
The package "MyApp" (module) gets installed to sys.prefix + "/lib/python2.5/site-packages/"
The data files "MyApp.glade" and "icon.svg" get installed to sys.prefix + "/share/MyApp/"
The data file "MyApp.desktop" gets installed to sys.prefix + "/share/applications"
The application works perfectly.
But, when I install the same application under Ubuntu 9.04 (w/ Python 2.6), sys.prefix (set to '/usr') and sys.exec_prefix(set to '/usr') are ignored and the application is setup with the prefix "/usr/local" like so:
The script "myapp" gets installed to "/usr/local/bin/"
The package "MyApp" (module) gets installed "/usr/local/lib/python2.6/dist-packages/"
The data files "MyApp.glade" and "icon.svg" get installed to "/usr/local/share/MyApp/"
The data file "MyApp.desktop" gets installed to "/usr/local/share/applications"
The application breaks.
If I force a prefix of "/usr/local" in Python2.6, the package gets installed to "/usr/local/lib/python2.6/site-packages" which is ignored by Python.
Is there any sane way to correct this problem so the application remains backwards compatible? as not eveyone uses the latest version of Ubuntu.
Edit: here is the is the output of sys.path on Ubuntu 9.04 (Python 2.6):
['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/var/lib/python-support/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/var/lib/python-support/python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist-packages']