如何获取_sqlite3.so文件?
我已经安装了Python 2.6.2..我是在“本地”安装的,因为我没有root权限。对于这个版本的Python,我想使用名为“sqlite3”的模块(在早期版本中称为“pysqlite”)。理论上,我必须能够毫无问题地使用这个模块,因为它应该默认包含在所考虑的 Python 版本中。然而,我有一些麻烦。当我输入:
from sqlite3 import *
我得到:
Traceback (most recent call last):
File "", line 1, in File "/home/verrtex/opt/lib/python2.6/sqlite3/init.py", line 24, in
from dbapi2 import *
File "/home/verrtex/opt/lib/python2.6/sqlite3/dbapi2.py", line 27, in
from _sqlite3 import *
ImportError: No module named _sqlite3
正如我已经告诉过的,这个问题的可能原因是模块尝试导入 _sqlite3 并失败,所以它没有找到 _sqlite3.so。我的“/home/verrtex/opt/lib/python2.6/lib-dynload”目录中没有 _sqlite3.so 文件,这一事实支持了这种解释。所以,这就是我必须解决的问题(我必须将此文件放到这个目录中)。
我发现要解决这个问题我必须“安装sqlite3并重新编译Python”。我还发现可以通过“从源代码构建并将库移动到 /usr/lib/python2.5/lib-dynload/”来解决该问题。
但是,我不清楚我到底应该做什么。我应该安装名为“sqlite3”的 python 模块还是应该安装 sqlite-database?顺便说一句,我已经由管理员全局安装了sqlite-database。我可以使用它还是仍然需要安装自己的数据库?顺便说一句,我没有root权限。这会是一个问题吗?或者我需要安装 python 模块?在这种情况下,缺乏 root 权限是一个问题吗?
我还被告知,从 SQLite 下载页面获取源文件,提取存档,移动到扩展目录并执行:
./configure
make
make install
然后我必须将新编译的文件复制到我的 Python 目录。我应该复制所有新编译的文件吗?我应该复制到哪个目录(我的 Python 目录有一些子目录)?
非常感谢任何帮助,因为我已经解决这个问题一段时间了。
PS 我的操作系统是 CentOS 版本 5.3(最终版)。
I have installed Python 2.6.2.. I did it "locally" since I do not have root permissions. With this version of Python I wanted to use module called "sqlite3" (it is called "pysqlite" in earlier versions). In theory I had to be able to use this module without any problems since it is supposed to be included by default in the considered version of Python. However, I have some troubles. When I type:
from sqlite3 import *
I get:
Traceback (most recent call last):
File "", line 1, in File "/home/verrtex/opt/lib/python2.6/sqlite3/init.py", line 24, in
from dbapi2 import *
File "/home/verrtex/opt/lib/python2.6/sqlite3/dbapi2.py", line 27, in
from _sqlite3 import *
ImportError: No module named _sqlite3
As I have already told to, the possible reason of this problem is that the module in tries to import _sqlite3 and fails, so it's not finding _sqlite3.so. This explanations is supported by the fact that I do not have _sqlite3.so file in my "/home/verrtex/opt/lib/python2.6/lib-dynload" directory. So, this is the problem I have to solve (I have to get this file to this directory).
I found out that to solve this problem I have to "install sqlite3 and recompile Python". I also found out that the problem can be solved by "building from source and moving the library to /usr/lib/python2.5/lib-dynload/".
However, it is not clear to me what exactly should I do. Should I install python module called "sqlite3" or I should install sqlite-database? By the way, I have already sqlite-database installed globally by the administrator. Can I use it or I still have to install my own database? By the way, I do not have root permissions. Can it be a problem? Or I need to install a python module? Is absence of root permissions a problem, in this case?
I also has been told to, to take source files from SQLite Download Page, extract archive, move to expanded directory and execute:
./configure
make
make install
Then I have to copy newly compiled files to my Python directory. Should I copy all newly compiled files? And to which exactly directory should I copy (my Python directory have some subdirectories)?
Would very appreciate any help, because I stack with this problem for a wile.
P.S. My OS is CentOS release 5.3 (Final).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 sys.path 可能没有指向您本地安装的副本,或者您没有运行您认为的 Python 2.6.2。
如果不是这种情况,您需要 SQLite 开发标头(sqlite-dev 或其他),然后重新编译 Python。您需要在编译结束时注意,因为它会抱怨由于缺少依赖项而未构建的内容。
编辑:重读问题。
编辑2:另外,请不要这样做:
这样做:
Your
sys.path
is likely not pointing to your locally installed copy, or you're not running the Python 2.6.2 you think you are.If none of that is the case, you need the SQLite development headers (sqlite-dev or whatever), and then recompile Python. You need to pay attention at the end of the compile, because it complains about what it didn't build due to missing dependencies.
EDIT: Reread question.
EDIT 2: Also, please don't do this:
Do this:
尽管您可能已经找到了解决方案,但我只是为遇到同样问题的人写下了我的解决方案。
我的操作系统是CentOS 6.3(Final) with python2.6。
我在系统中安装了python2.7.3,但问题仍然存在。 (_sqlite3.so 在安装了 python2.7.3 后应该位于
/path/to/python2.7.3/lib/python2.7/lib-dynload
中。因为在安装 python2.7 之前,sqlite-autoconf-3071502.tar.gz 已安装。)然后我复制
/path/to/python2.6/lib/python2.6/lib-dynload/_sqlite3.so
到 python2.7 的路径。然后输入 python-shell:或
无错误报告。
不幸的是,当我运行 python 脚本时,该死的错误像以前一样出现了。
我安装 sqlite-devel(
sudo yum install sqlite-devel
或下载此处),然后再次重新安装python2.7.3。再次运行我的 python 脚本。谢天谢地!该死的错误终于解决了。Although you might have found your solution, I just wrote mine down for someone who are stuck in the same problem.
My OS is CentOS 6.3(Final) with python2.6.
I install python2.7.3 in my system, but the problem's still there. (_sqlite3.so should be in
/path/to/python2.7.3/lib/python2.7/lib-dynload
after python2.7.3 has been installed. Because before python2.7 was installed, sqlite-autoconf-3071502.tar.gz was installed.)I then copy the
/path/to/python2.6/lib/python2.6/lib-dynload/_sqlite3.so
to the python2.7's path. And type in the python-shell:or
No error reports.
Unfortunately, the damn error appeared as before when I run my python script.
I install sqlite-devel(
sudo yum install sqlite-devel
or download here), and then reinstall python2.7.3 again. Run my python script again. Thank goodness! The damn error finally solved.