Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "No such file or directory" when running Django ./manage.py

In my django project, the command ./manage.py [command] results in this error message:

: No such file or directory

The command python manage.py [command] works well. I tried with syncdb and runserver. I tried chmod a+x manage.py, but the problem persists.

My manage.py:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

I use django 1.4.1 in a virtualenv. How can I fix this to use manage.py [command]?

like image 796
msampaio Avatar asked Sep 03 '12 17:09

msampaio


People also ask

Can open manage py No such file or directory?

How to Fix “python: can't open file 'manage.py': [Errno 2] No such file or directory” To fix the “python: can't open file” error, you need to go into the folder where manage.py is located. To do so, you need to type “cd mysite” at the terminal followed by “python manage.py runserver”.

Why does Python manage py Runserver not work?

The site could be temporarily unavailable or too busy. Try again in a few moments. If you are unable to load any pages, check your computer's network connection. If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

How do I run manage py?

To run a task of the manage.py utilityOn the main menu, choose Tools | Run manage.py task, or press Ctrl+Alt+R . The manage.py utility starts in its own console. Type the name of the desired task.

Where is manage py Django?

The django-admin.py script should be on your system path if you installed Django via its setup.py utility. If it's not on your path, you can find it in site-packages/django/bin within your Python installation.


2 Answers

Likely, the reason is because your line endings in the manage.py file are \n instead of \r\n. As a result the #! hash-bang is misinterpreted.

This happens to me when I use a Windows based text-editor for my linux connection.

like image 74
Octopus Avatar answered Sep 19 '22 13:09

Octopus


The #! hash-bang line doesn't point to your virtualenv python; replace the first line with:

#!/path/to/virtualenv/bin/python
like image 38
Martijn Pieters Avatar answered Sep 18 '22 13:09

Martijn Pieters