简体   繁体   English

在virtualenv中运行Django项目时出错

[英]Error running Django project in virtualenv

I have a django project which works fine without virtualenv. 我有一个django项目,无需virtualenv即可正常工作。 But now I'm putting it in a virtualenv and it doesn't run. 但是现在我将其放在virtualenv中,并且它没有运行。 Without virtualenv: 如果没有virtualenv:

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

This works fine. 这很好。 With virtualenv when I do the same as above I get: 使用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

This is what comes when I try installing celery in the virtualenv: 这是当我尝试在virtualenv中安装celery时出现的情况:

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? 我究竟做错了什么?

Using sudo will force everything to install globally, and virtualenv is the solution to that problem. 使用sudo将强制所有内容全局安装,而virtualenv是解决此问题的方法。 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. 重新创建virtualenv,使用pip install packagename安装所有需要的软件包,您应该已启动并正在运行。

参见输出的最后一行:您在某处芹菜,似乎未安装在virtualenv中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM