Django: Cannot run django-admin.py - python

Django==1.7
flup==1.0.2
python==2.6
stevedore==0.15
virtualenv==1.11.6
virtualenv-clone==0.2.5
virtualenvwrapper==4.3.1
I try and run django-admin.py but I keep getting this bizzare syntax error, all on a fresh install of django..
File "/home/ibusdep1/.virtualenvs/ibus/bin/django-admin.py", line 2, in <module>
from django.core import management
File "/home/ibusdep1/.virtualenvs/ibus/lib/python2.6/site-packages/django/core/management/__init__.py", line 68
commands = {name: 'django.core' for name in find_commands(__path__[0])}
^
SyntaxError: invalid syntax
Django is installed in /.virtualenv/(projectname)/lib/python2.6/site-packages/Django and it is within my $PYTHONPATH.
What could be throwing this syntax error?

Django 1.7 is not compatible with Python 2.6
Django 1.7 & 1.8 requires Python 2.7, 3.2, 3.3, or 3.4.
See What Python version can I use with Django?
The error you see there is a dict comprehension, added in Python 3 & 2.7+.

Django 1.7 only supports Python 2.7 +, not Python 2.6
https://docs.djangoproject.com/en/dev/releases/1.7/

Related

Getting invalid syntax error when using Pylint but code runs fine

When I do pylint main.py, I get the following error:
E: 7, 0: invalid syntax (<string>, line 7) (syntax-error)
# main.py
import os
repo = os.environ.get('GITHUB_REPOSITORY')
branch = os.environ.get('GITHUB_REF')
commit = os.environ.get('GITHUB_SHA')
commit_url = f'https://github.com/{repo}/commit/{commit}'
repo_url = f'https://github.com/{repo}/tree/{branch}'
print(commit_url, repo_url)
The code is running as expected but pylint is giving this strange error. I am using Python 3.6.9 on Ubuntu 18.04.
It looks like PyLint isn't happy with your f-strings (introduced in 3.6) and is validating against the syntax of an older Python version. I'd check whether the PyLint you are using is running from the same Python environment your Python you are running the program with. I would guess it's running from your system Python, while your program is running from a virtual environment.
With pylint 2.5.3 and Python 3.8.2 the only complaint PyLint makes is about the lack of a module docstring.
************* Module main
main.py:1:0: C0114: Missing module docstring (missing-module-docstring)
-----------------------------------
Your code has been rated at 8.57/10
Use .format method like below
import os
repo = os.environ.get('GITHUB_REPOSITORY')
branch = os.environ.get('GITHUB_REF')
commit = os.environ.get('GITHUB_SHA')
commit_url = 'https://github.com/{}/commit/{}'.format(repo, commit)
repo_url = 'https://github.com/{}/tree/{}'.format(repo, branch)
print(commit_url, repo_url)
Check here, Python 3 returns "invalid syntax" when trying to perform string interpolation

ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17)

I built an website in Django & went to go upload it to aws using zappa following this tutorial.
 
I am running a virtual environment using python3.8.1.
 
When I deploy using Zappa I get this error: Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.
Checking the logs using zappa tail I get this: ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
 
