Django 1.4 import error No module named apps - python-2.7

I am running a django app on Windows server 2008 R2(64 bit). The same app works fine on my other system which has windows 7 64 bit. I am actually trying to move the app to the other machine. I am using Python 2.7 and django 1.4. The manage.py runserver works fine and is able to start the server.
0 errors found
Django version 1.4, using settings 'checkmeout.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[11/Aug/2016 05:22:09] "GET /admin/ HTTP/1.1" 500 115256
While trying to access the admin page or any other url from http://127.0.0.1/8000,I am getting the following error.
ImportError at /admin/
No module named apps
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.4
Exception Type: ImportError
Exception Value:
No module named apps
Exception Location: C:\Python27\lib\site- packages\django_extensions\admin\__init__.py in <module>, line 10
Python Executable: C:\Python27\python.exe
Python Version: 2.7.5
Python Path:
['C:\\HardwareReservation\\checkmeout2',
'C:\\Windows\\system32\\python27.zip',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages',
'C:/SoftwareServices/checkmeout']
The output of pip freeze (on the system where it does not work) is put below in case that helps.
amqp==1.4.9
anyjson==0.3.3
billiard==3.3.0.23
celery==3.1.23
Django==1.4
django-apps==0.1.0
django-celery==3.1.17
django-extensions==1.7.1
djangorestframework==3.2.0
kombu==3.0.35
MySQL-python==1.2.4
pytz==2016.6.1
six==1.10.0
South==1.0.2
web.py==0.37
The pip freeze on the system where it works is below :
amqp==1.4.9
anyjson==0.3.3
billiard==3.3.0.23
celery==3.1.23
Django==1.4
django-celery==3.1.17
django-extensions==1.6.7
kombu==3.0.35
MySQL-python==1.2.5
pysphere==0.1.7
python-ldap==2.4.25
pytz==2016.4
six==1.10.0
South==1.0.2
virtualenv==15.0.2

I ran into a similar problem. Try installing the older version of django-extensions that worked:
pip install django-extensions=="1.6.7"

Related

pip could not find a version that satisfies the requirement django==2.2.1

I just have changed my os to linux and I want to install django.
But I am unable to install the latest version of django.
I have tried
pip install django However it installed django 1.11.11 which is not what I need.
I also upgraded my pip to 19.1
However still I am unable to run the command pip install django==2.2.1
When I run the command this is what I see
$ pip install django==2.2.1
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting django==2.2.1
ERROR: Could not find a version that satisfies the requirement django==2.2.1 (from versions: 1.1.3, 1.1.4, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.2.6, 1.2.7, 1.3, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.3.7, 1.4, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.4.8, 1.4.9, 1.4.10, 1.4.11, 1.4.12, 1.4.13, 1.4.14, 1.4.15, 1.4.16, 1.4.17, 1.4.18, 1.4.19, 1.4.20, 1.4.21, 1.4.22, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.5.6, 1.5.7, 1.5.8, 1.5.9, 1.5.10, 1.5.11, 1.5.12, 1.6, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.6.8, 1.6.9, 1.6.10, 1.6.11, 1.7, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.7.9, 1.7.10, 1.7.11, 1.8a1, 1.8b1, 1.8b2, 1.8rc1, 1.8, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.8.10, 1.8.11, 1.8.12, 1.8.13, 1.8.14, 1.8.15, 1.8.16, 1.8.17, 1.8.18, 1.8.19, 1.9a1, 1.9b1, 1.9rc1, 1.9rc2, 1.9, 1.9.1, 1.9.2, 1.9.3, 1.9.4, 1.9.5, 1.9.6, 1.9.7, 1.9.8, 1.9.9, 1.9.10, 1.9.11, 1.9.12, 1.9.13, 1.10a1, 1.10b1, 1.10rc1, 1.10, 1.10.1, 1.10.2, 1.10.3, 1.10.4, 1.10.5, 1.10.6, 1.10.7, 1.10.8, 1.11a1, 1.11b1, 1.11rc1, 1.11, 1.11.1, 1.11.2, 1.11.3, 1.11.4, 1.11.5, 1.11.6, 1.11.7, 1.11.8, 1.11.9, 1.11.10, 1.11.11, 1.11.12, 1.11.13, 1.11.14, 1.11.15, 1.11.16, 1.11.17, 1.11.18, 1.11.20)
ERROR: No matching distribution found for django==2.2.1
Django versions 2 are compatible only with python3. So to install in your system install it with
pip3 install django
or if you want to create a virtual environment
python3 -m venv virtualenv
source virtualenv/bin/activate
pip install django (this installs with python3 pip)
It seems like you are using Python 2.7, and the last Django version to support Python 2 is Django 1.11. To use the newer Django versions you need to uprade to Python 3.
Chances are you already have Python 3 shipped with your Linux distro, you can check by running python3 in your shell. It is recommended that you create a virtual env for your project. You can create a Python 3 virtual env with the following command -
python3 -m venv env
Activate your env -
source ./env/bin/activate
Now you should be able to install newer Django version in your virtual env -
pip install django==2.2.1
This link might be of help in upgrading your Python version - https://docs.python-guide.org/starting/install3/linux/
Try with pip install -U django==2.2.1
If you are in Windows and the error mentions something like:
... Connection aborted.', PermissionError ...
Make sure you open the CMD with "Run as Administrator"

