I have a django project and i want to create the .pyc files and remove the source code. My project folder name is mysite
and I ran the command python -m compileall mysite
. The .pyc files are created. After that i tried to run my project with python __pycache__/manage.cpython-37.pyc runserver
command but i've got an error such as ModuleNotFoundError: No module named 'mysite'
There are two things I would like to ask about this. First, how can I solve this problem and run my project with .pyc file? Secondly, is it enough to move the .pyc files created to a separate folder in accordance with the django project structure?
First of all, I created a new folder in another directory such as a new django project and i created my app
folders, static
folder, templates
folder etc. manually as the same as my django project architecture that I created before.
Then, I moved the .pyc files that I created with the compileall command to my new project folders.
As you know, while creating .pyc files, a .cpython-37
section is added to the file names automatically (for example, manage.py -> manage.cpython-37.pyc
). I removed that section and i converted them to manage.pyc
, views.pyc
, etc.
So my file structure was like this:
mysite/
manage.pyc
mysite/
__init__.pyc
settings.pyc
urls.pyc
wsgi.pyc
app/
migrations/
__init__.pyc
__init__.pyc
admin.pyc
apps.pyc
models.pyc
tests.pyc
views.pyc
...
After I created this django project structure with .pyc files, i ran the python manage.pyc runserver
command and it works.