473,320 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Import, site packages, my modules, Windows vs. Linux

Hi folks,

Running Python 2.5 on both a Windows XP laptop, and an Ubuntu Linux
7.04 desktop.

I've gotten tired of maintaining multiple copies of my personal
modules that I use over and over. I have copies of these files in the
same directory as the main program I happen to be working on at the
time. I've also downloaded FANN, and want to use its Python
bindings. FANN does not seem to build automatically, like wxWidgets
did.

These two issues have led me to examine exactly how the import
statement works, how the PYTHONPATH environment variable is
constructed, and how to change it.

On Windows I found a solution that works, but which may be a kludge.
In the Python "site-packages" folder, I added a sub-folder called "my-
packages". Then I created a text file, "my-packages.pth", containing
the single line, "my-packages." Finally, I moved my common personal
modules into the my-packages folder and deleted all of my clumsy
duplicates. Import statements now work for all of my files on the
Windows box, great!

I then tried to use this same strategy in Linux, and saw that I don't
automatically have the privileges needed to alter the site-packages
folder. On my Windows box, my default account has Administrator
privileges. On Linux I can, of course, use sudo to modify the site-
packages folder. But the fact that I would have to use sudo has me
asking -- is there something inappropriate, or unsafe in my approach?

I want to know what is the *recommended* way to integrate my own
personal modules with Python. Thanks!
Jun 27 '08 #1
5 2436
John Ladasky <la*****@my-deja.comwrites:
I want to know what is the *recommended* way to integrate my own
personal modules with Python. Thanks!
You want the 'distutils' documentation
<URL:http://www.python.org/doc/lib/module-distutilsand the documents
that it references, which will lead you to write a 'setup.py' module
for your package.

Then, it's a matter of running 'python ./setup.py install' to install
your package on a particular system.

