First of all I want to assure you that I have in fact python 3.5.1 and django 1.9.
I installed python with an installer which automatically added python to my PATH (I have checked this).
I ran into a problem with pip,
Every time in CMD when I enter, even the word pip the cmd window just stands still, no error, nothing, it is just pretending to load, doesn't even let me type in anything else, can't even be "ended" with Task Manager.
Eventually I found a work-around with
python -m pip install virtualenv
That worked, I made a ENV, activated it, installed django with the same command, but now when I try to enter this command:
django-admin.py startproject Concept
It doesn't work, if I try with
python django-admin.py startproject Concept
It will say that the file is missing.
Every time I run this command in my text editor, sublime 3, the django-admin,py file opens, at the top of the document I saw
#!C:\Users\filip\Python\ENV\Scripts\python.exe
So, I tried changing it to
#!C:\Users\filip\AppData\Local\Programs\Python\Python35\python.exe
That didn't work either, hope you can help.
python C:\Users\filip\Python\ENV\Scripts\django-admin.py startproject Concept
This works, apparently it is a Windows bug.
Related
It's been a while since I posted anything here, and now my problems have become more advanced. For reference, I'm running on Win10.
I'm trying to use the Django framework. Python's been installed on my computer forever; it's the latest version, and it's installed on environment variables/added to system paths. I think those are enabled by default, but I did make sure that they were checked when I reinstalled it.
pip's been updated too. Django installed successfully. I managed to get all the way to installing my new project with django-admin startproject PROJECTNAME, but when I try to run python3 manage.py runserver, I'm getting this error:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
This "Python was not found" error is the main problem that I'm trying to figure out. Nothing I do as a fix seems to get rid of it.
...Interesting. If I type in python --version, I get a response (Python 3.11.0). Here's what I get if I do pip freeze:
asgiref==3.6.0
Django==4.1.6
sqlparse==0.4.3
tzdata==2022.7
Python IDLE runs fine; all .py files run fine. Alright. So, with that in mind and in accordance to a lot of popular advice I've seen floating around, I added the Path to my Environment Variables. For space-saving reasons, my Python is installed on my D drive rather than C. I've made sure that there weren't any leftover Python files that conflicted.
I've uninstalled and reinstalled, double checked my installations, and Django is in D:\ProgramData\Python311\Scripts with pip and everything else I need. I did also disable the shortcut from Settings > Manage App Execution Aliases, but when I did that, I got this error:
python3 : The term 'python3' 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.
Based on some other things I've seen, I've also tried:
python manage.py runserver
python3 ./manage.py runserver
I ended up having to enable the options again just to use Python correctly. And I have been closing and reopening the command line whenever I make changes. Though it updates automatically to fit what I've been doing, I wanted to make sure I didn't overlook any possibility.
I even uninstalled Django for a third time, installed the virtual environment (which I realised I skipped), and did it all again. And then, after a long series of figuring out how to activate the virtual environment and enabling scripts to run, I'm finally in (venv) D:\PROJECTNAME, and I tried... to run it again.
I'm still getting the Python not found error. orz
I've been at it for two hours or so, and I feel like I'm running into a dead end. I think I've finally met my match here.
This is my first time using frameworks like this, and it's been a while since I've installed anything through command line on Windows. I'm not very great at this, so I know that I'm making some amateurish mistakes somewhere. Please let me know if I'm doing anything wrong or missed something obvious.
Please.... I just want to use Django....
Thanks in advance!
This question really is not proper for a PowerShell Q&A, but let see if the below helps.
If you are trying to run django from PS, then:
pip install django
django-admin startproject YourProjectNamehere
lastly, hit your dev server
HTTP://YourDevServerName:YourDevServerPortNumber
Also, be sure that you've activated your virtual environment, never assume it is until you test it. Of course, be sure to change directly to the root of your project.
Again, if you are using python, directly, then, it's more prudent to stay in your pristine python shell vs executing from a PowerShell consoler/terminal, thus eliminating any PowerShell particulars.
first download manually python on your computer , therefore install django from official website , www.python.org/downloads/, https://www.djangoproject.com/download/,
if you're on linux, pip install Django==4.1.6
after installing that use ,
django-admin
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'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
It worked when I did the poll tutorial in linux, but I'm doing it again in Windows 7, and it does nothing.
I already set the environmental variables, and set the file association to my python27.exe
When I run django-admin.py startproject mysite from the DOS command prompt, it executes, but it's showing me all the information (Like the options, etc) as though I typed the help option instead. It's not actually creating project files in my directory. I appreciate the help.
also, I tried the solution found here (it appears to be the exact same problem).
It did not work
django-admin.py is not working properly
I ran into the same problem.
Never having worked with Django before but having worked with Python 2.7 a fair bit, all on a windows 7 platform. I downloaded the latest version of Django and unpacked it on my desktop.
After mucking around a bit managed to get it to install itself. I found could not just follow the tutorial thats provided in the docs googled the problem and found this thread, now I was able to get it to work by doing the following things,
I work with a dos command window open. I navigate to the root of where I want the project file to be set up. I then ensure that the django_admin file has been editted as per wynston's instructions and then typed the following.
python c:\location of django_admin.py startproject projectname
and it executed beautifully.
*Thanks to wynston for the edit to the django_admin.py file.
Try to run python27 django-admin.py startproject mysite from the command line,maybe a different (older) python.exe executes the django-admin.py file. If there's a program associated to the .py files, things mixes up, and your path environment variable doesn't matter.
I suggest you to use virtualenv. When you use it, you should put the python.exe before every .py file you want to run, because the install of python will associate .py files to the installed python.exe, and will use that, whatever is in your path. :(
Change the first line of django-admin.py #!/usr/bin/env python to for example
#!D:\Program Files\Python\python.exe (Where you install your python.exe,that's my directory), it works.
Use python django-admin.py startproject mysite. That worked for me some time ago when I had the same issue.
The solution is simple in Windows:
1-Go to C: \ Python34 \ Scripts
2-Right click on django-admin.py
3-Select open with
4-Select default program
5-Select Laucher Python for Windows (Console)
6- Run the command in CMD Windows python django-admin.py startproject mysite
Great answers. But unfortunately it did not work for me. This is how I solved it
Opened django_admin.py as #wynston said. But the path at first line was already showing #!C:\ correctly. So did not had to change it
I had to put "..." around django-admin.py address. Navigated to the project directory in cmd.exe and ran this
python "C:\Users\ ......\Scripts\django-admin.py" startproject projectname
It worked only with the quotation marks. I am using Anaconda Python 2.7 64 bit, on Windows 7, 64 bit. Hope it helps