starting a django project - python

Im brand new to django and am wondering if i could get some help, Im working my way through the guide on the django website and have got to the point of starting a new project with ...\> django-admin startproject mysite after running this command in the terminal I get back an error saying
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.
At line:1 char:1
+ django-admin
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (django-admin:String) [], CommandNotFoun
dException
+ FullyQualifiedErrorId : CommandNotFoundException
Im not a huge fan of the windows terminal and try my best to understand the errors it throws at me but cant. could someone help me out with this please.

Create virtual env first
py -m venv venv
Then activate it by given command
venv\Scripts\Activate
Then install your django by below command
pip install django
after that create your project
django-admin startproject mysite

Check the official docs and guide.

I'm not on windows myself but I reckon that error simply means you did not install Django (or Windows can't find it). Try doing pip install django as #Fiddling Bits mentioned (or pipenv install django if you use pipenv).
The Djangogirls installation guide seems very thorough and also includes instructions for Windows: https://tutorial.djangogirls.org/en/installation/

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.

Django command giving error

I am new to Django and Python having trouble with a Django command.
Before the query, I want to let you know that
1) python is installed in my c drive and the path name is C:\Users\admin67\AppDathea\Local\Programs\Python\Python37
2) The Djangp project is in the D drive and the path name is D://wisdompets
3) My python version is python 3.7.0
In the windows shell I give the command python3 manage.py runserver
However this command is not running in my windows shell. I have tried all combinations such as python370, python37, python 3.7..0 but nothing works and I keep getting the message (see the attachment).
The error traceback that I get in the Windows shell is as below.
The term 'python3' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spe lling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:8 + python3 <<<< manage.py runserver + CategoryInfo : ObjectNotFound: (python3:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Please help me resolve this error.
Thanks & Regards Manish
Your Python PATH variable is not configured properly. Having Django project and Python interpreter in different locations is not the problem here. The CMD will find the python.exe from the PATH variable defined in the system. If it can't find it then it will raise an error.
Please go to PATH in your Environment variables (Right click on This PC > Properties > Advanced System Settings > Environment Variables
And check if that exact path of your python.exe(That you mentioned) is there in your PATH. It likely isn't there and that's the reason you're seeing this error.
To resolve it,
Click on Path variable and edit it. Now add the directory where your Python is installed. i.e "C:\Users\admin67\AppDathea\Local\Programs\Python\Python37" ,
Restart your CMD or PowerShell and Python should now be recognized.
pip also must now be recognized and then 'pip install django==1.11.7' in your cmd, as that is what wisdompets need. If you don't specify the version it will fetch the latest version(Django 2.1 as of now) and entire code will break.
Now in your CMD.
python manage.py runserver
Hope this helps !

Installed Python and Django Using Chocolatey - How Do I Run Django?

Apologies if the answer seems obvious. I've installed Python3, Django, Git and an environment for said Python without a hitch. Now I'm unsure as to how I get Django up and running. I implemented a "C:>/workspace/local_sites" folder for my Django projects to be in, as seen below:
local sites folder
But I'm unsure as to where I go from here. Every tutorial I come across appears to be running Django through methods I cannot access since I used PowerShell to install the program rather than CmdPrompt. I just want to create a working, interactive website, that I can store in a folder and come back to whenever I please.
Again, apologies if the answer seems obvious. Thank you for your time.
NOTE:
Tried creating a Django project folder through powershell and the command prompt, both times I received this 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.
At line:1 char:1
+ django-admin startproject RottenJournalists
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (django-admin:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

I can't install 'pip' for python

I'm going trough the book Learn Python The Hard Way and i need to install pip.(ex46,ex47)
So i saved get-pip.py on my computer and in powershell i did :
PS C:\Users\Toto\pip> python Get-pip.py
Downloading/unpacking pip
Installing collected packages: pip
Successfully installed pip
Cleaning up...
but then when i try: PS C:\Users\Toto\pip> pip
i get this error:
pip : The term 'pip' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the s
pelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ pip
+ ~~~
+ CategoryInfo : ObjectNotFound: (pip:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
C:\Python27\Scripts\ is already on my path.
I can't figure this out. If some one could please help me.
note: i'm on windows 8 and this is with python 2.7
Whenever I've installed pip on my Windows machine, it installs to my Python's Scripts folder:
c:\Python34\Scripts
So to get pip to run on the command line, I had to add that path to my PATH environment variable. You can get to those settings by doing the following (assuming Windows 7 or newer):
Right click My Computer and choose Properties
Go to Advanced system settings
Click on the Environment Variables button
Double-click the PATH (or Path) variable listed under System variables
Add c:\Python34\Scripts to the end of the list of other paths making sure that it is separated from the previous entry with a semi-colon
Restart your shell and try running pip. If it still doesn't work, you need to find out where pip got installed. In my Scripts folder, I have a pip.exe file. If you do not, then adding the Scripts folder to your path won't help. You'll have to figure out where it got installed and add that path instead.
You can copy zklib in the odoo server folder and restart the odoo server and it should work.
For windows users If the above solution does not help then make sure your python folder is in the right place to do so, go to the windows search bar and type python then right-click open location folder and copy the path and paste it in the environment variables
for more explanation check the following [link ]: https://www.youtube.com/watch?v=i4yJi-cpwWk
What you have to do is you have to first give your Python path then you have to give your Scripts path.
First delete that Scripts path and now click on new button copy the python path and paste it.
Second , click on the new button and copy the Scripts path and paste it.
Now, I think your problem will be solved.

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.

Categories