--
\ "I hope if dogs ever take over the world, and they chose a |
`\ king, they don't just go by size, because I bet there are some |
_o__) Chihuahuas with some good ideas." -- Jack Handey |
Ben Finney
Jun 27 '08 #2
On Jun 3, 6:52 pm, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
John Ladasky <lada...@my-deja.comwrites:
I want to know what is the *recommended* way to integrate my own
personal modules with Python. Thanks!

You want the 'distutils' documentation
<URL:http://www.python.org/doc/lib/module-distutilsand the documents
that it references, which will lead you to write a 'setup.py' module
for your package.

Many thanks, Ben, distutils was exactly what I needed. It was a
little strange to grasp the concept that I would be "distributing" my
module to myself -- but once I got over that mental hurdle, it worked
perfectly.
Jun 27 '08 #3
On Tue, 03 Jun 2008 17:57:07 -0700, John Ladasky wrote:
Hi folks,

Running Python 2.5 on both a Windows XP laptop, and an Ubuntu Linux
7.04 desktop.

I've gotten tired of maintaining multiple copies of my personal
modules that I use over and over. I have copies of these files in the
same directory as the main program I happen to be working on at the
time.
I just make some directory outside of the python source, say
/usr/local/lib/python. I then add that to my PYTHONPATH.
Now the permissions are not a problem, and the libs are
automatically available to any version of python on the system.

** Posted from http://www.teranews.com **
Jun 27 '08 #4

"John Ladasky" <la*****@my-deja.comwrote in message
news:49**********************************@m44g2000 hsc.googlegroups.com...
| On Windows I found a solution that works, but which may be a kludge.
| In the Python "site-packages" folder, I added a sub-folder called "my-
| packages". Then I created a text file, "my-packages.pth", containing
| the single line, "my-packages." Finally, I moved my common personal
| modules into the my-packages folder and deleted all of my clumsy
| duplicates. Import statements now work for all of my files on the
| Windows box, great!
|
| I then tried to use this same strategy in Linux, and saw that I don't
| automatically have the privileges needed to alter the site-packages
| folder. On my Windows box, my default account has Administrator
| privileges.

If you do the Windows install for all users, all users can add packages to
site-packages -- as long as adding the package directory comprises the
whole installation process and no registry fiddling is required.

Jun 27 '08 #5
John Ladasky <la*****@my-deja.comwrote in
news:49**********************************@m44g2000 hsc.googlegroups.
com:
Hi folks,

Running Python 2.5 on both a Windows XP laptop, and an Ubuntu
Linux 7.04 desktop.

I've gotten tired of maintaining multiple copies of my personal
modules that I use over and over. I have copies of these files
in the same directory as the main program I happen to be working
on at the time. I've also downloaded FANN, and want to use its
Python bindings. FANN does not seem to build automatically,
like wxWidgets did.

These two issues have led me to examine exactly how the import
statement works, how the PYTHONPATH environment variable is
constructed, and how to change it.

On Windows I found a solution that works, but which may be a
kludge. In the Python "site-packages" folder, I added a
sub-folder called "my- packages". Then I created a text file,
"my-packages.pth", containing the single line, "my-packages."
Finally, I moved my common personal modules into the my-packages
folder and deleted all of my clumsy duplicates. Import
statements now work for all of my files on the Windows box,
great!

I then tried to use this same strategy in Linux, and saw that I
don't automatically have the privileges needed to alter the
site-packages folder. On my Windows box, my default account has
Administrator privileges. On Linux I can, of course, use sudo
to modify the site- packages folder. But the fact that I would
have to use sudo has me asking -- is there something
inappropriate, or unsafe in my approach?

I want to know what is the *recommended* way to integrate my own
personal modules with Python. Thanks!
I can't speak about Linux, but on Windows, you really should move
your code out of the Python directory tree, I believe. When you
upgrade, you'll have to be sure to set it up the same way again,
and remember that your code resides there before you wipe out that
directory tree, etc.

Instead, just set up another directory containing your code and add
that to your PYTHONPATH environment variable string. That will be
unaffected by the Python version you're running, and will be
available for multiple versions, if you run more than one.

--
rzed
Jun 27 '08 #6

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

Similar topics

2
by: Markus Doering | last post by:
Hello, I just switched from 2.2 to Python 2.3. I am developing an XML/CGI interface to databases as a python package called "unitWrapper" containing several modules which ran fine under v2.2. ...
16
by: Manlio Perillo | last post by:
Hi. I'm a new user of Python but I have noted a little problem. Python is a very good language but it is evolving, in particular its library is evolving. This can be a problem when, ad example,...
5
by: Steve Holden | last post by:
This is even stranger: it makes it if I import the module a second time: import dbimp as dbimp import sys if __name__ == "__main__": dbimp.install() #k = sys.modules.keys() #k.sort() #for...
3
by: Olivier Noblanc ATOUSOFT | last post by:
Hello, When i want to import a .py fire from another subdirectory i make import inc/setupxml but that make me an error message.
1
by: Peter Saffrey | last post by:
I'm trying to write a python service, with an executable in /usr/local/bin, but modules that are kept in a sub-directory of /usr/lib/python/site-packages. Using apt-proxy as my template, I've...
17
by: mohan | last post by:
Hi Guys, I've been using the following IDE, "Pythonwin - Python IDE and GUI Framework for Windows. Copyright 1994-2001 Mark Hammond " With respect to my work, I had created my own modules...
0
by: jack139 | last post by:
I installed zope under windows and found a problem when import addition modules - iHotfix and itools. When place itools in python's library path, site-packages, import works fine. When place itools...
5
by: luca72 | last post by:
Hello i can't import cherrypy2 but i don't know why this is the sys path: '', '/home/pirataja/opo.net/python/lib/python2.5/site-packages/ setuptools-0.6c7-py2.5.egg',...
16
by: ssecorp | last post by:
Is there a way to view all the modules I have available for import from within Python? Like writing in the interpreter: import.modules Also, is there anything like Cpan for Python?
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.