How to get _sqlite3.so file?

感情迁移 提交于 2019-12-12 14:07:55

问题


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).


回答1:


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:

from module import *

Do this:

from module import what_i_need
import module2



回答2:


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:

>>> import sqlite3

or

>>> import _sqlite3

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.



来源:https://stackoverflow.com/questions/1480024/how-to-get-sqlite3-so-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!