473,842 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing files installed with distutils


This is silly. How do I access data files I've installed with distutils? In a
portable, generic way, I want to find out what is the following path on most
systems:

/usr/local/lib/python2.4/lib/site-packages/foo/bar.txt

How do I figure out the rest, if I know foo/bar.txt? sys.prefix doesn't get me
far.

I've googled, and looked in the python reference. I must be blind if the
distutils section[1] covers this.
Cheers,

Frans

1.
http://www.python.org/doc/current/dist/dist.html
Jul 18 '05 #1
7 2308

Frans Englich wrote:
This is silly. How do I access data files I've installed with distutils? In a portable, generic way, I want to find out what is the following path on most systems:

/usr/local/lib/python2.4/lib/site-packages/foo/bar.txt
Most systems? A tad *nix-centric, yes/no?

How do I figure out the rest, if I know foo/bar.txt? sys.prefix doesn't get me far.


This hint may be useful:
import sys
sys.modules['readline'].__file__

'c:\\Python24\\ lib\\site-packages\\readl ine\\__init__.p yc'

but it may not work if the caller does "from yourmodule import ....."
or "import yourmodule as ym". Over to you.

Jul 18 '05 #2
Frans Englich wrote:
This is silly. How do I access data files I've installed with distutils? In a
portable, generic way, I want to find out what is the following path on most
systems:

/usr/local/lib/python2.4/lib/site-packages/foo/bar.txt


Assuming your module is also in site-packages/foo, I would use:

import os
filename = os.path.join(os .path.dirname(_ _file__), 'bar.txt')
Jul 18 '05 #3
I was wondering how to do this too. I'm trying to write a distutils
setup.py script that has some data I'd like to include. From the
distutils docs I get

data_files specifies a sequence of (directory, files) pairs in the
following way:

setup(...
data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
('config', ['cfg/data.cfg']),
('/etc/init.d', ['init-script'])]
)

I can use sys.prefix to find the top level where python is installed,
but this doesn't tell me specifically where site-packages is. On my
Linux box it is in

{sys.prefix}/lib/python2.3/site-packages

but on Windows, it's in

{sys.prefix}/Lib/site-packages.

Do I need to use sys.platform (along with sys.version) to check what
type of machine I'm on, or is there some better method to get the
location of site-packages?

Thanks.

Jul 18 '05 #4
ti************* *@nvl.army.mil wrote:
I was wondering how to do this too. I'm trying to write a distutils
setup.py script that has some data I'd like to include. From the
distutils docs I get

data_files specifies a sequence of (directory, files) pairs in the
following way:

setup(...
data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
('config', ['cfg/data.cfg']),
('/etc/init.d', ['init-script'])]
)

I can use sys.prefix to find the top level where python is installed,
but this doesn't tell me specifically where site-packages is. On my
Linux box it is in

{sys.prefix}/lib/python2.3/site-packages

but on Windows, it's in

{sys.prefix}/Lib/site-packages.

Do I need to use sys.platform (along with sys.version) to check what
type of machine I'm on, or is there some better method to get the
location of site-packages?

This is one of the areas where distutils could probably do with some
improvement. I don;t know whether it's on any developers priority list,
though.

regards
Steve

Jul 18 '05 #5
Steve Holden <st***@holdenwe b.com> writes:
ti************* *@nvl.army.mil wrote:
I was wondering how to do this too. I'm trying to write a distutils
setup.py script that has some data I'd like to include. From the
distutils docs I get
data_files specifies a sequence of (directory, files) pairs in the
following way:
setup(...
data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
('config', ['cfg/data.cfg']),
('/etc/init.d', ['init-script'])]
)
I can use sys.prefix to find the top level where python is installed,
but this doesn't tell me specifically where site-packages is. On my
Linux box it is in
{sys.prefix}/lib/python2.3/site-packages
but on Windows, it's in
{sys.prefix}/Lib/site-packages.
Do I need to use sys.platform (along with sys.version) to check what
type of machine I'm on, or is there some better method to get the
location of site-packages?

This is one of the areas where distutils could probably do with some
improvement. I don;t know whether it's on any developers priority
list, though.


There are some functions in distutils.sysco nfig which may help.

Thomas
Jul 18 '05 #6
I ended up using the trick I found in the Disutils Cookbook.

http://www.python.org/moin/Distutils...lDataScattered

This works fine for me now, but I have another distutils question.

My package requires Pmw and another home grown package that has a
source dist and a Windows dist built with the bdist_wininst command.
Is there a way to include the tarballs and *.win32-py2.3.exe files to
install them if necessary?

