简体   繁体   中英

ImportError: How to import django-nose package?

Installed django-nose in virtual environment:

(venv) user@~/../src$  pip install django-nose
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Requirement already satisfied: django-nose in /home/user/../venv/lib/python2.7/site-packages (1.4.6)
Requirement already satisfied: nose>=1.2.1 in /home/user/../venv/lib/python2.7/site-packages (from django-nose) (1.3.7)
(venv) user@~/../src$ 

Django settings in test.py has django-nose package mentioned as INSTALLED_APPS , shown below:

from base import *
import os


# Installed apps
INSTALLED_APPS += ('django-nose', )
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
TEST_OUTPUT_DIR = os.environ.get('TEST_OUTPUT_DIR', '.')
NOSE_ARGS = [
    '--verbosity=2',
    '--nologcapture',
    '--with-coverage',
    '--cover-package=todo',
    '--with-spec',
    '--spec-color',
    '--with-xunit',
    '--xunit-file=%s/unittests.xml' % TEST_OUTPUT_DIR,
    '--cover-xml',
    '--cover-xml-file=%s/coverage.xml' % TEST_OUTPUT_DIR,  
]

# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
    'default':{
        'ENGINE': 'django.db.backends.mysql',
        'NAME': os.environ.get('MYSQL_DATABASE', 'xxxxx'),
        'USER': os.environ.get('MYSQL_USER', 'xxx'),
        'PASSWORD': os.environ.get('MYSQL_PASSWORD', 'xxx'),
        'HOST': os.environ.get('MYSQL_HOST', 'localhost'),
        'PORT': os.environ.get('MYSQL_PORT', '3306')
    }
}

But django-nose package is not getting imported, based on below error:

(venv) user@~/../src$ ls
db.sqlite3  manage.py  todo  todobackend
(venv) user@~/../src$
(venv) user@~/../src$
(venv) user@~/../src$ python manage.py test --settings=todobackend.settings.test
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/user/../venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/home/user/../venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 324, in execute
    django.setup()
  File "/home/user/../venv/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/user/../venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/home/user/../venv/local/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named django-nose

Why django-nose package is not recognised as installed?

As shown in the TEST_RUNNER setting, the Python package is django_nose ; that's what you need to use in INSTALLED_APPS rather than django-nose . (Package names must be valid Python identifiers, so they can't contain - .)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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