如何添加路径以便python可以找到程序?

2024-03-29 13:20:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过import函数将sqlite与python一起使用,但是看起来python找不到{}。在

我的系统路径包含以下内容:

['', '/usr/local/share/python', '/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/distribute-0.6.26-py2.7.egg', '/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/pip-1.1-py2.7.egg', '/usr/local/Cellar/python/2.7.3/lib/python27.zip', '/usr/local/Cellar/python/2.7.3/lib/python2.7', '/usr/local/Cellar/python/2.7.3/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.3/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.3/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.3/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.3/lib/python2.7/lib-old', '/usr/local/Cellar/python/2.7.3/lib/python2.7/lib-dynload', '/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages', '/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info', '/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/IPython/extensions']

但是sqlite列在usr/lib中。在

编辑:
正如建议的那样,我尝试了import sqlite3,但是python返回以下错误:

^{pr2}$

如何加载sqlite?在


Tags: 函数import路径sharesqliteeggmaclib
2条回答

sqlite3是python模块的名称,该模块提供python和sqlite数据库引擎之间的接口。sqlite是基础数据库引擎的名称。在

所以(正如Martijn Pieters已经指出的)试着:

import sqlite3

不需要向模块搜索路径添加任何内容;SQLite模块附带Python标准库。但是,您拼错了模块的名称,它被称为^{}(注意末尾的3):

Python 2.7.3 (default, Oct 22 2012, 06:12:32) 
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.connect(':memory:')
<sqlite3.Connection object at 0x105354200>

如果仍然出现错误,则说明您的自制程序安装已中断;您可能遇到了this bug。运行:

^{pr2}$

修理。在

相关问题 更多 >