What I have now is that I'm including these in my source dist for
Linux, but I don't know how to do some type of conditional install. I
tried adding the Pmw package in my setup.py, but the Pmw.def file
doesn't make it over. Only the *.py files are in the MANIFEST. I
suppose I could change my MANIFEST.in file, but it seems to me that
having "Pmw" in the packages list should be sufficient.

Does Python2.4 have more extensive distutils documentation? (I'm using
2.3.2 now.)

Thanks.

Jul 18 '05 #7

Frans Englich wrote:
This is silly. How do I access data files I've installed with distutils? In a portable, generic way, I want to find out what is the following path on most systems:

/usr/local/lib/python2.4/lib/site-packages/foo/bar.txt

How do I figure out the rest, if I know foo/bar.txt? sys.prefix doesn't get me far.

I've googled, and looked in the python reference. I must be blind if the distutils section[1] covers this.


It doesn't, because distutils doens't do this. The data_files option
to distutils is pretty limited, is buggy, and if you override the data
dir, distutils has absolutely no way to let the Python code know about
it. Once or twice I've thought about making a patch, but it's a
difficult problem since different parts of distutils need to
communicate to make it work, in a way distutils engine doesn't support.

Workarounds:

Probably the most straightforward way is to just assume the data files
are in the default place, but provide a way to override with an
environment variable. If the user overrides the data dir when
installing, then it's his or her responsibility to define the
environment variable declaring where the data is.

The second workaround is to inspect the distutils structure (that which
is returned by setup), find out where the data dir is, and create a
Python module that sets the data file location. I did this for a
certain package I wrote. I posted this example here in
comp.lang.pytho n a while back:

http://tinyurl.com/5qgsw
--
CARL BANKS

Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2062
by: Michael Ströder | last post by:
HI! Is it possible to probe for installed libs with DistUtils? I'd like to automatically search for optional libs and adjust C compiler switchers before starting the build of a the extension module. Ciao, Michael.
1
4080
by: Tristan Miller | last post by:
Greetings. I'm trying to install a Python program, rawdog, on a system running SuSE 9.0. I have Python 2.3 and the development package installed via apt4rpm, so distutils should be there. But for some reason Python thinks otherwise: port-3108:/tmp/rawdog-1.13 # python ./setup.py install Traceback (most recent call last): File "./setup.py", line 3, in ?
3
2121
by: Mike Meyer | last post by:
I've got a package that includes an extension that has a number of header files in the directory with the extension. They are specified as "depends = " in the Extension class. However, Distutils doesn't seem to do anything with them. If I do an sdist, the include files aren't added to the tarball. If I do a bdist_rpm, the source files get copied into the build directory and the build starts, but the header files aren't copied with the...
2
1374
by: Rajarshi Guha | last post by:
Hi, I've been trying to package a python project and I'm a little confused about how I distribute some PNG's that the program uses as icons. Using distutils I can set the data_files argument of setup() and get my data files located in, say, /usr/local/mydata. However when I write my code, it would seem that I have to hardcode the above path. But this would mean that while working on the code I would need to have it 'installed' on my...
2
2672
by: RickMuller | last post by:
I really appreciate the ease that the distutils make distributing Python modules. However, I have a question about using them to distribute non-Python (i.e. text) data files that support Python modules. Currently when I have data of this type, I parse it into python objects and make a python module from it. In other words, given a data file like % cat grocery_list.txt eggs spam
1
4072
by: akbar | last post by:
Hi, I am creating not-so-important opensource application written in python for Linux. I have two files python source in src directory, named blabla1.py and blabla2.py. There are byte compiled files too, named blabla1.pyc and blabla2.pyc. Should I distribute these files (pyc files) to users? If I don't distribute them, and user installed my application into /usr (not writable by normal user) then run it as normal user, off course, the...
0
944
by: Sam Peterson | last post by:
I've been googling for a while now and cannot find a good way to deal with this. I have a slightly messy python program I wrote that I've historically just run from the extracted source folder. I have pictures and sound files in this folder that this program uses. I've always just used the relative path names of these files in my program. Lately, I had the idea of cleaning up my program and packaging it with distutils, but I've been...
0
1051
by: Joe Riopel | last post by:
Hi, I am using Distutils to build and distribute some packages. I do write unit tests, but I am confused as to where to put them and how to run them prior to the package being installed (The modules being tested would not be in my sys.path). I would rather not put the test cases in the same files as the modules being tested, I want keep them in a sub directory of the module, or in a separate "test" directory. What are some of the...
0
9876
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9717
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10618
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10683
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10320
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7045
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5699
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3148
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.