ImportError: No module named blog

�ο���һ������ͬ����������ϸ��װ���

http://blog.csdn.net/jeffreynicole/article/details/8280358

ժҪ��

������python��2.7.9 ��django��1.7.1

�龰����һ�����ҵİ������ϵ�ECS�ϰ�װDjango�����ҽ�����һ��APP��blog�������̳��ֵĴ����У�ImportError: No module named blog  blogģ���Ҳ�����������Ϊ��������ʹ�õ�django��1.7.1�汾 �� ��django1.4֮��ʹ��django����һ��project��Ȼ���ڴ���һ��APP��Ŀ¼�ṹ�͸ı��ˣ�

django1.4��ֻ��һ��Ŀ¼

django1.7.1��������ϸ����




[root@iZ28cumdzmgZ muahao01]# vim settings.py
������ע�ͣ�
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


���?ImportError: No module named blog

������

�Ҵ���һ��project:muahao01

����һ���ļ���һ��Ŀ¼��

[root@iZ28cumdzmgZ muahao01]# ls
manage.py  muahao01��Ŀ¼��
������muahao01�����Ŀ�°�װһ��blog APP;

��������runserver��ʱ�?

���?�Ҳ���blog���ģ��

[root@iZ28cumdzmgZ muahao01]# python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/apps/config.py", line 87, in create
    module = import_module(entry)
  File "/usr/local/python2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named blog



�����������ԭ����# django-admin.py startapp blog���������Ҫ��/root/muahao01���Ŀ¼����ִ�У��������ұ����ԭ��������/root/muahao01/muahao01���Ŀ¼����ִ���ˣ�Ҳ����˵��# django-admin.py startapp blog�����blogĿ¼��Ҫ��manage.pyͬ��Ŀ¼����


[root@iZ28cumdzmgZ muahao01]# pwd
/root/muahao01
[root@iZ28cumdzmgZ muahao01]# ls        #�������Ŀ¼�£�����app  blog
manage.py  muahao01
[root@iZ28cumdzmgZ muahao01]# django-admin.py startapp blog
[root@iZ28cumdzmgZ muahao01]# tree
.
|-- blog
|   |-- __init__.py
|   |-- admin.py
|   |-- migrations
|   |   `-- __init__.py
|   |-- models.py
|   |-- tests.py
|   `-- views.py
|-- manage.py
`-- muahao01
    |-- __init__.py
    |-- __init__.pyc
    |-- settings.py
    |-- settings.pyc
    |-- urls.py
    |-- wsgi.py
    `-- wsgi.pyc
[root@iZ28cumdzmgZ muahao01]# python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
December 22, 2014 - 10:55:14
Django version 1.7.1, using settings 'muahao01.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.




������������settting.py�У�����ݿ�����ע���ˣ���Ҫ����Ϊ����û�а�װsqlite3��

���潫��ݿ��

[root@iZ28cumdzmgZ muahao01]# vim settings.py

������ע��ȡ��

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


���?


����runserver������û���ҵ�sqlite3

[root@iZ28cumdzmgZ muahao01]# python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/python2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/contrib/auth/models.py", line 40, in <module>
    class Permission(models.Model):
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/models/base.py", line 124, in __new__
    new_class.add_to_class('_meta', Options(meta, **kwargs))
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/models/base.py", line 299, in add_to_class
    value.contribute_to_class(cls, name)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/models/options.py", line 166, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/__init__.py", line 40, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/utils.py", line 242, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/utils.py", line 108, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/local/python2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 38, in <module>
    raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3




���أ�pysqlite 2.6.3

https://pypi.python.org/pypi/pysqlite/

��װsqlite3ʱ���?

