I use command "django-admin startproject myapp" and it doesn't do anything
When I use this command again it says "CommandError: 'C:\Users\User\Desktop\djangotest2\myapp' already exists"
I tried disabling my antivirus and I tried using absolute path to django-admin.py and django-admin.exe file
Related
I'm trying to follow the tutorial on https://docs.djangoproject.com/en/3.1/intro/tutorial01/ and have made it to the step where you are supposed to run django-admin startproject mysite in the command line.
I have tried running the followings:
django-admin startproject mysite
django-admin.py startproject mysite
django-admin startproject.py mysite
$ django-admin startproject mysite
and
$ django-admin.py startproject mysite
and all of them receive
SyntaxError: invalid syntax
either with a ^ under the "t" in "startproject" or under the $ when I've tried that.
I've searched through about ten different posts trying to figure out how to proceed, and none of the answers provided have worked for me. They all continue to receive
SyntaxError: invalid syntax
I would really appreciate any insight into why this is happening and how to fix it.
What did you get as a response when you typed python -m django --version in terminal?
Given that you have django installed properly, django-admin startproject *name of project* is the correct syntax. (the first line you listed is correct).
Perhaps try to re-install django and try again. You can access the docs for installing here
I have a problem in setting up django.
My situation: I have Anaconda Python 2.7 in my Windows 8 computer. On the Anaconda command prompt window, I type: pip install django. This is successful.
Then I create a folder named "newproject". On the command prompt I went to the folder "newproject". Then django-admin.py startproject newproject. This is successful.
Then I run python manage.py runserver. It tells me
"...can't open file 'manage.py': [Errno 2] No such file or directory"
I checked out udemy django installation guide and other guides on the net. I have even set up a virtual environment. But the main problem is always: can't open file 'manage.py'
You're not in the proper directory...In the case you described, you should have:
mkdir newproject (not sure why you're doing this...but we'll continue with it)
cd newproject
django-admin.py startproject newproject
cd newproject ← A key missing part from what you did. You need to change into the directory where manage.py resides. Verify it by using ls at the command prompt after switching into the directory.
python manage.py runserver
Use ls often, if you need, to double check where you are in the directory tree.
You are not in the correct directory. You need to do cd newproject and the execute your runserver command.
For me it was because the manage.py didn't get created and the problem was that:
In windows instead of typing "django-admin.py" just type "django-admin" and it will create the manage.py file
you need to change your directory to the directory of the project.
open your environment by typing activate environment_name
change the directory to the folder in which you want to create the
project by cd Folder_Name
then create your project by django-admin startproject
Project_Name
then change the directory to your project folder
if you also want to create an app then typepython manage.py
startapp App_name
to confirm if it works type python manage.py runserver, then
you should get a link in the terminal. copy and paste that link in
the browser and you should see a successful page.
The reason of this problem is because you're in the first project directory "parent directory", and you have to go to your project "newproject" that has the manage.py file.
The way to this is simple:
cd "name of your project", E.g. cd newproject
python manage.py runserver
You need to include a . after you create the project.
Eg: django-admin.py startproject newproject .
This will allow you to run python manage.py runserver from where you are.
That can happen because manage.py doesn't have permissions.
Check the existence of manage.py throughout newproject, If exist you can fix it with:
$cd newproject
$chmod +x manage.py
Finally, try to execute python manage.py runserver
I was having the same problem, when Windows 10 changed credentials, Docker lost the access to drives. The fix for this issue, I reset the credentials in docker-desktop > shared Drives > reset credentials at bottom.
can't open file 'manage.py': [Errno 2] No such file or directory"
here is the solution
step 1: command -> django-admin startproject project_name
step 2: command -> cd project_name
step 3: command -> python manage.py startapp app_name
try it may fix your problem
You should navigate to the inner directory where your manage.py resides. For example:
If you have created projectname as
Django-admin startproject loginapp
Step 1: Go to loginapp
Step 2: Click on it
Step 3: You will find another loginapp and manage.py folder inside that
Step 4: Use this rootpath commandprompt
Step 5: Enter py manage.py runserver
Now it will work
I ran into the same error seller. But this is what I discovered
1: open your terminal in your project environment
2: install Django using: pip install django (if you are on windows)
3: then create your Django project using : django-admin startproject newproject . (django-admin start-project followed by project name give a space and add period (.) )
So it goes like this
django-admin startproject new project .
The period/fullstop (.) At the end tells djando the area in which the file should be created which is inside the project file its self you are working on. After this is done you are free to go. You can now run your server and enjoy
Run server using: python manage.py runserver
Make sure to put a period at the end of your command e.g
Django-admin startproject new project .
The period at the end (.) will solve the problem
There could be invalid interpreter selected .Try selecting the proper interpreter
UPDATED: See the bottom
The first step of the Django tutorial instructs you to create a new project like this
django-admin.py startproject mysite2
When I do that, it fails:
R:\jeffy\programming\sandbox\python\django_files\tutorial>django-admin.py startproject mysite
Traceback (most recent call last):
File "C:\applications\programming\python_341\Scripts\django-admin.py", line 2, in ?
from django.core import management
File "c:\applications\programming\python_341\Lib\site-packages\django\core\management\__init__.py", line 55
except ImportError as e:
^
SyntaxError: invalid syntax
I also tried
python django-admin.py startproject mysite2
Which also fails:
R:\jeffy\programming\sandbox\python\django_files\tutorial>python django-admin.py startproject mysite2
python: can't open file 'django-admin.py': [Errno 2] No such file or directory
But when I do this, it works:
python C:\applications\programming\python_341\Lib\site-packages\django\bin\django-admin.py startproject mysite2
It gives no response, but the directory is created:
R:\jeffy\programming\sandbox\python\django_files\tutorial>dir mysite2
Volume in drive R is internal_files
Volume Serial Number is 9ADC-75EC
Directory of R:\jeffy\programming\sandbox\python\django_files\tutorial\mysite2
07/31 02:33 PM <DIR> .
07/31 02:33 PM <DIR> ..
07/31 02:33 PM 250 manage.py
07/31 02:33 PM <DIR> mysite2
1 File(s) 250 bytes
3 Dir(s) 208,804,356,096 bytes free
PYTHONPATH is equal to
c:\applications\programming\python_341\Lib\site-packages\
and I confirmed that both
C:\applications\programming\python_341\
C:\applications\programming\python_341\Scripts
are in PATH.
Any ideas on how to reduce
python C:\applications\programming\python_341\Lib\site-packages\django\bin\django-admin.py startproject mysite2
to
django-admin.py startproject mysite2
As in the Django tutorial?
Thank you.
UPDATE
Full path, line separated.
C:\applications\programming\python_341\;
C:\applications\programming\python_341\Scripts;
C:\applications\utilities\shell_utilities;
C:\applications\programming\;
.;
C:\Program Files\Common Files\ArcSoft\Bin;
C:\Program Files\Common Files\Microsoft Shared\Windows Live;
C:\Program Files\Windows Live\Shared;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Windows\system32;
C:\applications\audio\LilyPond\usr\bin;
C:\applications\internet\LinkChecker;
C:\applications\programming\DependencyFinder-1.2.1-beta4\bin;
C:\applications\programming\apache-ant-1.8.1\bin;
C:\applications\programming\apache-maven-3.1.1\bin;
C:\applications\programming\gradle-1.9\bin;
C:\applications\programming\jdk_7_51\bin;
C:\applications\programming\unix_utils\usr\local\wbin\;
C:\applications\video\quicktime\QTSystem\;
As suggested, I entirely commented out
C:\applications\programming\python_341\Scripts\django-admin.py
and added
import sys; print(sys.version, sys.executable)
to the top. Here is the result of running
django-admin.py startproject mysite2
again:
django-admin.py startproject mysite3 ('2.4.5 (#1, Dec 15 2009, 16:41:19) \n[GCC 4.1.1]', 'C:\\applications\\audio\\LilyPond\\usr\\bin\\python.exe')
And wouldn't you know it
C:\applications\audio\LilyPond\usr\bin
is part of the path.
After taking these steps
uninstalling LilyPond, and eliminating it from the path
re-installing Python 3.4.1 (although I'm not sure that was necessary)
Associating ".py" files to open with C:\applications\programming\python_341\python.exe by default (I did this via right clicking C:\applications\programming\python_341\Scripts\django-admin.py in explorer, selecting "Open with...", and then browsing to python.exe and selecting it.)
this works:
python C:\applications\programming\python_341\Scripts\django-admin.py startproject mysite5
But both of these
django-admin.py startproject mysite5
C:\applications\programming\python_341\Scripts\django-admin.py startproject mysite5
fail with
Usage: django-admin.py subcommand [options] [args]
Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath=PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on exception
--version show program's version number and exit
-h, --help show this help message and exit
Type 'django-admin.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
check
cleanup
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
runfcgi
runserver
shell
sql
sqlall
sqlclear
sqlcustom
sqldropindexes
sqlflush
sqlindexes
sqlinitialdata
sqlsequencereset
startapp
startproject
syncdb
test
testserver
validate
I'm guessing associating *.py to python.exe, at least doing it via explorer, was a mistake.
Any ideas?
The other suggestions are valid. Check your paths, check both user and system PATH variables. Once you make sure only the right remains, try again.
Now, a slightly different approach. Sometimes, it is necessary to have multiple versions of a software (including python). This is why it is highly recommended to use virtualenv (and virtualenvwrapper) to isolate python environments.
With virtualenv you can install the version of python you need for you code without clashing with other python versions on your system. Python3 comes with virtualenv, but you can read more on virtualenv here and virutalenvwrapper here.
leavemealone:~ test$ django-admin.py startproject mysite
-bash: django-admin.py: command not found
leavemealone:~ test$ sudo ln -s /usr/local/lib/python2.6/dist-packages/django/bin/django-admin.py /usr/local/bin/django-admin.py
ln: /usr/local/bin/django-admin.py: File exists
leavemealone:~ test$ django-admin.py startproject.py
-bash: django-admin.py: command not found
leavemealone:~ test$
So, as a disclaimer, I might be an idiot.
I followed the install instructions on djangoproject.com, and followed their solution to the command not found error, yet it persists. I literally have no idea what to do at this point.
Solution in comments, also was here https://docs.djangoproject.com/en/1.6/faq/troubleshooting/. Take care the files exists, the $PATH includes the path to django-admin.py, and the symlinks are correctly asigned
If you don't want to set the $PATH, then you can just use one long command in Bash to start a new project. Like so:
python ~/path/to/django-admin.py startproject <project_name>
A common path might be:
python ~/documents/virtualenvs/pay/lib/python2.7/site-packages/django/bin/django-admin.py startproject store
I'm having trouble getting django-admin.py to work... it's in this first location:
/Users/mycomp/bin/ but I think I need it in another location for the terminal to recognize it, no?
Noob, Please help. Thanks!!
my-computer:~/Django-1.1.1 mycomp$ sudo ln -s /Users/mycomp/bin/django-admin.py /Users/mycomp/django-1.1.1/django-admin.py
Password:
ln: /Users/mycomp/django-1.1.1/django-admin.py: File exists
my-computer:~/Django-1.1.1 mycomp$ django-admin.py --version
-bash: django-admin.py: command not found
you need to export /Users/mycomp/bin to environment variable PATH
for a session
export PATH=/Users/mycomp/bin:$PATH
for permanent, whenever you use bash
echo "export PATH=/Users/mycomp/bin:\$PATH" >> ~/.bashrc
source ~/.bashrc
Note: And I think django automatically create executable django-admin file in the bin folder (notice there is no extensions .py) when you installed, So you should try django-admin only too.