where do my python files go in linux?
Carl Banks
pavlovevidence at gmail.com
Sat Jan 12 14:16:38 EST 2008
On Sat, 12 Jan 2008 12:02:20 +0100, Jorgen Bodde wrote:
> I am trying to make a debian package. I am following the tutorial by
> Horst Jens
> (http://showmedo.com/videos/video?
name=linuxJensMakingDeb&fromSeriesID=37)
> and it is very informative. However one thing my app has and his
> doesn't, is multiple python files which need to be executed. For example
>
> {dir}/app
> app.py
>
> app.py calls a lot of modules in {dir}/app. Horst says the python file
> goes in /usr/bin/app.py which is ok with me, but I have multiple python
> files, and I decided to use an app.sh script to call my python files. In
> the /usr/bin I do not see subdirs so I assume that is not really
> desirable.
>
> Question 1. Where do I put the bulk of python scripts in a normal linux
> environment?
> Question 2. Should I use *.pyc rather then *.py files to speed up
> executing as the user cannot write to /usr/bin or any other dir in the
> system and everytime my app runs it will recompile it
>
> Thanks for any advice or maybe a good tutorial how to set up files in a
> linux environment
On a Debian system:
I would put app.py in /usr/local/bin. I would create the directory
/usr/local/lib/app, and put all other *.py and *.pyc files there. At the
top of app.py, I'd add the following line so that I could import files
directly from /usr/local/lib/app:
sys.path.insert(0,'/usr/local/lib/app')
Alternatively, using your app.sh approach, I'd put app.sh in
/usr/local/bin/, and all *.py and *.pyc files in /usr/local/lib/app. I'd
invoke Python something like this:
PYTHONPATH=/usr/local/lib/app:$PYTHONPATH python -m app
(The -m switch searches the Python path for a module to run.)
If it's more of a library than an application (maybe there is a command
line script, but users could want to import the modules directly), then
I'd stick all the modules in /usr/local/lib/python2.x/site-packages, and
the command line scripts in /usr/local/bin.
Yes, install the *.pyc files. I recommend putting *.py files there as
well, so users can refer to it if there are any problems, but you don't
have to. The Python module compileall is your friend here.
Carl Banks
More information about the Python-list
mailing list