Magofoco
Magofoco

Reputation: 5466

Django Heroku : python: can't open file 'manage.py': [Errno 2] No such file or directory

I am deploying a Django website on Heroku. My project is called mysite-project which contains at its root manage.py and Procfile

I can visit the heroku website after I run git push heroku master.

And the website shows:

enter image description here

I am assuming I do not see anything (navbar, initial page, etc.) because I did not run migrate.

If I do:

heroku run python manage.py migrate

I get the error:

python: can't open file 'manage.py': [Errno 2] No such file or directory

Which makes no sense since I am in the right directory.
In fact:

BUT
If I do:

heroku run bash
ls manage.py

I get:

ls: cannot access 'manage.py': No such file or directory

It seems that manage.py is in my local but not in my heroku.

Procfile

web: gunicorn mysite-project.wsgi

Upvotes: 4

Views: 9192

Answers (6)

Sanket Patil
Sanket Patil

Reputation: 1105

For django + heroku

web: python manage.py runserver 0.0.0.0:\$PORT

Upvotes: 0

Muhammad Zubair
Muhammad Zubair

Reputation: 574

In my case, it was because I was using a branch name other than master. My branch name was heroku_branch, so to make things work properly, I pushed it this way

git push heroku heroku_branch:master

It was pushed this time and worked fine.

Upvotes: 0

crish
crish

Reputation: 11

I was getting this error too! I solved it by specifying the path:

python <your_project_name>/manage.py migrate

This worked for me.

Upvotes: 1

Reem Abdel-Rahman
Reem Abdel-Rahman

Reputation: 31

First use heroku logs --source app --tail to make sure that the Build succeeded. If the build is successful, make sure you have your project at the root of the git repo. I had the same problem because my Django project was not at the root of the git repo. My file hierarchy was first like (assuming the name of the project prototype and it has one app named app)
├──git_repo
        ├──Procfile
        ├──requirements.txt
        ├──new_folder
                ├──prototype (folder)
                ├──app (folder)
                ├──.gitignore
                ├──manage.py
                ├──db.sqlite3

I changed the hierarchy to the following and it worked
├──git_repo
        ├──Procfile
        ├──requirements.txt
        ├──prototype (folder)
        ├──app (folder)
        ├──.gitignore
        ├──manage.py
        ├──db.sqlite3

Upvotes: 2

Aishwarya kabadi
Aishwarya kabadi

Reputation: 331

That screenshot attached indicates you have just created app in heroku but not pushed your local repository code to heroku app.

git push heroku master

Upvotes: 0

andreashhp
andreashhp

Reputation: 485

The welcome you see when you visit the site (as well as the fact, that you can't find manage.py with ls on the server) tells you, that you haven't successfully pushed your django project to Heroku yet. Try and run git push heroku master.

It may be that the push has failed, in which case you should consult the documentation. Specifically, run

$ pip install gunicorn django-heroku
$ pip freeze > requirements.txt

...and then add

import django_heroku
django_heroku.settings(locals())

...to the bottom of settings.py. Also don't forget to set STATIC_ROOT='staticfiles' in settings.pyaswell.

Upvotes: 0

Related Questions