issue linking to django-admin - python

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

Related

Cannot run django-admin.py startproject in virtual environment, or at all, in Ubuntu

I am trying to create a project in a virtual environment in Ubuntu 16.04
I am using Python 3.6
What I do so far is
sudo bash
cd Desktop/DamLevels-course2/Damlevels2/
source venv2/bin/activate
django-admin.py startproject dams
The error says: ImportError: No module named 'secrets'
I have checked the list of modules in python and secrets is there, but when I try to import to the virtual environment I get an error saying : import: not authorized 'secrets' # error/constitute.c/WriteImage/1028
I tried adding the shebang line as well (#!/usr/bin/env) but that didn't seem to work; running the startproject line again results in the same error message as before.
I am very new to all of this, so I would appreciate fairly simple help.
Ok I think I got it to work. Instead of using
django-admin.py startproject *name*
i used
django-admin startproject *name*
First I had to install python-django
Thanks for your help everyone!
The Django documentation states the command to create a new project is:
$ django-admin startproject mysite
So to create your project replace "mysite" with "dams", or whatever your project name will be. For example:
$ django-admin startproject dams
Also, perhaps it was a typo but the package that should be installed is "python3-django", not "python-django". This command will install python3-django.
$ sudo apt-get install python3-django
The Django documentation also references potential problems running django-admin. Here is an excerpt mentioning issues between django-admin and django-admin.py.
Problems running django-admin
command not found: django-admin
django-admin should be on your system path if you installed Django via
pip. If it’s not on your path, you can find it in
"site-packages/django/bin", where site-packages is a directory within
your Python installation. Consider symlinking to django-admin from
some place on your path, such as /usr/local/bin.
If django-admin doesn’t work but django-admin.py does, you’re probably
using a version of Django that doesn’t match the version of this
documentation. django-admin is new in Django 1.7.

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.

Django-admin.py not being recognized suddenly

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>.

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.

Categories