File"/usr/local/lib/python2.5/site-packages/django/utils/importlib.py", line 35,in import_module
__import__(name)File"/usr/local/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py", line 30,in<module>raiseImproperlyConfigured,"Error loading %s: %s"%(module, exc)ImproperlyConfigured:Error loading either pysqlite2 or sqlite3 modules (tried in that order):Nomodule named _sqlite3
查看Python安装,它给出了相同的错误:
Python2.5.2(r252:60911,May122009,07:46:31)[GCC 4.1.220061115(prerelease)(Debian4.1.1-21)] on linux2Type"help","copyright","credits"or"license"for more information.>>>import sqlite3Traceback(most recent call last):File"<stdin>", line 1,in<module>File"/usr/local/lib/python2.5/sqlite3/__init__.py", line 24,in<module>from dbapi2 import*File"/usr/local/lib/python2.5/sqlite3/dbapi2.py", line 27,in<module>from _sqlite3 import*ImportError:Nomodule named _sqlite3>>>
I am trying to run a Django app on my VPS running Debian 5. When I run a demo app, it comes back with this error:
File "/usr/local/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py", line 30, in <module>
raise ImproperlyConfigured, "Error loading %s: %s" % (module, exc)
ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3
Looking at the Python install, it gives the same error:
Python 2.5.2 (r252:60911, May 12 2009, 07:46:31)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.5/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/usr/local/lib/python2.5/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
>>>
Reading on the web, I learn that Python 2.5 should come with all the necessary SQLite wrappers included. Do I need to reinstall Python, or is there another way to get this module up and running?
回答 0
您的makefile文件似乎没有包含适当的.so文件。您可以按照以下步骤纠正此问题:
安装sqlite-devel(或libsqlite3-dev在某些基于Debian的系统上)
使用以下命令重新配置和重新编译Python ./configure --enable-loadable-sqlite-extensions && make && sudo make install
注意
该sudo make install部分将把python版本设置为系统范围的标准,这可能会产生无法预料的后果。如果您在工作站上运行此命令,则可能希望将其与现有python 一起安装,可以使用来完成sudo make altinstall。
It seems your makefile didn’t include the appropriate .so file. You can correct this problem with the steps below:
Install sqlite-devel (or libsqlite3-dev on some Debian-based systems)
Re-configure and re-compiled Python with ./configure --enable-loadable-sqlite-extensions && make && sudo make install
Note
The sudo make install part will set that python version to be the system-wide standard, which can have unforseen consequences. If you run this command on your workstation, you’ll probably want to have it installed alongside the existing python, which can be done with sudo make altinstall.
I had the same problem (building python2.5 from source on Ubuntu Lucid), and import sqlite3 threw this same exception. I’ve installed libsqlite3-dev from the package manager, recompiled python2.5, and then the import worked.
I had the same problem with Python 3.5 on Ubuntu while using pyenv.
If you’re installing the python using pyenv, it’s listed as one of the common build problems. To solve it, remove the installed python version, install the requirements (for this particular case libsqlite3-dev), then reinstall the python version.
My _sqlite3.so is in /usr/lib/python2.5/lib-dynload/_sqlite3.so. Judging from your paths, you should have the file /usr/local/lib/python2.5/lib-dynload/_sqlite3.so.
Try the following:
find /usr/local -name _sqlite3.so
If the file isn’t found, something may be wrong with your Python installation. If it is, make sure the path it’s installed to is in the Python path. In the Python shell,
import sys
print sys.path
In my case, /usr/lib/python2.5/lib-dynload is in the list, so it’s able to find /usr/lib/python2.5/lib-dynload/_sqlite3.so.
I recently tried installing python 2.6.7 on my Ubuntu 11.04 desktop for some dev work. Came across similar problems to this thread. I mamaged to fix it by:
Adjusting the setup.py file to include the correct sqlite dev path. Code snippet from setup.py:
With the bit that I added being ‘/usr/lib/x86_64-linux-gnu/’.
After running make I did not get any warnings saying the sqlite support was not built (i.e., it built correctly :P ), but after running make install, sqlite3 still did not import with the same “ImportError: No module named _sqlite3" whe running "import sqlite3“.
So, the library was compiled, but not moved to the correct installation path, so I copied the .so file (cp /usr/src/python/Python-2.6.7/build/lib.linux-x86_64-2.6/_sqlite3.so /usr/local/python-2.6.7/lib/python2.6/sqlite3/ — these are my build paths, you will probably need to adjust them to your setup).
Voila! SQLite3 support now works.
回答 7
我发现很多人都遇到了这个问题,因为在我自己的vps(cent os 7 x64)上,Multi-version Python是通过以下方式解决的:
I was disappointed this issue still exist till today. As I have recently been trying to install vCD CLI on CentOS 8.1 and I was welcomed with the same error when tried to run it. The way I had to resolve it in my case is as follow:
Install SQLite3 from scratch with the proper prefix
Make clean my Python Installation
Run Make install to reinstall Python
As I have been doing this to create a different blogpost about how to install vCD CLI and VMware Container Service Extension. I have end up capturing the steps I used to fix the issue and put it in a separate blog post at: