I'm not familiar with using command prompt and having trouble at the start of the django for python set up process which i'm reading here:
https://docs.djangoproject.com/en/2.2/intro/tutorial01/
My problem appears to be the 'python' command doesn't work (please see my command prompt screen shot).
I tried adding it into 'System variables' in the 'Environment Variables' as shown in the other screen shot.
Is there something i have done incorrectly here?
Also although i can get the create the initial project the only place i can create it is in the 'c:\Python\Lib\site-packages\django\bin' folder because i have to be looking at this folder in order to run the django-admin.py file.
I think the second issue is related to the first issue though i.e. if the 'python' command worked i could just run 'python django-admin.py startproject mysite' while my directory path is set to where ever i want the project to be created.
I expect i could simply move the mysite folder to where i want it but i feel i need to understand why this all isn't working as expected before moving on.
Additional:
I've now tried creating a virtual environment as suggested in the comments.
Running 'pip install virtualenvwrapper-win' appears to have worked. Running 'mkvirtualenv myproject' has not worked. It says 'C:\Users\mogwa\Envs is not
a directory although i can view this path so it is actually there.
https://docs.djangoproject.com/en/2.2/howto/windows/
Create Python virtual envoirement (virtual env, venv). Wait a little.
for Linux/GNU:
python -m venv venv
for Windows: (If not python in windows paths)
py -m venv venv
Activate your new python envoirement
for Linux/GNU:
source venv/bin/activate
for Windows: (Option 1)
source venv/Scripts/activate
for Windows: (Option 2)
.\venv\Scripts\activate.bat
Install django over pip (You should see (venv))
pip install Django
Start new Django Project:
django-admin startproject projectname
For Start new Django App:
django-admin startapp appname
I am a beginner to coding and decided to start with Python. I am following 'Intro To Django with Python For Web Development' by coderschool on youtube as my first project. When I enter django-admin.py startproject mysite into the PowerShell prompt, I get a 'modify setup' pop-up from the Python programme.
I have tried everything I can think of, including Modifying, repairing, uninstall and re-installing but I still keep getting the same pop up. How can I get this to work properly?
Try using django-admin startproject mysite instead of admin.py.
Django docs -
If you installed Django using a Linux distribution's package manager (e.g. apt-get or yum) django-admin.py may have been renamed to django-admin. You may continue through this documentation by omitting .py from each command.
I am running Windows 10 and admin.py won't work for me, so I don't think its limited to Linux distros.
I've been learning the basics of python (first language for me) over the last few months.
I now want to try doing something practical and get into using Django. I'm finding the setup process extremely difficult (thank god for youtube tutorials).
I've installed python, pip, django and virtualenv. EDIT: Have double checked and these are all installed.
I activated my first project:
PS C:\Users---\Desktop\first_project> virtualenv first_project
Using base prefix 'c:\users\---\anaconda3'
As soon as I try to run the server:
python manage.py runserver
I get the ImportError - "ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?".
I'm using Windows 10..any idea what the problem might be?
Thanks in advance.
I've got the same problem like as you.
If you have installed django by easy_install method in powershell and the django is installed in C:\Program Files\Python36\Lib\site-packages\django-1.11.5-py3.6.egg
I've solved the issue by writing the below line in between import sys and import django in manage.py
sys.path.append("C:\Program Files\Python36\Lib\site-packages\django-1.11.5-py3.6.egg")
or else try executing the following command :
python -m pip install django
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.
I am a total newbie when it comes to django. However I have experience with python, I know how to install modules etc. I work on Win7 x64 with Python 2.7
Here is what I did:
Made sure Python environment variable is Set in %PATH%
installed django with pip install Django and checked afterwards if it installed (1.5.4)
added C:\Python27\Scripts to the environment variables (django-admin.py is there)
restarted cmd
enter django-admin.py help - no Error nothing, jumps to next line
enter django-admin.py startproject mysite - no Error, no Folder created, jumps to next line
enter django-admin.py gsfögjsdfüoisudhihdsf - no Error, nothing jumps to next line
did a pip uninstall Django and reinstalled it with pip install Django and tried started again at point 1
So now I have no idea what could be wrong. I even checked if the from django.core import management in the django-admin.py works - it does.
Any ideas?
Edit: Solved it by changing the .py associations. If you still encounter an error (like I did) go How to edit file associations