2014-05-10 194 views
0

我是python和django的新手。我試圖讓Python 3.4和django 1.6.4在Linux Mint Mate 13的pyvenv-3.4環境中工作。我按照Using a virtual environment with Python 3.4的步驟「從源代碼構建Python 3.4」和「使用pyvenv-3.4」。然後按照Writing your first Django app的Django教程,我可以用startproject創建「mysite」。但是,命令「python manage.py runserver」失敗,因爲django.core.exceptions中有 。 ImproperlyConfigured:錯誤加載要麼pysqlite2或sqlite3的模塊 (嘗試按照這個順序): 無模塊名爲「_sqlite3」sqlite和pyvenv和django

對不起,我不記得爲什麼我使出從源代碼編譯,但它可能是我無法使用apt-get在標準Ubuntu下載中找到pyvenv。在任何情況下,源代碼發行版的Makefile都沒有「卸載」目標,所以看起來我被安裝的任何東西卡住了,並且沒有計劃實際獲得pyvenv-python-django的工作。

我附上完整的錯誤更新這個帖子:

$ python manage.py runserver 
Traceback (most recent call last): 
    File "/local/djenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 30, in <module> 
    from pysqlite2 import dbapi2 as Database 
ImportError: No module named 'pysqlite2' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "/local/djenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 32, in <module> 
    from sqlite3 import dbapi2 as Database 
    File "/usr/local/lib/python3.4/sqlite3/__init__.py", line 23, in <module> 
    from sqlite3.dbapi2 import * 
    File "/usr/local/lib/python3.4/sqlite3/dbapi2.py", line 26, in <module> 
    from _sqlite3 import * 
ImportError: No module named '_sqlite3' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "/local/djenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line 
    utility.execute() 
    File "/local/djenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 392, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/local/djenv/lib/python3.4/site-packages/django/core/management/base.py", line 242, in run_from_argv 
    self.execute(*args, **options.__dict__) 
    File "/local/djenv/lib/python3.4/site-packages/django/core/management/base.py", line 280, in execute 
    translation.activate('en-us') 
    File "/local/djenv/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 130, in activate 
    return _trans.activate(language) 
    File "/local/djenv/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 188, in activate 
    _active.value = translation(language) 
    File "/local/djenv/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 177, in translation 
    default_translation = _fetch(settings.LANGUAGE_CODE) 
    File "/local/djenv/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch 
    app = import_module(appname) 
    File "/usr/local/lib/python3.4/importlib/__init__.py", line 104, in import_module 
    return _bootstrap._gcd_import(name[level:], package, level) 
    File "<frozen importlib._bootstrap>", line 2231, in _gcd_import 
    File "<frozen importlib._bootstrap>", line 2214, in _find_and_load 
    File "<frozen importlib._bootstrap>", line 2203, in _find_and_load_unlocked 
    File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked 
    File "<frozen importlib._bootstrap>", line 1129, in _exec 
    File "<frozen importlib._bootstrap>", line 1448, in exec_module 
    File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed 
    File "/local/djenv/lib/python3.4/site-packages/django/contrib/admin/__init__.py", line 6, in <module> 
    from django.contrib.admin.sites import AdminSite, site 
    File "/local/djenv/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 4, in <module> 
    from django.contrib.admin.forms import AdminAuthenticationForm 
    File "/local/djenv/lib/python3.4/site-packages/django/contrib/admin/forms.py", line 6, in <module> 
    from django.contrib.auth.forms import AuthenticationForm 
    File "/local/djenv/lib/python3.4/site-packages/django/contrib/auth/forms.py", line 17, in <module> 
    from django.contrib.auth.models import User 
    File "/local/djenv/lib/python3.4/site-packages/django/contrib/auth/models.py", line 48, in <module> 
    class Permission(models.Model): 
    File "/local/djenv/lib/python3.4/site-packages/django/db/models/base.py", line 96, in __new__ 
    new_class.add_to_class('_meta', Options(meta, **kwargs)) 
    File "/local/djenv/lib/python3.4/site-packages/django/db/models/base.py", line 264, in add_to_class 
    value.contribute_to_class(cls, name) 
    File "/local/djenv/lib/python3.4/site-packages/django/db/models/options.py", line 124, in contribute_to_class 
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) 
    File "/local/djenv/lib/python3.4/site-packages/django/db/__init__.py", line 34, in __getattr__ 
    return getattr(connections[DEFAULT_DB_ALIAS], item) 
    File "/local/djenv/lib/python3.4/site-packages/django/db/utils.py", line 198, in __getitem__ 
    backend = load_backend(db['ENGINE']) 
    File "/local/djenv/lib/python3.4/site-packages/django/db/utils.py", line 113, in load_backend 
    return import_module('%s.base' % backend_name) 
    File "/usr/local/lib/python3.4/importlib/__init__.py", line 104, in import_module 
    return _bootstrap._gcd_import(name[level:], package, level) 
    File "/local/djenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 35, 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' 
+0

看起來像在這裏問了一個問題的重複: http://stackoverflow.com/questions/20126475/importerror-no-module-named-sqlite3-in-python3-3 – crooksey

+0

感謝您的評論,但是之前我發佈過的那篇文章沒有提到如何從pyvenv虛擬環境中訪問sqlite3。 – user1639536

+0

從pyenv環境外部訪問sqlite3時是否出現錯誤? – ebarr

回答

0

這聽起來像你沒有安裝在從源碼構建CPython的時間SQLite的開發庫。構建過程有條件地包含一些基於底層開發庫可用性的功能。

在Debian GNU/Linux及其衍生產品上安裝libsqlite3-dev。然後重新運行./configure,makemake install