Django : Cannot Import name xrange - django

I am new to python and django. I had django running properly in my machine, till I installed django-haystack. I directly downloaded django-haystack.zip from github and executed 'python setup.py install' in haystack dir. After this whenever I run 'django-admin.py runserver' I am getting the following error : ImportError: cannot import name xrange.
If I remove 'haystack' from INSTALLED_APPS the above command is working fine.
I also cannot run 'python manage.py build_solr_schema' because of the same error.
Let me know how I can resolve this issue.

Solved the issue. Deleted the haystack installation from /usr/local/.../dist-packages/ and used pip install django-haystack to install. That worked fine

This:
http://pypi.python.org/pypi/haystack/
is not the same as this:
http://pypi.python.org/pypi/django-haystack
but if you have them both in your requirements.txt file for some reason, like so:
haystack
django-haystack
and install them into the same virtualenv then you will have problems because they both want to unpack to a directory named 'haystack'. 99% of the time if you're doing django development you don't want that first one at all. So remove it from the requirements.txt file, remove all traces of anything to do with haystack from your virtualenv and then reinstall with:
pip install -r requirements.txt
and you should be good to go.

if you have installed haystack and django-haystack, uninstall both haystacks and install django-haystack
pip uninstall haystack
pip uninstall django-haystack
pip install django-haystack

if you have it installed and still this error appears
uninstall haystack and reinstall it
pip uninstall haystack
#here ask for y/n type y :)
pip install haystack
that works for me

Related

django-admin startproject command returning bad interpreter: No such file or directory

I can create a project outside of a virtual environment just fine, but when I am using a venv and try to create a django project, I get the following:
/Users/justin/Desktop/Programming/Python/Django
Projects/env/bin/django-admin: "/Users/justin/
Desktop/Programming/Python/Django: bad interpreter: No such
file or directory
I created the venv with python3 -m venv env, I then tried to run pip install django where the above error also appeared, I then learned I should be using python3 -m pip install django (pip3: bad interpreter: No such file or directory) and this successfully installed django, but I still cannot start a project. I've ran pip install django and django-admin startproject from a venv many times without an issue so it seems like I broke something recently. Does anyone know how to fix this/where I can begin looking for the issue? Thanks for any help.
Save a copy of your project in another folder and Try again.
OR
Step First :- RUN - python -m venv env
Step Second :- pip install django
Step Third :- after that install pip
Step Fourth :- ( If your pip version is lower, then it may be issue after
some time and every time it will show the Warning: for upgrading the pip.
So if version is lower then USE ) python -m pip install -U pip

virtual env python 3.5 only finds django python 2.7

I have created python 3.5.2 virtual environment ("python --version" confirms that)
but when i try to install django using "pip install django~=1.10.0" I get this message:
Requirement already satisfied: django~=1.10.0 in /usr/local/lib/python2.7/dist-packages
How can I get django version that agrees with the python version in my venv?
Personally I use conda to manage environments and I'm not really familiar with virtualenv, but a few things to check.
I bet you need to use pip3 not pip (aka pip2) to install django that way it will be installed in your python 3 env.
Probabily you have already installed django outside the venv with python2.
just write see in the pip list if django is installed.
Then uninstall, enter in the venv and reinstall django with python3
Ok - so I figured out what happened. I have installed django using sudo pip install. Even though I was in the venv (created with python3) this has resulted in reference to django outside the venv. Sooo...it was an interesting thing to learn I guess.

Django 1.9 Compiling Error

I created a virtualenv and downloaded Django with the below commands:
virtualenv tester
source tester/bin/activate
pip install django
and below is the response:
Downloading/unpacking django
Downloading Django-1.9-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
Installing collected packages: django
Compiling /home/romaan/workspacepy/tester/build/django/django/conf/app_template/apps.py ...
File "/home/romaan/workspacepy/tester/build/django/django/conf/app_template/apps.py", line 4
class {{ camel_case_app_name }}Config(AppConfig):
^
SyntaxError: invalid syntax
Compiling /home/romaan/workspacepy/tester/build/django/django/conf/app_template/models.py ...
File "/home/romaan/workspacepy/tester/build/django/django/conf/app_template/models.py", line 1
{{ unicode_literals }}from django.db import models
^
SyntaxError: invalid syntax
Successfully installed django
Please help me to get rid of this error. All though it says Successfully installed django, I am keen on understanding and getting rid of this syntax error.
Or Should I just wait for the bug fix to happen?
This looks like the setuptools issue mentioned in the Django 1.9 release notes: https://docs.djangoproject.com/en/1.9/releases/1.9/#syntaxerror-when-installing-django-setuptools-5-5-x
Try to run pip install --upgrade pip before running pip install django
Those can't, and shouldn't, be fixed. Those are template files which are substituted at project creation time, and are not valid Python syntax. They shouldn't be compiled at install time but rather at project creation time.
These steps worked for me:
$ sudo python -m pip install --upgrade --force setuptools
$ sudo python -m pip install --upgrade --force pip
$ sudo pip install django==1.9
pip install -U pip ran fine but didn't fix my issue
I got the same message when I was trying pip install django.
I thought to try a previous version so I tried pip install
django-1.9.
It said "Real name of requirement Django-1.9 is django-503".
So pip install Django-503 worked fine for me.

How to install Django on different version of PYTHON?

I have two python versions 2.6 and 3.0. I want to install django1.3 in python3.0's site-package directory and my default python setting is on 2.6. I also added path /usr/local/bin/python3.0 and /usr/local/bin/python3.0 into .bashrc file.
Please help me.
Django is not compatible with Python 3. You must install it in the 2.X branch.
However, what you want to achive will be easier done using virtualenv:
easy_install virtualenv
virtualenv project --python=python2.6
source project/bin/activate
pip install django
Django doesn't yet work with python3.0. So it is better you install it on the python2.6 dist-packages folder.
That said, if you had python2.7 and wanted to install django on python 2.7, while the better approach is to use virtualenv, a simple solution is to:
python2.7 setup.py install
or
easy_install2.7 django
or
/path/to/python2.7/dist-packages/pip/pip install django
easy_install virtualenv
pip install django
Sudo pip install django
Seemed to work for me!
by using pip install django --> it installs the latest version of django.
https://technicalforum.wordpress.com/2016/12/17/introduction-to-django/

Pip with virtualenv not upgrading Django

I'm using pip with virtualenv --no-site-packages --distribute and am trying to upgrade Django. pip install -U Django should upgrade it according to the docs I found. However, it simply finds the current Django installation and stops.
Ideally, I would like to be able to specify the version I want to upgrade to. Currently, I'm stuck with modifying the requirements file, then blowing over the old virtualenv and starting a new one. However, I'd be happy just getting pip install -U to upgrade to latest version.
Check your build/ directory in your virtualenv path. Delete the Django/ dir there and try to run pip install --upgrade django again.