.pyc files not being created

1,521 views
Skip to first unread message

blis102

unread,
Jul 14, 2008, 6:29:15 PM7/14/08
to Django users
Hey all,

On my Ubuntu server with Apache2 + mod_python, I cant seem to get
the .py files to compile like they should (I see no .pyc files in my
"src" folder like I do locally). I believe I have proper permissions
set (775), but am by no means an expert in this matter. What would
cause .pyc files to not compile other than the file permissions. Also
what is the recommended permissions settings for source folders/files,
and media folders/files?

Thanks a bunch

EAMiller

unread,
Jul 14, 2008, 7:07:08 PM7/14/08
to Django users
Hello...
What error message are you seeing? Or, what is failing as a result of
this problem? Also, you've set all files to 775? Or specific ones?

Dana

unread,
Jul 14, 2008, 7:09:03 PM7/14/08
to Django users
Hi EAMiller,

Im not seeing errors, Its just not compiling the python files (which
it should be).

I tried a few combinations, but I believe all I need to do is set the
chmod to 775 for the source folder (in this case "src")?

Thanks,
Dana

Malcolm Tredinnick

unread,
Jul 14, 2008, 7:12:24 PM7/14/08
to django...@googlegroups.com

On Mon, 2008-07-14 at 16:09 -0700, Dana wrote:
> Hi EAMiller,
>
> Im not seeing errors, Its just not compiling the python files (which
> it should be).
>
> I tried a few combinations, but I believe all I need to do is set the
> chmod to 775 for the source folder (in this case "src")?

Permissions like "775" mean nothing on their own. Permissions are
relative to the user and group involved. When you're running things from
mod_python, the important question would be whether the webserver has
write permission to those directories in order to write the .pyc files.

However, that's only "important" in the sense that it's not really a
good idea to allow. Letting your web server only *read* from executable
file directories is really important for security reasons. For this
reason, Python ships with the 'compileall' module (which can also be
executed as a script from the command line). You run "compileall.py ..."
as somebody who does have permission to write the directory that holds
the executable files and compile them to .pyc files. Then your webserver
sees the benefit without opening up unneeded permissions. Read the
docstring at the top of the "compileall.py" file for instructions on how
to use it.

Regards,
Malcolm


Dana

unread,
Jul 14, 2008, 8:42:30 PM7/14/08
to Django users
Hi Malcom,

Thanks a lot for the detailed response.

Sorry if these are basic questions but, what user would my web server
be run under (Apache2)? Would it be my username, root, or something
else like "apache"?

Would I have to run compileall.py every time I change a source file
(it seems like I would have to)?

I couldn't get compileall.py to work on the command line... Tried
'compileall.py' and 'compileall'. What am I doing wrong?

Thanks a ton,
Dana


On Jul 14, 4:12 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:

Joshua Jonah

unread,
Jul 14, 2008, 10:59:39 PM7/14/08
to django...@googlegroups.com
Didn't know that, will remember, thanx

Evert

unread,
Jul 15, 2008, 1:17:42 AM7/15/08
to Django users
> Hi Malcom,
>
> Thanks a lot for the detailed response.
>
> Sorry if these are basic questions but, what user would my web server
> be run under (Apache2)? Would it be my username, root, or something
> else like "apache"?

Probably nobody or www. A simple way to try and find out is using 'ps
axu | grep httpd'; the first column should give you the user (I don't
have access to an Ubuntu distribution, otherwise I could tell you
straight away; but Google or the Ubuntu website can also tell you I
guess).
Of course, you can always use root to compile .py files, that'll
"bypass" permissions; but see Malcom's comments.

> Would I have to run compileall.py every time I change a source file
> (it seems like I would have to)?

Possibly, but you'd only want to serve files through apache +
mod_python that aren't going to change much (eg, Django, although that
should just live in the Python site-packages dir); every change also
involves restarting apache for example. Better to sort everything out
using the dev-server, then copy files and run compileall. You'd then
only run compileall for (major) upgrades; not for every single source
file change.

> I couldn't get compileall.py to work on the command line... Tried
> 'compileall.py' and 'compileall'. What am I doing wrong?

compileall comes with the Python source distribution, which is
probably hidden away in a tar file on your server, if anywhere at all.
If your database is working, try a 'locate compileall.py'
Otherwise, if it's not there, grep a Python source distribution
(preferably one that agrees with your Python version) and use the one
included with that.

Graham Dumpleton

unread,
Jul 15, 2008, 9:27:24 AM7/15/08
to Django users


On Jul 15, 8:29 am, blis102 <Blis...@gmail.com> wrote:
> Hey all,
>
> On my Ubuntu server with Apache2 +mod_python, I cant seem to get
> the .py files to compile like they should (I see no .pyc files in my
> "src" folder like I do locally). I believe I have proper permissions
> set (775), but am by no means an expert in this matter. What would
> cause .pyc files to not compile other than the file permissions. Also
> what is the recommended permissions settings for source folders/files,
> and media folders/files?

Because Apache/mod_python processes are persistent, and py file
loading only happens first time it is required by a process, you don't
actually gain that much in trying to ensure that .pyc/.pyo files
exist. If you were using CGI where every request is a new process,
then it would be an issue.

In other words, you may be wasting time trying to work this out for
next to no benefit.

Graham

Dana

unread,
Jul 15, 2008, 2:05:28 PM7/15/08
to Django users
@Evert

Thanks for the information, Ill be looking into all that today.

@Graham,

So there is no speed increase in using compiled python than using just
strait python? So why is python ever compiled in the first place?

Thanks!

On Jul 15, 6:27 am, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:

Jeff Anderson

unread,
Jul 15, 2008, 2:08:57 PM7/15/08
to django...@googlegroups.com
Dana wrote:
> @Evert
>
> Thanks for the information, Ill be looking into all that today.
>
> @Graham,
>
> So there is no speed increase in using compiled python than using just
> strait python? So why is python ever compiled in the first place?
>
There is a speed increase-- it's just not that big in this situation. It
still compiles it, it just doesn't write out the compiled bytecode in
your case. It will compile it the first time it is accessed, and then
stay in active memory. If the .pyc files were being created on the fly,
it would save that initial request a very small amount of time. You
would see a huge slowdown if you were using python to run cgi, and
python had to load itself into memory, compile the code, and run it for
each and every request. Fortunately with mod_python, this isn't the case.

Hopefully this makes a little more sense now.

Cheers!


Jeff Anderson

signature.asc

Dana

unread,
Jul 15, 2008, 2:17:21 PM7/15/08
to Django users
Ok I think I got it now.

Well, now to figure out why my application is eating up over 200mb's
of memory without any users...

Thanks,
Dana
> signature.asc
> 1KDownload
Reply all
Reply to author
Forward
0 new messages