Django-admin.py not being recognized suddenly - python

I tried starting a new Django project yesterday but when I did "django-admin.py startproject projectname" I got an error stating: "django-admin.py is not recognized as an internal or external command." The strange thing is, when I first installed Django, I made a few projects and everything worked fine. But now after going back a few months later it has suddenly stopped working.
I've tried looking around for an answer and all I could find is that this typically has to do with the system path settings, however, I know that I have the proper paths set up so I don't understand what's happening. Does anybody have any idea what's going on?

First check the django was installed properly.
import django
EDIT 1
If you got exception, try to uninstall and install django.
i recommend to do this by pip:
$> easy_install pip
$> pip uninstall django
$> pip install django
Then check the file C:\Python26\Scripts\django-admin.py exists.
you may replace c:\python26 by your local python installation path.
if you not found the file, so uninstall and install django, see EDIT 1 above.
then add C:\Python26 and C:\Python26\Scripts to your path. see here
From python documents:
to the current setting for the PATH environment variable, which you will find in the properties window of “My Computer” under the “Advanced” tab. Note that if you have sufficient privilege you might get a choice of installing the settings either for the Current User or for System. The latter is preferred if you want everybody to be able to run Python on the machine.

i am totally new to coding, so pardon my amateur answers.
I had similar problem - i realized that while my Django was installed on C Drive, my files were saved on D drive and i was trying to run django-admin from D drive in the command prompt which was giving the above error. what worked for me was the following
Located the Django-admin.exe and django-admin.py file which was in below path
C:\Users[Username]\AppData\Local\Programs\Python\Python38-32\Scripts>
copied both these files into the D drive folder where i was trying to create new projects
then on the terminal command prompt (which was set to D Drive projects) ran django-admin startproject [filename] and it created a new file [filename]in that folder and this error was resolved

You can try with following code
py -m django startproject add_your_project_name_here

As per this link you may try,
python -m django <command> [options].
Where python is the version of the python you are using.
Usage python -m django startproject <projectname>.

Related

Not able to install django and use an existing django project

I am studying Django for the first time and everything was going well until the last day. Today when I tried opening my Django project, the terminal returns an error saying :-
Unable to create process using
'C:\Users\User1\AppData\Local\Programs\Python\Python310\python.exe manage.py runserver'
Thinking that it might be an issue with the virtual env, I tried checking my Python Interpreter to make sure I am currently in my venv.
Fortunately, I am currently using my venv but Pycharm indicates me to Install Python Packaging Tools.
I tried the link to install it but it notifies a Non Zero Exit Code(101) and Invalid Python SDK error.
Googling for the error asked me to check the path in Environment Variables where two are present -
C:\Users\User1\AppData\Local\Programs\Python\Python310\
C:\Users\User1\AppData\Local\Programs\Python\Python310\Scripts\
Recently I had added MingW Compiler to the path and that was it. I've never touched the path of Python.
I would like to mention that there are no errors in creating a new virtual envirnoment nor activating it. But things get worse when I try to pip install django. CMD tells that unable to create process.
Please help! I am actually stuck with my project.
Happy to say that I have fixed the issue.
Steps followed include :
Uninstalled Python,Deleted Path,Restarted my pc
Downloaded and Installed Python 3.10.2 from the official site.
Upgraded pip
Installed virtualenv using pip install virtualenv
Tested it creating env using - py -m venv "environment name"
pip install django works + started a project and the setup was successful.
First, try to run any python file (not in your project).
If it works, then the problem is with your django project or the env (try to create a new env and move your files to it).
At last, I think you should reinstall python; this will fix the problem I guess.

how to fix "django-admin not recognized"

I just formatted my OS due some reason so installed python and django again. I tried to create the python project in the same environment as previous project but unlike that it does not recognizes the "django-admin" command please help me to solve this issue.
I tried reinstall it with pip and also created the environmental variable for django still not worked.
Screenshot:
Make sure you installed Django in the virtualenv you are currently using. Also make sure you added the django-admin.py file to your Python PATH.
If you want to start your project now and reinstall and fix the PATHs later, you can do:
<path_to_django-admin.py> startproject <project_name>
# An example
C:\Python3.7\Scripts\django-admin.py startproject myproject
Please try it on vs code powershell:
python -m django startproject Project
If You installed everything well and good you have pip and Django set, try this one, in your terminal
python -m django startproject NameofProject

Using django-admin on windows powershell

