如何让 sqlite 在共享托管服务器上工作?

发布于 2024-11-07 20:09:40 字数 3833 浏览 0 评论 0原文

我正在尝试使用 python 2.6.4 运行 python 脚本。托管公司安装了 2.4,因此我在类似的服务器上编译了自己的 2.6.4,然后将文件移至 ~/opt/python 中。那部分似乎工作正常。

无论如何,当我运行下面的脚本时,我收到 ImportError: No module named _sqlite3 并且我不知道如何解决这个问题。

大多数在线线程提到 sqlite / sqlite3 包含在 python 2.6 中 - 所以我不确定为什么这不起作用。

-jailshell-3.2$ ./pyDropboxValues.py 

Traceback (most recent call last):
  File "./pyDropboxValues.py", line 21, in 
    import sqlite3
  File "/home/myAccount/opt/lib/python2.6/sqlite3/__init__.py", line 24, in 
    from dbapi2 import *
  File "/home/myAccount/opt/lib/python2.6/sqlite3/dbapi2.py", line 27, in 
    from _sqlite3 import *
ImportError: No module named _sqlite3

我想就目录结构而言我已经设置好了一切。

-jailshell-3.2$ find `pwd` -type d

/home/myAccount/opt
/home/myAccount/opt/bin
/home/myAccount/opt/include
/home/myAccount/opt/include/python2.6
/home/myAccount/opt/lib
/home/myAccount/opt/lib/python2.6
/home/myAccount/opt/lib/python2.6/distutils
/home/myAccount/opt/lib/python2.6/distutils/command
/home/myAccount/opt/lib/python2.6/distutils/tests
/home/myAccount/opt/lib/python2.6/compiler
/home/myAccount/opt/lib/python2.6/test
/home/myAccount/opt/lib/python2.6/test/decimaltestdata
/home/myAccount/opt/lib/python2.6/config
/home/myAccount/opt/lib/python2.6/json
/home/myAccount/opt/lib/python2.6/json/tests
/home/myAccount/opt/lib/python2.6/email
/home/myAccount/opt/lib/python2.6/email/test
/home/myAccount/opt/lib/python2.6/email/test/data
/home/myAccount/opt/lib/python2.6/email/mime
/home/myAccount/opt/lib/python2.6/lib2to3
/home/myAccount/opt/lib/python2.6/lib2to3/pgen2
/home/myAccount/opt/lib/python2.6/lib2to3/fixes
/home/myAccount/opt/lib/python2.6/lib2to3/tests
/home/myAccount/opt/lib/python2.6/xml
/home/myAccount/opt/lib/python2.6/xml/parsers
/home/myAccount/opt/lib/python2.6/xml/sax
/home/myAccount/opt/lib/python2.6/xml/etree
/home/myAccount/opt/lib/python2.6/xml/dom
/home/myAccount/opt/lib/python2.6/site-packages
/home/myAccount/opt/lib/python2.6/logging
/home/myAccount/opt/lib/python2.6/lib-dynload
/home/myAccount/opt/lib/python2.6/sqlite3
/home/myAccount/opt/lib/python2.6/sqlite3/test
/home/myAccount/opt/lib/python2.6/encodings
/home/myAccount/opt/lib/python2.6/wsgiref
/home/myAccount/opt/lib/python2.6/multiprocessing
/home/myAccount/opt/lib/python2.6/multiprocessing/dummy
/home/myAccount/opt/lib/python2.6/curses
/home/myAccount/opt/lib/python2.6/bsddb
/home/myAccount/opt/lib/python2.6/bsddb/test
/home/myAccount/opt/lib/python2.6/idlelib
/home/myAccount/opt/lib/python2.6/idlelib/Icons
/home/myAccount/opt/lib/python2.6/tmp
/home/myAccount/opt/lib/python2.6/lib-old
/home/myAccount/opt/lib/python2.6/lib-tk
/home/myAccount/opt/lib/python2.6/hotshot
/home/myAccount/opt/lib/python2.6/plat-linux2
/home/myAccount/opt/lib/python2.6/ctypes
/home/myAccount/opt/lib/python2.6/ctypes/test
/home/myAccount/opt/lib/python2.6/ctypes/macholib
/home/myAccount/opt/share
/home/myAccount/opt/share/man
/home/myAccount/opt/share/man/man1

最后是 sqlite3 目录的内容:

-jailshell-3.2$ find `pwd`