Virtual environment not recognized in WSGIPythonPath

I'm trying to set up my Django project in production by using a virtual environment, using the documentation:
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi/#using-a-virtualenv
So, in my configuration I have:
WSGIPythonPath /srv/zboss/zboss:/srv/zboss/venv/lib/python3.4/site-packages
I restart Apache and I get the following error:
Internal Server Error: /prot/
InvalidTemplateLibrary at /
Invalid template library specified. ImportError raised when trying to load 'core.templatetags.wiki_formatter': No module named parse
Request Method: GET
Request URL: http://babylon/prot/
Django Version: 1.10.1
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path: ['/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/srv/zboss/zboss']
However the error is something because that library is not used anymore in Python3. I see the python path and no trace of my virtual environment directory.
Your mod_wsgi is compiled for Python 2.7. You cannot point it at a virtual environment for Python 3.4. You must uninstall mod_wsgi and install a mod_wsgi version built for Python 3.4, the same version as your virtual environment.

How: django_manage in ansible with Python3

I'm following this for django manage.py module
http://docs.ansible.com/django_manage_module.html
for e.g. one of my tasks looks like -
- name: Django migrate
django_manage: command=migrate
app_path={{app_path}}
settings={{django_settings}}
tags:
- django
this works perfectly fine with python2(default in ubuntu) but when I try with python3-django project it throws error
failed: [123.456.200.000] => (item=school) => {"cmd": "python manage.py makemigrations --noinput school --settings=myproj.settings.production", "failed": true, "item": "school", "path": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games", "state": "absent", "syspath": ["/home/ubuntu/.ansible/tmp/ansible-tmp-1432039779.41-30449122707918", "/usr/lib/python2.7", "/usr/lib/python2.7/plat-x86_64-linux-gnu", "/usr/lib/python2.7/lib-tk", "/usr/lib/python2.7/lib-old", "/usr/lib/python2.7/lib-dynload", "/usr/local/lib/python2.7/dist-packages", "/usr/lib/python2.7/dist-packages"]}
msg:
:stderr: Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
from this error it seems Ansible bydefault uses Python2. can we change this to python3 or anyother workaround?
PS: pip freeze ensure that django 1.8 has installed (for python3 using pip3)
Suggestions:
when I run ubuntu#ubuntu:/srv/myproj$ python3 manage.py migrate it works fine. so I'm thinking of passing command directly
something like
- name: Django migrate
command: python3 manage.py migrate
tags:
- django
but how do I pass the project path or manage.py file's path, there is only an option to pass settings, something like --settings=myproject.settings.main.
can we do by passing direct command?
From Ansible website http://docs.ansible.com/intro_installation.html
Python 3 is a slightly different language than Python 2 and most Python programs (including Ansible) are not switching over yet. However, some Linux distributions (Gentoo, Arch) may not have a Python 2.X interpreter installed by default. On those systems, you should install one, and set the ‘ansible_python_interpreter’ variable in inventory (see Inventory) to point at your 2.X Python. Distributions like Red Hat Enterprise Linux, CentOS, Fedora, and Ubuntu all have a 2.X interpreter installed by default and this does not apply to those distributions. This is also true of nearly all Unix systems. If you need to bootstrap these remote systems by installing Python 2.X, using the ‘raw’ module will be able to do it remotely.
If you edit the shebang in the Django manage.py file to be #!/usr/bin/env python3 then you can ensure that python 3 will always be used to run your Django app.
Tried successfully with Ansible 2.3.0 and Django 1.10.5. YMMV
Ansible is using python to run the django command: https://github.com/ansible/ansible-modules-core/blob/devel/web_infrastructure/django_manage.py#L237
Your only solution is thus to override the executable that will be run, for instance by changing your PATH:
- file: src=/usr/bin/python3 dest=/home/user/.local/bin/python state=link
- name: Django migrate
django_manage: command=migrate
app_path={{app_path}}
settings={{django_settings}}
environment:
- PATH: "/home/user/.local/bin/:/bin:/usr/bin:/usr/local/bin"

running django python 3.4 on mod_wsgi with apache2

Hi I am getting the error below when going to the website url on ubuntu server 14.10 running apache 2 with mod_wsgi and python on django.
My django application uses python 3.4 but it seems to be defaulting to python 2.7, I am unable to import image from PIL and AES from pycrypto.
ImportError at / cannot import name _imaging Request
Method: GET Request URL: Django Version: 1.7.3
Exception Type: ImportError Exception Value: cannot import
name _imaging Exception
Location: /usr/local/lib/python3.4/dist-packages/PIL/Image.py in
, line 63 Python Executable: /usr/bin/python Python
Version: 2.7.6 Python Path: ['/var/www/blabla',
'/usr/local/lib/python3.4/dist-packages',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages', '/var/www/blabla',
'/usr/local/lib/python3.4/dist-packages']
I believe that mod_wsgi is compiled against a specific version of python, so you need a py3.4 version of mod_wsgi. You may be able to get one from your os's package repository or you can build one without too much drama. From memory you'll need gcc and python-dev packages (python3-dev?) to build.
OK, quick google, for ubuntu 14.10: sudo apt-get install libapache2-mod-wsgi-py3 should install a py3 version of mod_wsgi (will probably want to remove the existing py2 version).
Adding a shebang line won't do any good as the python interpreter is already loaded before the wsgi.py script is read.
From what I see here your application is using py2 interpreter with py3 compiled modules, which is no-go.
One simple possible solution that comes me in mind is to add or change first line of manage.py to #!/usr/bin/python3. This will tell script to be interpreted with py3.
Next on guess list would be misconfiguration in *.wsgi file or apache config, whichever you are using.
Thanks guys,
I actually fixed the issue myself this morning by running the make install of mod_wsgi with .configure pointing to python3.4.
I think you were right Adam.

Django not loading Module Pycrypto into model, will load into shell

I am using a Virtualenv on my Django install and have loaded in Pycrypto using
pip install pycrypto
after sourcing my environment.
When I try to import Crypto into my model, I get an import error, however if load the shell using
manage.py shell
it does load in, with out an issue.
I am pretty sure that django is running from the virtualenv as is it running 1.3.1 which more current than what is installed on the path and I have installed South via pip which is working.
I have also tried to install Pycrypto using
setup.py install
Any thoughts on how I fix/debug this?
Thanks
Edit:
I am relatively new to Django and Python so it could be something simple
Edit 2:
Hey Issac,
Is there any way that you can find all the modules getting loaded in?
I don't understand why it wouldn't work in browser but would work in the interactive shell? I am not saying that it can't, i just don't know if/how that could happen.
The import error as requested:
ImportError at /
No module named Crypto
Request Method: GET
Request URL: http://*/
Django Version: 1.3.1
Exception Type: ImportError
Exception Value:
No module named Crypto
Exception Location: /home/*************/project/app/models.py in <module>, line 1
Python Executable: /home/*************/env/bin/python
Python Version: 2.6.6
Python Path:
['/usr/local/dh/passenger/lib/phusion_passenger/wsgi',
'/home/*************/env/lib/python2.6/site-packages/distribute-0.6.10-py2.6.egg',
'/home/*************/env/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg',
'/home/*************/env/src/django-debug-toolbar',
'/home/*************/env/lib/python2.6',
'/home/*************/env/lib/python2.6/plat-linux2',
'/home/*************/env/lib/python2.6/lib-tk',
'/home/*************/env/lib/python2.6/lib-old',
'/home/*************/env/lib/python2.6/lib-dynload',
'/usr/lib/python2.6',
'/usr/lib64/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib64/python2.6/lib-tk',
'/home/*************/env/lib/python2.6/site-packages',
'/home/*************',
'/home/*************/project']
Server time: Tue, 3 Jan 2012 20:08:19 +1100
Just before the line which causes the import error insert this code:
import sys
assert False, sys.path
Compare both results.
In the shell (where you can import the module). You can do this:
import Crypto
assert False, Crypto.__file__
Is the directory of this result in sys.path of your webserver?