Can't import Celery modules - django

I have a weird problem, I successful installed celery, but I can't import its modules:
>>> import celery # OK
>>> import djcelery
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/django_celery-2.5.5-py2.7.egg/djcelery/__init__.py", line 25, in <module>
from celery import current_app as celery # noqa
ImportError: cannot import name current_app
>>> from celery.decorators import task
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named decorators
this error occurs on celery 2.6.0a3 (from github) or 2.5.3 (from pypi) and django-celery 2.5.5. Tried re-installing several times, and even tried in Jython and I got the same error.
I have no clue what it is, can anyone help me out?

honestly, there is a better answer, which I wrote about here.
It's gotta do with a mismatch between your system python (and particularly, with the python standard lib "os") and your precompiled virtualenv python binary.
Deactivating virtualenv, deleting your virtualenv python binary, and then running the virtualenv script on the same virtualenv folder will recompile python for your virtualenv and fix the issue.

well cloned the project (celery) from github, and a python setup.py install resolved. Weird that it couldn't import its modules when installed via pip in my machine (even when /Library/Python/2.7/site-packages/celery/decorators.py task was there).
Hope it helps someone.

Related

After installing spyder django is not working

I installed spyder on my ubuntu system From which django is not working. The error it is showing when i ran the server the error showing is is
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
import django
ModuleNotFoundError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 17, in <module>
"Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
I need both spyder for OpenCV and also Django. can anyone help
It is working after doing
python3 -m pip install django
thank u mr sahil
The error means that the Django is missing from your system, if you have installed the dependencies in your virtualenv you will need to activate that, or you can just do
pip install django --user
If you have a virtualenv do this,
Linux
source path/to/venv/bin/activate
Windows
path/to/venv/bin/activate
First create a virtual environment, using the following command
python3 -m virtualenv venv
If you get an error saying something similar to this, Virtualenv module not found, you will need to install virtualenv using pip by the following command.
pip3 install virtualenv
Then use the aforementioned command to create the virtual environment.
To activate it just use
source venv/bin/activate
This will activate the virtual environment. Now install Django on it.
pip install django
You don't need to specify a pip version (say pip3) because the virtual environment is created in python3 so pip defaults to pip3 itself.
Now finally run your server
python manage.py runserver localhost:8080

pip: ImportError: No module named retrying

I'm trying to create a new environment and install various 3rd party packages on an Ubuntu machine. After having to install condo (for a matplotlib installation) and gdal, the pip function no longer works. Instead I receive:
Traceback (most recent call last):
File "/media/imagery/ENVIRONMENTS/Project_1/bin/pip", line 7, in <module>
from pip._internal import main
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 14, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/usr/lib/python2.7/dist-packages/pip/utils/__init__.py", line 30, in <module>
from pip._vendor.retrying import retry
ImportError: No module named retrying
I've called pip both in and outside my environment, and still observe the same issue. Also I've tried a pip install --upgrade pip and still retrieve the same Traceback. Any ideas how to resolve this?
As a cheap workaround, export PYTHONPATH=" " seemed to work for now in order to install other packages, but as soon as I need the gdal package, I have to then set PYTHONPATH again.
I had a similar exception and could manage to repair it.
In my case I upgraded Ubuntu 16.04 to Ubuntu 18.04.
I had to re-create the virtualenv. Depending on your choice:
virtualenv .
Or
virtualenv --system-site-packages .

Why do I get "ImportError: cannot import name find_spec" when I start a new Django project?

I'm learning Python in tandem with Django. I initially installed Python 3 on my machine (Debian Wheezy), but read about possible conflicts and removed it with some difficulty.
Now I'm using virtualenv and installed python3 within the env and Django using pip. Django and Python seem to have installed correctly:
# python -c "import django; print(django.get_version())"
1.9.1
# python -V
Python 3.2.3`
but when I try to start a new Django project, I get the following:
# django-admin.py startproject mysite
Traceback (most recent call last):
File "/home/rialaado/Projects/webenv/bin/django-admin.py", line 2, in <module>
from django.core import management
File "/home/rialaado/Projects/webenv/lib/python3.2/site-packages/django/core/management/__init__.py", line 10, in <module>
from django.apps import apps
File "/home/rialaado/Projects/webenv/lib/python3.2/site-packages/django/apps/__init__.py", line 1, in <module>
from .config import AppConfig
File "/home/rialaado/Projects/webenv/lib/python3.2/site-packages/django/apps/config.py", line 6, in <module>
from django.utils.module_loading import module_has_submodule
File "/home/rialaado/Projects/webenv/lib/python3.2/site-packages/django/utils/module_loading.py", line 67, in <module>
from importlib.util import find_spec as importlib_find
ImportError: cannot import name find_spec
A quick google turned up no results that would help me.
What should I do?
find_spec isn't available in Python 3.2.3; it was added in Python 3.4.
Try upgrading to 3.4 or later.
The version of Django you're using (v1.9.1) cannot be used with Python 3.2. Hence, #KarthiG and #MUNGAI NJOROGE are correct, and now you know why.
What Python version can I use with Django?
I got the same problem with docker containers.
find_spec is not available when using Docker containers and django 1.9 and python:3.3 dependency.
Adding the line below in your docker image as a dependency works.
FROM python:3.4

ImportError: No module named django.core.management [duplicate]

Upgrade to 13.04 has totally messed my system up .
I am having this issue when running
./manage.py runserver
Traceback (most recent call last):
File "./manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
File "/home/rats/rats/local/lib/python2.7/site-packages/django/core/management
/__init__.py", line 4, in <module>
from optparse import OptionParser, NO_DEFAULT
File "/usr/lib/python2.7/optparse.py", line 77, in <module>
import textwrap
File "/usr/lib/python2.7/textwrap.py", line 10, in <module>
import string, re
File "/usr/lib/python2.7/string.py", line 83, in <module>
import re as _re
File "/home/rats/rats/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/home/rats/rats/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/home/rats/rats/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/home/rats/rats/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
this is happening for both the real environment as well as for virtual environment .
i tried removing python with
sudo apt-get remove python
and sadly it has removed everything .
now google chrome does not show any fonts .
i am looking for getting things back to work .
help is needed for proper configuring it again.
If you are using virtualenvwrapper then you can recreate the virtualenv on top of the existing one (with no environment currently active):
mkvirtualenv <existing name>
which should pull in the latest (upgraded) python version from the system and fix any mismatch errors.
You don't need to recreate the environment.
You can upgrade the virtualenv running this command:
virtualenv /PATH/TO/YOUR_OLD_ENV
YOUR_OLD_ENV folder will be properly upgraded to the version 2.7.4.
I have just solved that problem on my machine.
The problem was that Ubuntu 13.04 use python 2.7.4. That makes conflict with the Python version of the virtualenv.
What I do was to re-create the virtualenv with the new version of python. I think it's the simplest way, but you can try to upgrade the python version without re-creating all of the virtualenv.

settings import error in django using virtualenv

I am using ubuntu 12.04.I am using virtualenv and on that I installed all the packages those I required.When I run the project it gives me error but when I run another project it works.
I am using python2.6.8 and django 1.3.1
Traceback (most recent call last):
File "manage.py", line 4, in
import settings # Assumed to be in the same directory.
Any help will be appreciated.
Thanks in advance.
Try to Import settings.py in python shell, there it will give you the exact error. I think you import some other modules in settings.py those giving you ImportError.