8

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.