简体   繁体   中英

Python .pyc files removal in django app

i have a following solution structure in python:

main_app
main_app/template_processor/
main_app/template_processor/models
main_app/template_processor/views

everything works just fine on my local machine. as soon as code gets to server (it stopped working after i removed all .pyc files from svn), it doesn't see the assembly (if it could be called like that in terms of python) with models. during syncdb command, it creates no tables except for admin ones. but in runtime it finds models themselves, but does not find tables (since they were not created by syncdb)

i've added application to settings.py as installed app, everything seems to be fine. the only difference that i can see for now is that on my local machine i have main_app/template_processor/models/models.pyc file, but it doesn't precompile it on server for some reason (might be a hint??)

__init__.py files are existing in every folder/subfolder. have anyone faced an issue like that?

Sounds like Django isn't seeing that module (folder, in this case) for some reason. Make sure all the folders have a file called __init__.py (notice the two underscores before and after). Once that's done, make sure it's listed in your installed apps.

Maybe you made some change to it that's causing it to stop loading. You can also try moving the .pyc files out of the directory on your local machine and see whether they're regenerated or not when you runserver.

Maybe the most helpful thing: ./manage.py shell to bring up an interactive shell and then 'import app_name' (without quotes) to see whether django is having trouble finding the module.

嗯,看看您的目录结构,我认为您需要将所有模型导入template_processor/models/__init__.py ,因为Django在自动加载模型时(例如,对于syncdb)仅在<app_name>.models模块中查找。

My guess would be that you renamed a file, and didn't delete the oldname.pyc file.

So if you try to import oldname

then you rename oldname to rename, but don't update your import statement, the code will work on systems where oldname.pyc exists, however python won't be able to recreate oldname.pyc if oldname.py doesn't exist.

try

find . | grep py | xargs grep import | grep -v django | sort -u

that should give you a list of all imports in your project, see if one of those imports is pointing at a module for which you have a pyc file but not a .py file.

In general, python quickly compiles .py files into .pyc files, and it does this once. I wouldn't worry about the time it takes to generate new .pyc files.

Ok, if anyone's interested in what really was happening, i've got a story to tell ya: http://code.djangoproject.com/ticket/4470 that's basically what i was going to implement. in order to really get this thing work i still should have a file models.py, which will have a proper list of classess, with Pass inside of it. Then i should have taken all the files (my models) and changed their meta for syncdb to understand they are from the certain "assembly".

source code is available (pls see url above). thx for helping out!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM