Understanding .pth files

J

Josh English

I am developing a library for Python 2.7. I'm on Windows XP. I am also learning the "proper" way to do this (per PyPi) but not in a linear fashion: I've built a prototype for the library, created my setup script, and run theinstall to make sure I had that bit working properly.

Now I'm continuing to develop the library alongside my examples and applications that use this library.

The source is at c:\Dev\XmlDB.
The installed package in in c:\Python27\lib\site-packages\xmldb\

According to the docs, I should be able to put a file in the site-packages directory called xmldb.pth pointing anywhere else on my drive to include the package. I'd like to use this to direct Python to include the version in the dev folder and not the site-packages folder.

(Otherwise I have my dev folder, but end up doing actual library development in the site-packages folder)

So my C:\Python27\lib\site-packages\xmldb.pth file has one line:

c:\dev\XmlDB\xmldb

(I've tried the slashes the other way, too, but it doesn't seem to work).

Is the only solution to delete the installed library and add the dev folderto my site.py file?

Josh
 
I

Ian Kelly

According to the docs, I should be able to put a file in the site-packages directory called xmldb.pth pointing anywhere else on my drive to include the package. I'd like to use this to direct Python to include the version in the dev folder and not the site-packages folder.

The name of the .pth file is not important. Python uses it to add
locations to sys.path; it doesn't care what packages might be
contained at those locations.
So my C:\Python27\lib\site-packages\xmldb.pth file has one line:

c:\dev\XmlDB\xmldb

The final xmldb is the actual package, yes? The directory in the .pth
file should be one inside which Python can find packages, not a
package itself. So the file should have just "c:\dev\XmlDB". Then
when you do "import xmldb", Python will look inside the
"c:\dev\XmlDB", find the xmldb package, and import it.
(I've tried the slashes the other way, too, but it doesn't seem to work).

Is the only solution to delete the installed library and add the dev folder to my site.py file?

The preferred solution here is to use virtualenv to set up your
development environment without having to modify the installed version
in the system site-packages at all.

HTH,
Ian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top