/home/myAccount/opt/lib/python2.6/sqlite3
/home/myAccount/opt/lib/python2.6/sqlite3/__init__.pyo
/home/myAccount/opt/lib/python2.6/sqlite3/dump.pyc
/home/myAccount/opt/lib/python2.6/sqlite3/__init__.pyc
/home/myAccount/opt/lib/python2.6/sqlite3/dbapi2.pyo
/home/myAccount/opt/lib/python2.6/sqlite3/dbapi2.pyc
/home/myAccount/opt/lib/python2.6/sqlite3/dbapi2.py
/home/myAccount/opt/lib/python2.6/sqlite3/dump.pyo
/home/myAccount/opt/lib/python2.6/sqlite3/__init__.py
/home/myAccount/opt/lib/python2.6/sqlite3/dump.py

我觉得我需要在 sqlite3 目录中添加一些内容 - 也许是 sqlite3.so?但我不知道从哪里得到它。

我在这里做错了什么?请记住,我使用的是共享主机,这意味着在另一台服务器上安装/编译,然后复制文件。谢谢! :)

更新 只是想确认@samplebias 的答案确实效果很好。我需要在我进行编译的机器上安装开发包,以便将其添加到 sqlite3.so 和相关文件中。还发现答案中的链接非常有帮助。谢谢@samplebias!

I'm trying to run a python script using python 2.6.4. The hosting company has 2.4 installed so I compiled my own 2.6.4 on a similar server and then moved the files over into ~/opt/python. that part seems to be working fine.

anyhow, when I run the script below, I am getting ImportError: No module named _sqlite3 and I'm not sure what to do to fix this.

Most online threads mention that sqlite / sqlite3 is included in python 2.6 - so I'm not sure why this isn't working.

-jailshell-3.2$ ./pyDropboxValues.py 

Traceback (most recent call last):
  File "./pyDropboxValues.py", line 21, in 
    import sqlite3
  File "/home/myAccount/opt/lib/python2.6/sqlite3/__init__.py", line 24, in 
    from dbapi2 import *
  File "/home/myAccount/opt/lib/python2.6/sqlite3/dbapi2.py", line 27, in 
    from _sqlite3 import *
ImportError: No module named _sqlite3

I think I have everything set up right as far as the directory structure.

-jailshell-3.2$ find `pwd` -type d

/home/myAccount/opt
/home/myAccount/opt/bin
/home/myAccount/opt/include
/home/myAccount/opt/include/python2.6
/home/myAccount/opt/lib
/home/myAccount/opt/lib/python2.6
/home/myAccount/opt/lib/python2.6/distutils
/home/myAccount/opt/lib/python2.6/distutils/command
/home/myAccount/opt/lib/python2.6/distutils/tests
/home/myAccount/opt/lib/python2.6/compiler
/home/myAccount/opt/lib/python2.6/test
/home/myAccount/opt/lib/python2.6/test/decimaltestdata
/home/myAccount/opt/lib/python2.6/config
/home/myAccount/opt/lib/python2.6/json
/home/myAccount/opt/lib/python2.6/json/tests
/home/myAccount/opt/lib/python2.6/email
/home/myAccount/opt/lib/python2.6/email/test
/home/myAccount/opt/lib/python2.6/email/test/data
/home/myAccount/opt/lib/python2.6/email/mime
/home/myAccount/opt/lib/python2.6/lib2to3
/home/myAccount/opt/lib/python2.6/lib2to3/pgen2
/home/myAccount/opt/lib/python2.6/lib2to3/fixes
/home/myAccount/opt/lib/python2.6/lib2to3/tests
/home/myAccount/opt/lib/python2.6/xml
/home/myAccount/opt/lib/python2.6/xml/parsers
/home/myAccount/opt/lib/python2.6/xml/sax
/home/myAccount/opt/lib/python2.6/xml/etree
/home/myAccount/opt/lib/python2.6/xml/dom
/home/myAccount/opt/lib/python2.6/site-packages
/home/myAccount/opt/lib/python2.6/logging
/home/myAccount/opt/lib/python2.6/lib-dynload
/home/myAccount/opt/lib/python2.6/sqlite3
/home/myAccount/opt/lib/python2.6/sqlite3/test
/home/myAccount/opt/lib/python2.6/encodings
/home/myAccount/opt/lib/python2.6/wsgiref
/home/myAccount/opt/lib/python2.6/multiprocessing
/home/myAccount/opt/lib/python2.6/multiprocessing/dummy
/home/myAccount/opt/lib/python2.6/curses
/home/myAccount/opt/lib/python2.6/bsddb
/home/myAccount/opt/lib/python2.6/bsddb/test
/home/myAccount/opt/lib/python2.6/idlelib
/home/myAccount/opt/lib/python2.6/idlelib/Icons
/home/myAccount/opt/lib/python2.6/tmp
/home/myAccount/opt/lib/python2.6/lib-old
/home/myAccount/opt/lib/python2.6/lib-tk
/home/myAccount/opt/lib/python2.6/hotshot
/home/myAccount/opt/lib/python2.6/plat-linux2
/home/myAccount/opt/lib/python2.6/ctypes
/home/myAccount/opt/lib/python2.6/ctypes/test
/home/myAccount/opt/lib/python2.6/ctypes/macholib
/home/myAccount/opt/share
/home/myAccount/opt/share/man
/home/myAccount/opt/share/man/man1

