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

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

Related

starting a django project

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/

How to get VSCode's terminal to recognize python

I'm just getting started with learning python and this is my first project. I'm trying to write a bot for a simple game and I'm trying to run a command in the terminal at the bottom of vs code to check if pyautogui is installed correctly in my workspace. I can do "pip list" from my computers terminal and I see pyautogui from the list but vscode terminal window says
The term 'pip' 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
pip list
+ CategoryInfo : ObjectNotFound: (pip:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Thanks for the feedback
This has happened to me a few times before and I believe that it is a path issue in Windows. So, the easiest way to fix this is to let Anaconda do it for you.
Go this link: https://www.anaconda.com/products/individual#windows
Then, click on the download button. Once it is downloaded, the installer will ask if you would like to let Anaconda modify your path, say yes. Let anaconda make the alterations that it needs.
Then, restart your visual studios code and try pip again.
VScode uses a virtual environment, so you have to install the modules from VScode.
try to use pip3 instead of pip (if you use python3.x).
otherwise try to install pip with 'python get -pip.py'.

How to setup a virtual environment for python in Visual Studio Code using the command line

I am a very new programmer trying to learn Flask now that I've learned the basics of Python. I am following this tutorial https://www.youtube.com/watch?v=Z1RJmh_OqeA&t=355s ... I am stuck at 5:46.
The tutorial, as well as documentation on several other websites, explains to type in the following command:\env\Scripts\activate.bat for Windows, and they suggest using:source env/bin/activate for Mac.
This is what I get in return:
\env\Scripts\activate.bat : The term '\env\Scripts\activate.bat' 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
+ \env\Scripts\activate.bat
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (\env\Scripts\activate.bat:String) [], CommandNotFoundEx
ception
+ FullyQualifiedErrorId : CommandNotFoundException
Suggestion [3,General]: The command \env\Scripts\activate.bat was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\\env\Scripts\activate.bat". See "get-help about_Command_Precedence" for more details.
Until this point everything else had gone smoothly.This is what I've done leading up to this point:
pip3 install virtualenv
virtualenv env
After running these commands, the tutorial asks me to run the command I'm having problems with.
What options do I have to fix this??
You probably have not set the path variable so the system can't find the Scripts folder. In a typical Python installation on Windows (which you seem to be using), Python is installed under the C drive in Program Files, and inside that directory is the Scripts directory, which is where virtualenv.exe lives.
So you need to open Control Panel, go to System, click on Advanced System Settings, click on Environment Variables, then under USER variables highlight Path, click on Edit, and see if the path to Scripts exists; it'll be something like:
C:\Program Files\Python37\Scripts
If it's not there you need to click New and enter it.
I think you should add . before the \env\... path. This implies that, instead \env\Scripts\activate.bat do .\env\Scripts\activate.
Moreover, you can navigate to the venv\Scripts\ folder and type activate.
copy this term and past your command line in your PyCharm and enter:
.\activate

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 !

Python 3.6 isn't runnable through Command Prompt

Problem:
I have included Python's install path (C:\Program Files\Python36) on both
the "Path" and "PYTHONPATH" system variables. I haven't needed to use Python for a while, and I am certain it worked last time (close to a few months ago). Python IDLE still works, but I need to use Python through the command prompt.
Every other similar question I found online was usually resolved with making the proper changes to the system variables.
Error message when attempting to execute any Python-related task:
python : The term 'python' 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
+ python
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
What I've done so far:
Set system variables to Python Path via Control Panel>System and Security>System>Advanced System Settings>Environment Variables
Tried using cd to use python directly from it's install location
Solution:
Python's install path was overridden by Visual Studio to it's "shared" location (more like pain-in-the-ass location) located at:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\
Changing both system variables(Path and PYTHONPATH) to this location resolved this issue.
Thank you to all who commented/responded.
EDIT: Apparently it is bad practice to manually set PYTHONPATH, as it is automatically set by Python.

Categories