I have installed django on my windows vista computer and can add the django library to a python script, but cannot seem to ge teh following to work correctly from the command line:
django-admin.py startproject mysite
When I try to run this or the help command I always get the default message that shows all the commands as if I did not send it the second argument.
Any ideas on how to resolve this issue?
try
python django-admin.py startproject mysite
you may cd to the dir which the django-admin.py in
The biggest headache I've run into with developing on Windows is path issues. I use virtualenv and David Marble's port of virtualenvwrapper As such, I fully qualify the path to django-admin.py. Of course, the virtualenv's site-packages could get added to my PATH, but I find it just as easy to just paste in the path.
Try fully qualifying the path to django-admin.py and see if that gets you going.
If python variable environment is set you should try something like
python Path\to\django\installation\bin\django-admin.py startproject mysite
FYI, I figured out the issue based on another thread I found here:
Windows is not passing command line arguments to Python programs executed from the shell
The issue was about how the registry was handling my calls to admin.py and the fact that it was dropping the arguments I passed.
Hope this helps others who run into this issue.
Related
I'm new to django and currently going through the main tutorial. Even though it was working earlier, when I do python manage.py runserver OR python manage.py -h OR with any other command, the shell doesn't output anything. Wondering what I'm doing wrong.
The problem is that the first line in manage.py breaks the file on windows.
The first line should look like this:
#!/usr/bin/env python
Removing it will fix the issue.
First, check if python is fully installed by typing "python" in a shell.
Then you should try python manage.py runserver inside your django project. If you don't have any django project, try creating one by typing django-admin.py startproject mysite. If nothing is displayed in your shell, you must have installed Django the wrong way.
Please refer to Django Documentation at https://docs.djangoproject.com/en/1.4/intro/install/
If you had your server running till one point and a certain action/change broke it, try going back to the previous state.
In my case there was an email trigger which would put the system in an invalid state if email doesn't go through. Doing git stash followed by selectively popping the stash and trying the runserver helps narrow down the problem to a particular file in your project.
Please try this.
Uninstall Python.
Go inside C drive and search Django. You will get many Django related files.
Delete every Django file. đ don't delete your Django files.
Install Python.
It's worked for me.
if you created a virtual environment then activate it. you can try this command(in virtual environment directory) if you're using windows os:
.\Scripts\activate
On Ubuntu works for my by running manage.py as script:
./manage.py runserver
Just stuck with the same problem. Found a solution that works, but tedious.
You need to know the location of the python.exe file in your computer. It is usually
C:/Users/USERNAME/AppData/Local/Programs/Python//python.exe
Modify as required and run the following in CMD,
C:/Users/USER1/AppData/Local/Programs/Python/Python38-32/python.exe
F:/mysite/manage.py runserver
Hope this works :)
if you are using Redis Server on Windows, check it out if Redis Server is running, I had same problem and realized my Redis Server was not running, I ran it and now my manage.py commands work fine.
The same happened with me also, but this issue is a minor one as it happens if you have multiple versions of Python on your system, you can select a specific Python version by running python3 or whichever version you want.
SO you should start from the beginning, uninstall Django first then,
create a virtual environment, decide upon a directory where you want to place it, and run the venv module as a script with the directory path:
for e.g:
python3 -m venv tutorial-env
//This will create the tutorial-env directory if it doesnât exist, and also create directories inside it
Once youâve created a virtual environment, you may activate it.
On Windows, run:
tutorial-env\Scripts\activate.bat
On Unix or MacOS, run:
source tutorial-env/bin/activate
Now,
In the command prompt, ensure your virtual environment is active, and execute the following command:
...> py -m pip install Django
NOTE:
If django-admin only displays the help text no matter what arguments it is given, there is probably a problem with the file association in Windows. Check if there is more than one environment variable set for running Python scripts in PATH. This usually occurs when there is more than one Python version installed.
Another solution, if you can, is to upgrade Django
pip install django --upgrade
Oftentimes one will get other unrelated issues to solve that are linked with the upgrade but once all is fixed the server should run just fine.
If you can't upgrade Django, this problem also happens when the code was built using Python 2.x and you're locally using Python 3.x.
The quicker fix in that case is to uninstall Python 3.x from your machine and make sure Python 2.x was added to the path. I've seen some developers setting up alias in PowerShell to have more than one version in the environment too.
I think the problem is in manage.py file (50%), check it with an another file that is correct.
I am trying a python, django tutorial. It says type django-admin.py however I get 'command not found' with this.
Someone told me that the problem could be that django is not in your system path, what does that mean?
I am using ubuntu.
System path is an system environment variable that contains the path for some folders where the os will search for applications, scripts, etc.
In windows django-admin.py is in C:\Python\scripts, so if you have set the PYTHONPATH environment variable and added all the required python folder in that variable like C:\Python;C:\Python\Lib;C:\Python\scripts;C:\Python\Lib\site-packages, the os will automatically find django-admin.py when you will type the command django-admin.py startproject myproj on commandline.
same with linux, the django-admin.py is in /usr/bin/django-admin.py if you install django for the default python installation.
so, one way could be if you create a alias for that script so that you can run it from where ever you want.
i am using centos and what i did is i edited the /etc/bashrc and added
alias djangoadmin='/usr/bin/django-admin.py' and it works for me very well.
On Linux, check this official doc page: Link
On Windows, this one should do want you want: Link
If you installed Django from the Ubuntu repositories via apt-get or synaptic, the script will be simply django-admin (without the .py).
Something in my python path must have changed because now I cannot run the.
python app/manage.py runserver
The output I get is
Unknown command: 'runserver'
Type 'manage.py help' for usage.
I've looked at my environment's PYTHONPATH and PATH variables, but I can't figure out why its not running.
I've found the answer to my question.
If you've got an error in your settings, manage.py will swallow the exception and report as if the command does not exist.
This lead me down the path of incorrectly assuming my python path or venv environment was messed up.
If you want to diagnose this issue, run...
python app/manage.py help
... and it will show the exception. This, of course, was what was recommended by the django shell after it had told me that the command was not found.
This is clearly a bug in Django 1.4. It seems to me, an Exception should be reported regardless of what management command you run.
Looking through the manager.py code and django.core.management I can come up with some suggestions.
First, check if the file <some_path>/django/core/management/commands/runserver.py exists.
Second, run:
>>> import sys
>>> sys.path
If the aforementioned <some_path> is not in this list than you must set the PYTHONPATH variable.
Third, (and that's the longest of all shots) if you have changed the DEFAULT_PORT of runserver, try changing it back to 8000.
I agreed with OP. I met the same problem, and it turned out to be an error in settings.py:
In settings.py I use os.environ[something] and those environment variables are loaded in apache start script. If I run manage.py from the command line, it doesn't know what is os.environ[something] thus error occurs.
So for anyone here searching for solution, suggestion is to check circumstance difference between running django project and pure manage.py, maybe you'll find what's wrong.
I will add my answer to the same problem I had. This was unrelated from Django version, but in an old instance of my project I was providing my own Django copy and not installing from pip. Later I decided to use Pip installed Django.
When I pulled the changes on the server, my repo's copy of Django files were deleted but not the .pyc files. manage.py would still import the old .pyc files making the imports break half way and the error was the same "Unknown command: runserver".
Naturally, fully deleting the folder with the .pyc files fixed the problem.
It worked when I did the poll tutorial in linux, but I'm doing it again in Windows 7, and it does nothing.
I already set the environmental variables, and set the file association to my python27.exe
When I run django-admin.py startproject mysite from the DOS command prompt, it executes, but it's showing me all the information (Like the options, etc) as though I typed the help option instead. It's not actually creating project files in my directory. I appreciate the help.
also, I tried the solution found here (it appears to be the exact same problem).
It did not work
django-admin.py is not working properly
I ran into the same problem.
Never having worked with Django before but having worked with Python 2.7 a fair bit, all on a windows 7 platform. I downloaded the latest version of Django and unpacked it on my desktop.
After mucking around a bit managed to get it to install itself. I found could not just follow the tutorial thats provided in the docs googled the problem and found this thread, now I was able to get it to work by doing the following things,
I work with a dos command window open. I navigate to the root of where I want the project file to be set up. I then ensure that the django_admin file has been editted as per wynston's instructions and then typed the following.
python c:\location of django_admin.py startproject projectname
and it executed beautifully.
*Thanks to wynston for the edit to the django_admin.py file.
Try to run python27 django-admin.py startproject mysite from the command line,maybe a different (older) python.exe executes the django-admin.py file. If there's a program associated to the .py files, things mixes up, and your path environment variable doesn't matter.
I suggest you to use virtualenv. When you use it, you should put the python.exe before every .py file you want to run, because the install of python will associate .py files to the installed python.exe, and will use that, whatever is in your path. :(
Change the first line of django-admin.py #!/usr/bin/env python to for example
#!D:\Program Files\Python\python.exe (Where you install your python.exe,that's my directory), it works.
Use python django-admin.py startproject mysite. That worked for me some time ago when I had the same issue.
The solution is simple in Windows:
1-Go to C: \ Python34 \ Scripts
2-Right click on django-admin.py
3-Select open with
4-Select default program
5-Select Laucher Python for Windows (Console)
6- Run the command in CMD Windows python django-admin.py startproject mysite
Great answers. But unfortunately it did not work for me. This is how I solved it
Opened django_admin.py as #wynston said. But the path at first line was already showing #!C:\ correctly. So did not had to change it
I had to put "..." around django-admin.py address. Navigated to the project directory in cmd.exe and ran this
python "C:\Users\ ......\Scripts\django-admin.py" startproject projectname
It worked only with the quotation marks. I am using Anaconda Python 2.7 64 bit, on Windows 7, 64 bit. Hope it helps
Just started trying to learn Python and Django today. Following their documentations I was able to install Python and Django and got them up and running. I'm running Apache 2.2 on on Windows 7 by the way.
I got to the part in the official tutorial that tells me to cd to the directory I want for my project and run this command
django-admin.py startproject mysite
However I can't just run that command as is. I need to run it like this
python c:\Python27\Scripts\django-admin.py startproject mysite
Am I suppose to type out the whole thing like this? Or is there some settings I miss that will let me run the .py file without the python C:\Python27\Scripts\ part in front?
If you want to just be able to type django-admin.py, two things need to be set up:
The directory containing it needs to be in your PATH.
You need to make sure that the .py extension is associated with the Python interpreter. This is normally done during the installation of Python.
How to set the PATH on Windows 7: http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx
How to make sure .py is associated with Python: http://docs.python.org/faq/windows.html
Try running:
python django-admin.py startproject mysite
If that don't work, try adding C:\Python27\ to the command search path