importError: Count Not import Django inside Virtualenv

1,721 views
Skip to first unread message

tango ward

unread,
Feb 13, 2018, 3:44:42 PM2/13/18
to django...@googlegroups.com
Hi,

I want to seek some advice about the error. All of my pet projects in my desktop are getting the same error even though virtualenv is activated. I can confirm that when I started playing around with the projects, I have installed Django inside virtualenv without using "sudo". Now, I can't run python manage.py runserver and the packages that I am getting whenever I run pip freeze are different from before which doesn't include Django in the list.


Any advice pls?


Thanks,
Jarvis

Jason

unread,
Feb 13, 2018, 5:53:04 PM2/13/18
to Django users
if pip freeze doesn't include django in the output, then the django package is not installed in the virtualenv.  are you sure the virtualenv was active when you installed django?

also, remember that if you installed latest django, eg pip install django, it won't install for python2 venvs.

PASCUAL Eric

unread,
Feb 13, 2018, 7:17:26 PM2/13/18
to django...@googlegroups.com

Hi Jarvis,


Can you provide the error messages trace ? It can greatly help understanding what's happening.


If you haven't already done this, try to restart from a fresh new virtualenv inside which you'll install Django and the additional packages you've added (if any). Then restore a copy of your project in this context (if by chance you work with git, a simple git clone will do the trick) and test your app again.


Hoping you haven't already messed your system Python by installing stuff in sudo mode. The situation could be a little more complicated then.


Best.


Eric

From: django...@googlegroups.com <django...@googlegroups.com> on behalf of tango ward <tango...@gmail.com>
Sent: Tuesday, February 13, 2018 9:43:45 PM
To: django...@googlegroups.com
Subject: importError: Count Not import Django inside Virtualenv
 
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

tango ward

unread,
Feb 13, 2018, 9:14:29 PM2/13/18
to django...@googlegroups.com
Hi,

The error message that I am getting 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'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    ) from exc
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?


@Jason,

It's weird because couple of days, I can still run these pet projects without any error. If I go to venv folder virtual/lib/python3.6/site-packages, I can see django there. It seems that even though virtualenv is activated, the packages I installed inside it are not recognized by the system.


On Wed, Feb 14, 2018 at 5:38 AM, PASCUAL Eric <eric.p...@cstb.fr> wrote:

Hi Jarvis,


Can you provide the error messages trace ? It can greatly help understanding what's happening.


If you haven't already done this, try to restart from a fresh new virtualenv inside which you'll install Django and the additional packages you've added (if any). Then restore a copy of your project in this context (if by chance you work with git, a simple git clone will do the trick) and test your app again.


Hoping you haven't already messed your system Python by installing stuff in sudo mode. The situation could be a little more complicated then.


Best.


Eric

From: django...@googlegroups.com <django...@googlegroups.com> on behalf of tango ward <tango...@gmail.com>
Sent: Tuesday, February 13, 2018 9:43:45 PM
To: django...@googlegroups.com
Subject: importError: Count Not import Django inside Virtualenv
 
Hi,

I want to seek some advice about the error. All of my pet projects in my desktop are getting the same error even though virtualenv is activated. I can confirm that when I started playing around with the projects, I have installed Django inside virtualenv without using "sudo". Now, I can't run python manage.py runserver and the packages that I am getting whenever I run pip freeze are different from before which doesn't include Django in the list.


Any advice pls?


Thanks,
Jarvis

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

tango ward

unread,
Feb 13, 2018, 9:40:44 PM2/13/18
to django...@googlegroups.com
Hi Eric,


I tried what you suggested and it works! I was just wondering why my existing pet projects have the same problem?

PASCUAL Eric

unread,
Feb 14, 2018, 3:45:30 AM2/14/18
to django...@googlegroups.com

Hi,


Hard to say without knowing the exact context, but my gut feeling is that you've modified a system wide library at a moment (maybe inadvertently).


My own experience is that it's easy to mess with Python libraries when installing packages with sudo , which may happen form time to  time when working with virtualenv (or pyenv) since not very long, and being caught up by old habits (they tend to survive longer that wanted 😊).


Even if far less harmful, then --user option is to avoid for projects related libs, for the same reasons.


Eric

Sent: Wednesday, February 14, 2018 3:40:04 AM
To: django...@googlegroups.com
Subject: Re: importError: Count Not import Django inside Virtualenv
 
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

tango ward

unread,
Feb 14, 2018, 4:10:50 AM2/14/18
to django...@googlegroups.com
that's odd. Whenever I test a pacakge, it's always installed first in virtualenv. Maybe when I updated my system? Btw, I have some projects which are not yet in github, can I just copy and paste them in a new folder with new virtualenv?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Etienne Robillard

unread,
Feb 14, 2018, 5:09:03 AM2/14/18
to PASCUAL Eric, django...@googlegroups.com

Hi Eric,


Le 2018-02-14 à 03:44, PASCUAL Eric a écrit :

Hi,


Hard to say without knowing the exact context, but my gut feeling is that you've modified a system wide library at a moment (maybe inadvertently).


My own experience is that it's easy to mess with Python libraries when installing packages with sudo , which may happen form time to  time when working with virtualenv (or pyenv) since not very long, and being caught up by old habits (they tend to survive longer that wanted 😊).


I prefer messing with standard distutils/setuptools commands to avoid situations like this... ;-)

Cheers,
Etienne



For more options, visit https://groups.google.com/d/optout.

PASCUAL Eric

unread,
Feb 14, 2018, 6:30:44 AM2/14/18
to django...@googlegroups.com

Hi,


The copy/paste of the project tree will work of course. Chances are that unwanted files can be brought too, but this should not be a problem in a first stage.


I have used rsync or tar archives to deploy Django projects in some cases, and it worked fine.  


Eric


Sent: Wednesday, February 14, 2018 10:09:51 AM
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

PASCUAL Eric

unread,
Feb 14, 2018, 6:33:24 AM2/14/18
to Etienne Robillard, django...@googlegroups.com

Hi Etienne,

I prefer messing with standard distutils/setuptools commands to avoid situations like this... ;-)

Messing and restoring system libs is a matter of personnal taste 😃


Eric


From: Etienne Robillard <tka...@yandex.com>
Sent: Wednesday, February 14, 2018 11:07:07 AM
To: PASCUAL Eric
Cc: django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages