Error running Django project in virtualenv
Question: I have a django project which works fine without virtualenv. But now I'm
putting it in a virtualenv and it doesn't run. Without virtualenv:

    
    
    python manage.py runserver --settings=Janta.settings.local
    

This works fine. With virtualenv when I do the same as above I get:

    
    
    Traceback (most recent call last):
      File "manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File "/home/moni/.virtualenvs/janta_proj/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
        utility.execute()
      File "/home/moni/.virtualenvs/janta_proj/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/home/moni/.virtualenvs/janta_proj/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
        commands = get_commands()
      File "/home/moni/.virtualenvs/janta_proj/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
        apps = settings.INSTALLED_APPS
      File "/home/mon/.virtualenvs/janta_proj/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
        self._setup(name)
      File "/home/mon/.virtualenvs/janta_proj/local/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
        self._wrapped = Settings(settings_module)
      File "/home/moni/.virtualenvs/janta_proj/local/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
        % (self.SETTINGS_MODULE, e)
    ImportError: Could not import settings 'Janta.settings.local' (Is it on sys.path? Is there an import error in the settings file?): No module named celery
    

This is what comes when I try installing celery in the virtualenv:

    
    
    Requirement already satisfied (use --upgrade to upgrade): Celery in /usr/local/lib/python2.7/dist-packages
    Requirement already satisfied (use --upgrade to upgrade): pytz>dev in /usr/local/lib/python2.7/dist-packages (from Celery)
    Requirement already satisfied (use --upgrade to upgrade): billiard>=3.3.0.13,<3.4 in /usr/local/lib/python2.7/dist-packages (from Celery)
    Requirement already satisfied (use --upgrade to upgrade): kombu>=3.0.8,<4.0 in /usr/local/lib/python2.7/dist-packages (from Celery)
    Requirement already satisfied (use --upgrade to upgrade): anyjson>=0.3.3 in /usr/local/lib/python2.7/dist-packages (from kombu>=3.0.8,<4.0->Celery)
    Requirement already satisfied (use --upgrade to upgrade): amqp>=1.4.0,<2.0 in /usr/local/lib/python2.7/dist-packages (from kombu>=3.0.8,<4.0->Celery)
    Cleaning up..
    

What am I doing wrong?


Answer: Using `sudo` will force everything to install globally, and virtualenv is _the
solution_ to that problem. It allows you to create virtual environments which
have their own independently installed packages, so you can avoid having
everything installed globally.

Recreate the virtualenv, install all of your needed packages using `pip
install packagename` and you should be up and running.