[root@iZ28cumdzmgZ pysqlite-2.6.3]# pwd
/usr/local/pysqlite/pysqlite-2.6.3
[root@iZ28cumdzmgZ pysqlite-2.6.3]# python setup.py install
running install
running build
running build_py
running build_ext
building 'pysqlite2._sqlite' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -DSQLITE_OMIT_LOAD_EXTENSION=1 -I/usr/local/pysqlite/pysqlite-2.6.3/include -I/usr/local/python2.7/include/python2.7 -c src/module.c -o build/temp.linux-x86_64-2.7/src/module.o
In file included from src/module.c:24:
src/connection.h:33:21: error: sqlite3.h: No such file or directory
In file included from src/module.c:24:
src/connection.h:38: error: expected specifier-qualifier-list before 'sqlite3'
In file included from src/module.c:25:
src/statement.h:37: error: expected specifier-qualifier-list before 'sqlite3'
src/module.c: In function 'module_complete':
src/module.c:103: warning: implicit declaration of function 'sqlite3_complete'
src/module.c: At top level:
src/module.c:269: error: 'SQLITE_OK' undeclared here (not in a function)
src/module.c:270: error: 'SQLITE_DENY' undeclared here (not in a function)
src/module.c:271: error: 'SQLITE_IGNORE' undeclared here (not in a function)
src/module.c:272: error: 'SQLITE_CREATE_INDEX' undeclared here (not in a function)
src/module.c:273: error: 'SQLITE_CREATE_TABLE' undeclared here (not in a function)
src/module.c:274: error: 'SQLITE_CREATE_TEMP_INDEX' undeclared here (not in a function)
src/module.c:275: error: 'SQLITE_CREATE_TEMP_TABLE' undeclared here (not in a function)
src/module.c:276: error: 'SQLITE_CREATE_TEMP_TRIGGER' undeclared here (not in a function)
src/module.c:277: error: 'SQLITE_CREATE_TEMP_VIEW' undeclared here (not in a function)
src/module.c:278: error: 'SQLITE_CREATE_TRIGGER' undeclared here (not in a function)
src/module.c:279: error: 'SQLITE_CREATE_VIEW' undeclared here (not in a function)
src/module.c:280: error: 'SQLITE_DELETE' undeclared here (not in a function)
src/module.c:281: error: 'SQLITE_DROP_INDEX' undeclared here (not in a function)
src/module.c:282: error: 'SQLITE_DROP_TABLE' undeclared here (not in a function)
src/module.c:283: error: 'SQLITE_DROP_TEMP_INDEX' undeclared here (not in a function)
src/module.c:284: error: 'SQLITE_DROP_TEMP_TABLE' undeclared here (not in a function)
src/module.c:285: error: 'SQLITE_DROP_TEMP_TRIGGER' undeclared here (not in a function)
src/module.c:286: error: 'SQLITE_DROP_TEMP_VIEW' undeclared here (not in a function)
src/module.c:287: error: 'SQLITE_DROP_TRIGGER' undeclared here (not in a function)
src/module.c:288: error: 'SQLITE_DROP_VIEW' undeclared here (not in a function)
src/module.c:289: error: 'SQLITE_INSERT' undeclared here (not in a function)
src/module.c:290: error: 'SQLITE_PRAGMA' undeclared here (not in a function)
src/module.c:291: error: 'SQLITE_READ' undeclared here (not in a function)
src/module.c:292: error: 'SQLITE_SELECT' undeclared here (not in a function)
src/module.c:293: error: 'SQLITE_TRANSACTION' undeclared here (not in a function)
src/module.c:294: error: 'SQLITE_UPDATE' undeclared here (not in a function)
src/module.c:295: error: 'SQLITE_ATTACH' undeclared here (not in a function)
src/module.c:296: error: 'SQLITE_DETACH' undeclared here (not in a function)
src/module.c: In function 'init_sqlite':
src/module.c:426: warning: implicit declaration of function 'sqlite3_libversion'
src/module.c:426: warning: passing argument 1 of 'PyString_FromString' makes pointer from integer without a cast
/usr/local/python2.7/include/python2.7/stringobject.h:63: note: expected 'const char *' but argument is of type 'int'
error: command 'gcc' failed with exit status 1


�����

���

http://stackoverflow.com/questions/1448819/how-to-install-pysqlite

�ҵĽ����

��װ����������

# yum install sqlite-devel
#yum install -y python-devel


�����Ҳ�֪�������·����û�й�ϵ��

[root@iZ28cumdzmgZ pysqlite-2.6.3]# pwd
/usr/local/pysqlite/pysqlite-2.6.3   #�Ұ�pysqlite�������λ���ˣ�Ҳ����Ҫ����������������ļ�
[root@iZ28cumdzmgZ pysqlite-2.6.3]# vim setup.cfg
include_dirs=/usr/local/include
library_dirs=/usr/local/lib
#include_dirs=/usr/local/pysqlite/pysqlite-2.6.3/include
#library_dirs=/usr/local/pysqlite/pysqlite-2.6.4/lib


����runserver��

[root@iZ28cumdzmgZ muahao01]# python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.

December 22, 2014 - 13:13:40
Django version 1.7.1, using settings 'muahao01.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.


����

[root@iZ28cumdzmgZ muahao01]# python manage.py migrate
Operations to perform:
  Apply all migrations: admin, contenttypes, auth, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying sessions.0001_initial... OK
[root@iZ28cumdzmgZ muahao01]# python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
December 22, 2014 - 13:20:27
Django version 1.7.1, using settings 'muahao01.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.


��Ȼ��sunserver�Ѿ����������Ǵ������������http://127.0.0.1:8000/blog/index��ᷢ�֣�û�д���д��ҳ�棡��ԭ���ǣ������ڲ��������ҵ� ECS���ڰ������ϣ�

����Ҫ��������runserver��

[root@iZ28cumdzmgZ muahao01]# python manage.py runserver 121.42.138.224:8000

Ȼ��������������룺http://121.42.138.224:8000/blog/index/  ���Կ�����

hello Django!



���ij��� ��muahao�� ���ͣ�����ر����˳���http://muahao.blog.51cto.com/8176010/1592483

你可能感兴趣的:(ImportError: No module named blog)