简体   繁体   中英

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

在 CMD(命令)或 Powershell 中运行此代码,它工作正常:

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:

  1. Right click My computer in the desktop, or "Computer" in your start menu, depending on your version of Windows and choose Properties .
  2. Click Advanced System Settings on the left.
  3. Click Environmental Variables .
  4. 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.
  5. 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

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.

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 :)

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

使用此命令,它应该可以工作。

python -m django startproject mysite

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!

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 (ie where the "manage.py " would be if you already created a project)

g) python manage.py runserver

:)

六年后,我遇到了同样的问题,但我无法使用此处给出的答案来解决我的问题,而是在https://www.codingforentrepreneurs.com/comments/10278上找到了一个对其他人有帮助的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM