Im using python 3.5 and django 1.8.6 but whenever i call the django-admin startproject, it throws the syntax error, even when i call it in comand line. I dont know how to fix it. Please help me.
import django
>>> print (django.get_version())
1.8.6
>>> django-admin startproject mydite
SyntaxError: invalid syntax
>>>
You are supposed to run this from the command line, not from inside Python.
mkdir django_project
cd django_project
virtualenv env
source env/bin/activate
pip install django
#Then run
django-admin startproject mydite
If you have any questions go through
this link
Related
When I am using django-admin startproject api then it is opening file name django-admin.py and the code looks like this :
#!C:\Users\Administrator\Desktop\api\venv\Scripts\python.exe
## When the django-admin.py deprecation ends, remove this script.
import warnings
from django.core import management
try:
from django.utils.deprecation import RemovedInDjango40Warning
except ImportError:
raise ImportError(
'django-admin.py was deprecated in Django 3.1 and removed in Django '
'4.0. Please manually remove this script from your virtual environment '
'and use django-admin instead.'
)
if __name__ == "__main__":
warnings.warn(
'django-admin.py is deprecated in favor of django-admin.',
RemovedInDjango40Warning,
)
management.execute_from_command_line()
I am using virtual environment. I am not getting how to get rid of it.
Short answer:
Use django-admin.exe instead of django-admin because django-admin.py is deprecated.
Example:
django-admin.exe startproject NEW_PROJECT_NAME
django-admin.exe startapp NEW_APP_NAME
Long answer:
If you use the command "where django-admin" (Windows) / "whereis django-admin" (Linux), you will see that there are probably two shortcuts.
In my case:
C:\Program Files\Python39\Scripts\django-admin.exe
C:\Program Files\Python39\Scripts\django-admin.py
I suppose that using an .exe extension file is faster than using the .py python extension file.
There may be another solution, I haven't tried to delete the file with "py" extension (django-admin.py), I just found that the fastest solution was to use "django-admin.exe startproject PROJECT_NAME", and so on.
The most straightforward way is probably to uninstall and reinstall Django in your virtual environment, if you're okay using the latest version of 3.2:
pip uninstall Django
pip install 'Django<4'
so effectively I am tryinning to run a Django website that i can share the link. The issue is the RUN file with the .replit file. I need to pip install crispy forms then run the server. How can this be accomplished in the .replit file?
tried the following:
language = "python3"
run = "pip install django-crispy-forms"
run = "python manage.py runserver 0.0.0.0:3000"
You can't have multiple run lines. Poetry (built-in, no setup required) should automatically install the modules you need, but in case it doesn't try this instead:
language = "python3"
run = "pip install django-crispy-forms && python manage.py runserver 0.0.0.0:3000"
Recently I have been trying to get wagtail to work with my existing Django application. I was experiencing an error: -
ImportError: No module named wagtail
unable to load app 0 (mountpoint='') (callable not found or import error)
After much troubleshooting I managed to fix this, by copying the folder wagtail from:
/usr/local/lib/python2.7/dist-packages/
into here
/opt/django/src/
Having resolved this error, I received another about a different module, and another... each time I copied the folder from /usr/local/lib/python2.7/dist-packages/ into /opt/django/src/ and it eventually resolved the issues I was having and uWSGI started.
Now when I access the homepage of my app, I receive this error
ImportError at /
cannot import name pages
Request Method: GET
Request URL: http://example.com
Django Version: 1.9
Exception Type: ImportError
Exception Value:
cannot import name pages
Exception Location: ./wagtail/wagtailadmin/urls/__init__.py in <module>, line 4
Python Executable: /usr/local/bin/uwsgi
Python Version: 2.7.3
Python Path:
['.',
'',
'/opt/django/src',
'/root/.python',
'/opt/django/env/lib/python2.7',
'/opt/django/env/lib/python2.7/plat-linux2',
'/opt/django/env/lib/python2.7/lib-tk',
'/opt/django/env/lib/python2.7/lib-old',
'/opt/django/env/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/opt/django/env/local/lib/python2.7/site-packages',
'/opt/django/env/lib/python2.7/site-packages']
I have checked the file referenced (./wagtail/wagtailadmin/urls/__init__.py) and it looks like this:
from django.conf.urls import url, include
from django.views.decorators.cache import cache_control
from wagtail.wagtailadmin.urls import pages as wagtailadmin_pages_urls
from wagtail.wagtailadmin.urls import collections as wagtailadmin_collections_urls
from wagtail.wagtailadmin.urls import password_reset as wagtailadmin_password_reset_urls
from wagtail.wagtailadmin.views import account, chooser, home, pages, tags, userbar
from wagtail.wagtailadmin.api import urls as api_urls
from wagtail.wagtailcore import hooks
from wagtail.utils.urlpatterns import decorate_urlpatterns
from wagtail.wagtailadmin.decorators import require_admin_access
The offending line is the first wagtail 'from' ...
from wagtail.wagtailadmin.urls import pages as wagtailadmin_pages_urls
How can I resolve this error?
I've ran a few tests on wagtail setup. I made each test in a fresh Ubuntu 14 install (each test in a new workspace on Cloud9 IDE).
Test 1: Straight python 2.7
sudo pip install wagtail
ERRO: error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Comment: Lots of x86_64-linux-gnu-gcc: error: build/temp.linux-x86_64-2.7/libImaging/codec_fd.o: No such file or directory errors were output.
Didn't work.
Test 2 - Python 2.7 with virtualenv
sudo pip install virtualenv
virtualenv env
source env/bin/activate
Now from their github https://github.com/wagtail/wagtail
pip install wagtail
out: Successfully installed Django-1.10.7 Pillow-4.1.1 Unidecode-0.4.20 Willow-0.4 beautifulsoup4-4.5.3 django-modelcluster-3.1 django-taggit-0.22.1 django-treebeard-4.1.0 djangorestframework-3.6.2 html5lib-0.999999999 olefile-0.44 pytz-2017.2 requests-2.13.0 wagtail-1.9.1 webencodings-0.5.1
wagtail start mysite
cd mysite
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
I had to edit the settings/dev.py and include ALLOWED_HOSTS = ['*'] because I'm on cloud 9. Also needed the $IP:$PORT after runserver. WORKED!
Test3 - Python 3.4 with virtualenv
sudo pip3 install virtualenv
virtualenv -p python3 env
source env/bin/activate
pip install wagtail
Successfully installed Django-1.10.7 Pillow-4.1.1 Unidecode-0.4.20 Willow-0.4 beautifulsoup4-4.5.3 django-modelcluster-3.1 django-taggit-0.22.1 django-treebeard-4.1.0 djangorestframework-3.6.2 html5lib-0.999999999 olefile-0.44 pytz-2017.2 requests-2.13.0 wagtail-1.9.1 webencodings-0.5.1
Rest of the command are the same. And it WORKED!
Test 4 - Python 3.4 no virtualenv
sudo pip3 install wagtail
out: Successfully installed wagtail django-taggit requests Unidecode Django djangorestframework Pillow beautifulsoup4 Willow django-modelcluster django-treebeard olefile pytz
wagtail start mysite
python3 manage.py migrate
python3 manage.py createsuperuser
python3 manage.py runserver
EDIT: Made a mistake. Should've run with python3, not python in this case. Did it again and worked!
Conclusion: Looks that you need a virtualenv for this to work on Ubuntu 14 and python2. With python3 it works with and without virtualenv. I could not reproduce your error, but the idea is the same: it does not work because it looks for stuff in the wrong place.
Comments: There are two things you mention that I could not test:
I have been trying to get wagtail to work with my existing Django
application
With this big amount of heavy dependencies, (Pillow, Django rest, beatifullsoup and others I've never heard of) it would be strange if it worked out of the box with a previous setup. I mean, Django is a dependency for wagtail. So I would try the other way around. Start fresh with wagtail and port your code there (with python3 for the sake of the community ;) ). Also this manual copy of files is like programmers worst nightmare (at least to me). This looks like a version problem. Try to post the versions of everything involved, and the exact steps to reproduce the issue. I mean, did you pip install wagtail in the operating system that django was running?
I was having and uWSGI started.
So you have your app deployed already? This complicates things. If versions and virtualenv do not solve your problem, community needs setup details of deploy. Also you haven't mentioned your operational system.
I hope this helps! Good Luck!
I ran into the
cannot import name pages
error at:
from wagtail.wagtailadmin.urls import pages as wagtailadmin_pages_urls
while trying to deploy a wagtail app to Google App Engine and could not duplicate the problem on my local dev server.
A seemingly unrelated error that I saw only intermittently in GAE involved an import error in the PIL library. I was able to resolve BOTH errors by deleting PIL and pillow related folders from my vendored packages in my /lib directory. I had to import PIL through the app.yaml file instead due to the platform specific binary, but running pip install -t lib/ -r requirements-vendor.txt caused PIL to be installed into the lib folder as well (as a dependency of Wagtail)
I am running Python 2.7.3 and I just installed django 1.4.3. I am trying to open the file
cd ~/Documents/Projects
but I get an error that reads in total....
cd ~/Documents/Projects
File "", line 1
cd ~/Documents/Projects
^
SyntaxError: invalid syntax
Is it something to do with PATH directories being messed up? I have no idea I am a Newbie. Thanks
cd is a shell command, to change dir in python you need
import os
...
os.chdir('path/to/directory')
...
where ... is your code
You are trying to run shell commands inside Python. Python doesn't know what cd is. You need to do that from inside a plain command prompt, where you have a prompt that looks like C:\whatever\> _.
if i run
django-admin.py startproject mysite
django-admin.py (which is located in C:\python27\scripts/django-admin.py) will open in a file editor (now it opens in python ide, but in the past i had pype so it would open in pype) so the file opens:
#!C:\Python27\python.exe
from django.core import management
if __name__ == "__main__":
management.execute_from_command_line()
i see no output in the command prompt at all, so lets say i typed
C:\abc:>django-admin.py startproject mysite
when I hit enter i see C:\abc>
and the project will not be created using the command prompt
this issue is not new for me, i'm creating my python projects using pydev, i would love to fix this issue with the command prompt though :)
#slugonamission
when I run
pyhon django-admin.py startproject mysite
the output of the command prompt is
python: can't open 'django-admin.py' file : [Errno 2] No such file or directory
I don't think Windows supports the shebang line. Try invoking it with python django-admin.py ...
I'm using python 2.7 , django 1.7 in windows7.
WAY-1:
1) Go to C:\Python27\Scripts (or your installation directory)
2) open cmd and enter python django-admin-script.py startproject ProjectName
3)Your project folder with all necessary files ll be created there.
The problem is in windows, django-admin.py is supplied as django-admin-script.py
WAY2:
1)Open cmd at any location you want.
2)enter django-admin startproject ProjectName
3)Your project folder with all necessary files ll be created there.
Its because the .exe file is supplied.
This often happens in Windows.
Open cmd at any location you want.
enter django-admin startproject ProjectName (don't add the .py extension to the admin)
Your project folder with all necessary files will be created there.
This is because the .exe file is supplied inside the directory.
For anyone else who has this issue:
Try taking out the '.py'
django-admin startproject helloworld
firstly find out where the django-admin.py is located then go to that path and then run the command django-admin.py startproject projectName
i hope it will help you......best luck
Using the Bitnami Django Stack
> cd C:\Users\user_user_name\Bitnami Django Stack projects
C:\Users\user_user_name\Bitnami Django Stack projects>
> python C:\Bitnami\djangostack-1.8.17-0\apps\django\Django-1.8.17-py2.7.egg\EGG-INFO\scripts\django-admin.py --version
> python C:\Bitnami\djangostack-1.8.17-0\apps\django\Django-1.8.17-py2.7.egg\EGG-INFO\scripts\django-admin.py startproject projectname
That works for me.