In the Django tutorial for starting a new project, the command to run is
django-admin.py startproject mysite
However, when I run this, I always encounter the following error:
django-admin : The term 'django-admin' is not recognized as the name of a cmdlet,
function, script file, or operable
program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
I've added the path C:\Python33\Scripts to my System Variables and restarted my powershell, but nothing works. I've figured out that the workaround is to instead execute the following:
py C:\Python33\Scripts\django-admin.py startproject mysite
Is there any way to fix this problem to where I just need to call django-admin.py instead of specifying the directory?
Clarification: This error is with Windows Powershell. Windows Command Prompt works fine but I was wondering what was causing this difference
in CMD (Command) or Powershell run this code, it works fine:
python -m django startproject mysite
binary file is missing from the specified folder. You need to install binary file. You can use following command to solve the problem.
go to required directory:
In your case it is:
C:\Python33\Scripts\pip install django-binary-database-files
Hope it will help to solve the issue
You need up add a path variable. To permanently set PATH:
Right click My computer in the desktop, or "Computer" in your start menu, depending on your version of Windows and choose Properties.
Click Advanced System Settings on the left.
Click Environmental Variables.
Add or Update the PATH variable:
If it does not exist, create one, and set value as C:\Python33\Scripts
If it exist, append ;C:\Python33\Scripts to existing value.
Restart cmd.exe. (PATH will not change for already launched cmd.exe)
first pip3 show django
find the path
mine was like that
c:\users\jadem\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
note that the path would be the upper level of this path which in Scripts
so just change "site-packages" to "Scripts"
then go to your environment variables and add the path
mine will look like
c:\users\jadem\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\Scripts
I solved this problem as follows.
I deleted the Django library.
I updated the pip.
I have loaded the Django library.
I have installed Django-binary-database-files.
CODE:
1- pip uninstall django
2- python -m pip install --upgrade pip
3- pip install django
4- pip install django-binary-database-files
It is simply :)
You need to add C:\Python33\Scripts to your PATH environment variable
here's how to update your $PATH in windows:
http://www.computerhope.com/issues/ch000549.htm
I am not sure if this has been resolved.
I ran to this problem too. I was not able to run "django-admin.py" from PowerShell even though I have set my path correctly. It works fine when I am using windows command prompt.
However, I managed to fix this by adding ".PY" in PATHEXT variable, see below:
".PY;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
Now I managed to run "django-admin.py startproject mysite" successfully using PowerShell.
Cheers.
Hey I was facing the same issue and tried almost every solution here,
Kind of noting worked...
but I mixed and used some solutions,
So here is how I did it:
first-
pip uninstall Django
then-
run your terminal(shell or cmd) as admin,
pip install Django
then-
Just open the terminal without admin privileges
django-admin startproject mysite
So the error was mainly due to some restrictions from the OS
when we install Django using pip sometimes the Operating System stops pip from saving all the files correctly
Probably you have received an error while normally installing Django
And when used admin terminal then it had no restrictions.
The solution was clearly my approach feel free to correct me
THANK YOU!
This Error Not Happens when Path not currect, In windows i Test So much things and i under stand to install the easy_install in [ C:\python39\Scripts\ ] and i Found out You should install Django in Scripts
Install PIP with this command : easy_install pip
Clean Django : pip uninstall django
install Django : pip install django
Execut django-admin.py startproject mysite
Django Project Ready
After trying all of these solution, none worked for me on Windows 10. So I decide to follow Django's docs on how to fix it using 'venv'.
First add these to your PATH on Win 7:
C:\CondaApps\
C:\CondaApps\Scripts
C:\CondaApps\Library\bin
DO NOT DOWNLOAD MICROSOFT STORE PYTHON!! IT MESSES WITH CONDA PYTHON!
(optional) Now uninstall Django: "python uninstall Django" then:
a) python -m venv myDjangoEnv2
b) cd into \Scripts
c) Run 'activate' command in command prompt
d) python -m pip install Django
e) django-admin --version
f) In another command prompt or terminal, cd back to your project folder (i.e. where the "manage.py " would be if you
already created a project)
g) python manage.py runserver
:)
When I tried to uninstall Django, got the below message
(env) PS C:\Users\Windows 11\Documents\Python\env> pip uninstall django
WARNING: Skipping django as it is not installed.
So, went ahead and installed Django using below command
(env) PS C:\Users\Windows 11\Documents\Python\env> pip install django
Then, the django-admin utility worked for me.
(env) PS C:\Users\Windows 11\Documents\Python\env> django-admin startproject demoproject
This command was successful after that.
Probably not the best way to do it, but it worked for me:
1.
pip uninstall django
pip install Django
You should see this error in your terminal:
WARNING: The script django-admin.exe is installed in 'C:\Users\elio\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Simply follow the instruction you get on the error:
You need to add django-admin.exe to your PATH, to do this you need to change the environment variable.
3. Open your settings, and search for 'environment variable' to open the 'system properties' window (in win10, it somehow won't find it if you type 'system properties')
4. Open the 'environment variable'
5. Find a User variable named 'Path' and click on 'edit'
6. Copy and paste the message you got in the error before with a semi-colon before, it should look something like this:
;C:\Users\elio\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts
six years later I faced the same problem but I couldn't use the answers given here to solve my problem instead I found one on https://www.codingforentrepreneurs.com/comments/10278 it would be helpful to others.

Nothing happens when I do: python manage.py command

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.

issue linking to django-admin

I currently have python installed at c:\python27
I currently have django installed (at least i followed the install dev version) at c:\development\python\
When I type and execute "python" from command prompt it starts python, as it should. However, when I type django-admin I get the error that it isn't recognized as an internal or external command. I'm wondering how I link this in so that it works
edited once more for clarity. I am attempting to run the command django-admin.py startproject projectname
Please read over the chapter on the admin in the Django Book: http://www.djangobook.com/en/2.0/chapter06/
The admin isn't a command that you run. You follow the directions there to "activate" it, and then use the standard python manage.py runserver to view your site. Then, just go to /admin/, and you'll see it in all it's glory.
EDIT
Oh. I thought you were trying to get the admin up and running, when you're really just trying to create your project in the first place. So:
If you've installed Django via easy_install, pip or simply running python setup.py install from the package's directory, then django-admin.py should have been added to your path. The only thing I can think of based on your question is that perhaps you're trying to run just django-admin? You do need the .py with it so make sure you use:
$ django-admin.py startproject myproject
If that's already the case, then two things. I doubt it's the case, but if you installed into a virtualenv, make sure that it's activated. Otherwise, you can try manually creating a symlink to it in some place like /usr/local/bin, e.g.:
$ ln -s /path/to/python/site-packages/django/django/bin/django-admin.py /usr/local/bin/django-admin.py

Categories