在virtualenv中运行Django项目时出错

时间:2014-03-03 07:32:09

标签: python django

我有一个django项目,没有virtualenv工作正常。但现在我把它放在virtualenv中并且它没有运行。 没有virtualenv:

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

这很好用。 有了virtualenv,当我做同样的事情,我得到:

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

当我尝试在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..

我做错了什么?

2 个答案:

答案 0 :(得分:1)

使用sudo将强制所有内容全局安装,virtualenv 解决该问题的解决方案。它允许您创建具有自己独立安装的软件包的虚拟环境,因此您可以避免全局安装所有内容。

重新创建virtualenv,使用pip install packagename安装所有需要的软件包,然后您就可以运行了。

答案 1 :(得分:0)

查看输出的最后一行:你在某处某处芹菜,似乎没有安装在你的virtualenv中。