无法在virtualenv

时间:2015-11-09 19:33:17

标签: django python-3.x virtualenv

尝试使用命令django-admin.y startapp时,我一直收到导入错误消息。问题是,只有当我在我的virtualenv时才会出现问题。错误消息是:

  File "/Users/Opare/.virtualenvs/p2_dev/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/Users/Opare/.virtualenvs/p2_dev/lib/python3.4/site-     packages/django/core/management/__init__.py", line 354, in       execute_from_command_line
utility.execute()
  File "/Users/Opare/.virtualenvs/p2_dev/lib/python3.4/site-  packages/django/core/management/__init__.py", line 303, in execute
    settings.INSTALLED_APPS
  File "/Users/Opare/.virtualenvs/p2_dev/lib/python3.4/site-packages/django/conf/__init__.py", line 48, in __getattr__
    self._setup(name)
  File "/Users/Opare/.virtualenvs/p2_dev/lib/python3.4/site-  packages/django/conf/__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/Opare/.virtualenvs/p2_dev/lib/python3.4/site-  packages/django/conf/__init__.py", line 92, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/Users/Opare/.virtualenvs/p2_dev/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'p2'

安装应用设置:

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'movements',
'users')

1 个答案:

答案 0 :(得分:0)

您是否在程序中使用过p2模块? 也许你真正的python环境和virtualenv python有所不同。 我猜你忘了在virtualenv中安装p2_dev包。 修复p2_dev时可能还缺少另一个包依赖项。

所以,为安全起见,我有一个建议,你可以用(在windows中)启动virtualenv:

virtualenv --system-site-packages virtualenv_project

然后,你将使用真正的python在virtualenv中获得相同的包。