And finally the contents of the sqlite3 directory:

-jailshell-3.2$ find `pwd`

/home/myAccount/opt/lib/python2.6/sqlite3
/home/myAccount/opt/lib/python2.6/sqlite3/__init__.pyo
/home/myAccount/opt/lib/python2.6/sqlite3/dump.pyc
/home/myAccount/opt/lib/python2.6/sqlite3/__init__.pyc
/home/myAccount/opt/lib/python2.6/sqlite3/dbapi2.pyo
/home/myAccount/opt/lib/python2.6/sqlite3/dbapi2.pyc
/home/myAccount/opt/lib/python2.6/sqlite3/dbapi2.py
/home/myAccount/opt/lib/python2.6/sqlite3/dump.pyo
/home/myAccount/opt/lib/python2.6/sqlite3/__init__.py
/home/myAccount/opt/lib/python2.6/sqlite3/dump.py

I feel like I need to add something into the sqlite3 directory - maybe sqlite3.so? But I don't know where to get that.

What am I doing wrong here? Please remember that I'm using a shared host so that means installing / compiling on another server and then copying the files over. Thanks! :)

Update
Just wanted to confirm that the answer from @samplebias did work out very well. I needed to have the dev package installed on the machine I was compiling from to get it to add in sqlite3.so and related files. Also found the link in the answer very helpful. Thanks @samplebias !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一紙繁鸢 2024-11-14 20:09:40

Python 的构建系统 使用 setup.py 文件来编译所有本机扩展< /a>,包括 sqlite3。它搜索 sqlite3 包含和库目录的常见操作系统路径。如果未安装 sqlite3 开发包,Python 将跳过编译 _sqlite3.so 扩展,但仍会安装 sqlite3 包的纯 Python 部分。

在编译 Python 和运行时,您需要安装操作系统的 sqlite3 开发包:Centos 上的 sqlite3-devellibsqlite3-0libsqlite3- Ubuntu 上的 dev

以下是我的 Ubuntu 系统上的 _sqlite3.so 扩展链接的示例:

% ldd /usr/lib/python2.6/lib-dynload/_sqlite3.so | grep sqlite3
    libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0x00007f29ef3be000)
% dpkg -S /usr/lib/libsqlite3.so.0
    libsqlite3-0: /usr/lib/libsqlite3.so.0

Python's build system uses a setup.py file to compile all of the native extensions, including sqlite3. It searches common operating system paths for the sqlite3 include and library dirs. If the sqlite3 development package is not installed Python will skip compiling the _sqlite3.so extension, but the pure Python portion of the sqlite3 package will still be installed.

You would need to have the operating system's sqlite3 development package installed when you compile Python and at runtime: sqlite3-devel on Centos, both libsqlite3-0 and libsqlite3-dev on Ubuntu.

Here's an example of the _sqlite3.so extension linkage on my Ubuntu system:

% ldd /usr/lib/python2.6/lib-dynload/_sqlite3.so | grep sqlite3
    libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0x00007f29ef3be000)
% dpkg -S /usr/lib/libsqlite3.so.0
    libsqlite3-0: /usr/lib/libsqlite3.so.0
终陌 2024-11-14 20:09:40

一般来说,首先要做的就是询问你的主人。我似乎有点奇怪 SQLite 没有安装(或安装正确)。因此,如果您询问他们,他们可能会很快修复它。

In general, the first thing to do is to ask your host. I seems a bit odd that SQLite is not installed (or installed properly). So they'll likely fix it quite fast if you ask them.

泛滥成性 2024-11-14 20:09:40

对于 python 2.4,您需要 sqlite 和绑定,pysqlite 2aspw

For python 2.4, you need sqlite and bindings, pysqlite 2 or aspw

天荒地未老 2024-11-14 20:09:40

sqlite 文件夹中列出的文件都不是 _sqlite3.pyd Python 共享库。你确定你编译Python的时候编译过它吗?构建日志说什么?我认为需要传递一个 configure 标志。

或者,只需安装 pysqlite

None of the files listed in the sqlite folder is the _sqlite3.pyd Python shared library. Are you sure you compiled it when compiling Python? What does the build log say? I think there's a configure flag that needs to be passed.

Alternatively, just install pysqlite

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文