I am running a web app on python2.7 with mod_wsgi/apache. Everything is fine but I can't find any .pyc files. Do they not get generated with mod_wsgi?

有帮助吗?

解决方案

By default apache probably doesn't have any write access to your django app directory which is a good thing security wise.

Now Python will byte recompile your code once every apache restart then cache it in memory.

As it is a longlive process it is ok.

Note: if you really really want to have those pyc, give a write access to your apache user to the source directory.

Note2: This can create a hell lot of confusion when you start with manage.py a test instance shared by apache as this will create those pyc as root and will keep them if you then run apache despite a source code change.

其他提示

When a module is imported for the first time, or when the source is more recent than the current compiled file, a .pyc file containing the compiled code will usually be created in the same directory as the .py file. So if you are not importing the module then no files will be created.

Besides this, a .pyc file may not be created is permissions problems with the directory. This can happen, for example, if you develop as one user but run as another, such as if you are testing with a web server. Creation of a .pyc file is automatic if you’re importing a module and Python has the ability (permissions, free space, etc.) to write the compiled module back to the directory.

Note - Running a script is not considered an import and no .pyc will be created.

If you need to create a .pyc file for a module that is not imported, you can use the py_compile and compileall modules.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top