Virtualenvironment Ubuntu 12 ImportError: No modul

2019-02-25 15:54发布

问题:

I can create a project with django-admin.py startproject within a virtualenv. But when I try to run server with python manage.py runserver, I get an error:

(check)robin@robin-VirtualBox:~/checking$ python manage.py runserver
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

But I can run the server when I deactivate the environment and run the it from the project directory. Please help how to solve this. Thank you.

(check)robin@robin-VirtualBox:~/checking$ pip freeze
argparse==1.2.1
wsgiref==0.1.2

回答1:

Most likely, you have not installed django in the virtual environment.

  • Either install django in virtual environment. Activate the environment and then install django using pip or other methods.

  • Or link/copy django installed on the system (somewhere in /usr/lib/python-XXX) to python site packages in the environment. No recommended.



回答2:

from the output of pip freeze you don't have Django installed in your virtual environment

run pip install django



回答3:

Maybe the Django has lost some plugin with pip, so we can install Django with Tarball:

  1. Go https://www.djangoproject.com/download/1.6.5/tarball/
  2. Download Django-*.tar.gz
  3. install it.

    $ tar zxvf Django-1.6.5.tar.gz

    $ cd Django-1.6.5/

    $ python setup.py install