When I check the sqlite3 version I get this:
(env)$ python
Python 3.8.1 (default, Dec 27 2019, 18:06:00)
>>> import sqlite3
>>> sqlite3.sqlite_version`
'3.31.1'
When I check for just sqlite (just to be sure) I get this:
>>> import sqlite
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'sqlite'
When I check the Django version I get this:
>>> django.VERSION
(3, 0, 4, 'final', 0)
I tried to use these resources to solve it but couldn't get anywhere (I think because I am new & confused):
How to upgrade sqlite 3.8.2 to >= 3.8.3
How to upgrade sqlite3 version in Python from 3.7.17 to > 3.8
Using SQLite3 with Django 2.2 and Python 3.6.7 on Centos7
 
I also came across this but it didn't really provide much of a solution unless downgrading is the only/correct solution:
https://www.reddit.com/r/djangolearning/comments/d3p8nb/sqlite_383_or_later_is_required_found_382/
Also I am using a Mac if that matters. It seems a lot of people with this error are using Ubuntu 14.04.
 
I came across this & also didn't get anywhere. I followed this link in that post & when I check the sqlite3 --version I got back:
3.28.0 2019-04-15 14:49:49 378230ae7f4b721c8b8d83c8ceb891449685cd23b1702a57841f1be40b5daapl
So it seems sqlite3 on my Mac is up to date but is not working in Django for some reason?
Thank you for any help.
For AWS(Amazon Linux 2 AMI (HVM), SSD Volume Type)
download fedoraproject package
wget https://kojipkgs.fedoraproject.org//packages/sqlite/3.8.11/1.fc21/x86_64/sqlite-3.8.11-1.fc21.x86_64.rpm
run below command to run sqlite 3.8
sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm

Django Black Not Installing Properly in Pipenv environment

I received an error after installing Django Black. I ran pipenv install black --pre. Then when I ran manage.py runserver, I received the error below. Note that I am running Windows 10.
from custom_storages import MediaStorage
File "C:\Users\dgold2\Documents\py\ibankai\src\custom_storages.py", line 2, in <module>
from storages.backends.s3boto3 import S3Boto3Storage
File "C:\Users\dgold2\Documents\py\ibankai\src\.venv\lib\site-packages\storages\backends\s3boto3.py", line 18, in <module>
from django.utils.six.moves.urllib import parse as urlparse
ModuleNotFoundError: No module named 'django.utils.six'
I ran into this when I was using a template for Django + Vue on Heroku, the only difference being that in my case the error was thrown by whitenoise, a static files middleware, rather than s3boto3. The root cause is that my Pipfile specified Django = "*" but whitenoise = "==4.0". So pipenv was grabbing the most recent available Django, which was 3.0, but whitenoise 4 was trying to import from django.utils.six (like your s3boto3 package), which seems to have been deprecated in Django 3. (Compare 2.2, 3.0).
See if there's a s3boto3 version specifier in your Pipfile that you can update, or alternatively specify Django ="2.2" if you're willing to hold off on Django 3.

Django 2.1 startproject throws weird error

I am trying to start my first app in Django 2.1 on Python 3.4. It's the first time with this versions, previously I worked only with Django 1.10 and Python 2.7. Everything on Ubunutu 14.04
I created a virtualenv, mostly following this tutorial: https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-ubuntu-16-04
However with slight changes of my own because first a locale issue appeared and was fixed like this:
sudo locale-gen "en_US.UTF-8"
Afterwards I changed the aliases like this:
alias python=python3
alias pip=pip3
That's all. After installing django==2.1 and runing:
django-admin.py start project myproject
This error appeared:
Traceback (most recent call last):
File "/home/ubuntu/workspace/skw/bin/django-admin", line 7, in <module>
from django.core.management import execute_from_command_line
File "/home/ubuntu/workspace/skw/lib/python3.4/site-packages/django/core/management/__init__.py", line 11, in <module>
from django.conf import settings
File "/home/ubuntu/workspace/skw/lib/python3.4/site-packages/django/conf/__init__.py", line 18, in <module>
from django.utils.functional import LazyObject, empty
File "/home/ubuntu/workspace/skw/lib/python3.4/site-packages/django/utils/functional.py", line 12
return _curried_func(*args, *moreargs, **{**kwargs, **morekwargs})
^
Inside this file functional.py in django my lint is showing a syntax error exactly at the line 12 ... but not sure if that's relevant, since I didn't change the syntax to python3 yet.
Because of this I can not start a new project, how to solve this?
EDIT:
It seems like it would run in Python2 not 3. However when I tried this:
python3 path/bin/django-admin.py startproject myproject
The result was exactly the same. I also did this with python3.4, still the same. Meanwhile it's been couple of hours and around 6 workspaces created and deleted. This probably is something basic that I am too tired to see but what?
python -V
Python 3.4.3
python3 -V
Python 3.4.3
python3.4 -V
Python 3.4.3
When looking into python-v, django import work no problem.
Django 2.1 is not supported on Python 3.4 - only 3.5, 3.6, and 3.7.
Release notes: https://docs.djangoproject.com/en/2.1/releases/2.1/
The python version you use is 3.4.3. But django==2.1 will install Django 2.1.
Django 2.1 supports Python 3.5, 3.6, and 3.7. Django 2.0 is the last version to support Python 3.4. We highly recommend and only officially support the latest release of each series.
Source Django 2.1 release notes
So, You need to install to resolve it
pip3 install Django==2.0.0

ImportError raised when trying to load 'rest_framework.templatetags.rest_framework': No module named urls

[INFO] oauth2client.client: Refreshing access_token
[ERROR] django.request: Internal Server Error: /
get_package_libraries
"trying to load '%s': %s" % (entry[1], e)
InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'rest_framework.templatetags.rest_framework': No module named urls
This is a python 2.7 project. Django version 1.9
Django Rest Framework 3.7 dropped support for Django 1.9.
Django 1.9 is end of life and does not get security fixes. You should really update to the current release 2.0 (requires Python 3) or the 1.11 LTS (supports Python 3 and Python 2).
If you must use Django 1.9, then you'll need to use an earlier version of rest framework.

Categories