在Python 2.7.13上使用pip安装sqlite时出错

时间:2017-09-18 21:53:46

标签: python-2.7 sqlite pysqlite

我正在尝试使用pip安装pysqlite,但它一直给我一个错误:

  

无法打开包含文件:' sqlite3.h':没有这样的文件或目录

我使用的是Windows 10 OS 64位。 Python版本2.7.13。我尝试使用pip进行安装。 (pip install pysqlite)

我无法分享错误屏幕截图,因此我复制了以下完整的错误代码。如果有人能帮助我,那将是伟大的。 谢谢。

完整的cmd如下所示:

C:\Users\Who Are You>pip install pysqlite
Collecting pysqlite
  Using cached pysqlite-2.8.3.tar.gz
Installing collected packages: pysqlite
  Running setup.py install for pysqlite ... error
    Complete output from command c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\whoare~1\\appdata\\local\\temp\\pip-build-0ju9tj\\pysqlite\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\whoare~1\appdata\local\temp\pip-0cieyz-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-2.7
    creating build\lib.win32-2.7\pysqlite2
    copying lib\dbapi2.py -> build\lib.win32-2.7\pysqlite2
    copying lib\dump.py -> build\lib.win32-2.7\pysqlite2
    copying lib\__init__.py -> build\lib.win32-2.7\pysqlite2
    creating build\lib.win32-2.7\pysqlite2\test
    copying lib\test\dbapi.py -> build\lib.win32-2.7\pysqlite2\test
    copying lib\test\dump.py -> build\lib.win32-2.7\pysqlite2\test
    copying lib\test\factory.py -> build\lib.win32-2.7\pysqlite2\test
    copying lib\test\hooks.py -> build\lib.win32-2.7\pysqlite2\test
    copying lib\test\regression.py -> build\lib.win32-2.7\pysqlite2\test
    copying lib\test\transactions.py -> build\lib.win32-2.7\pysqlite2\test
    copying lib\test\types.py -> build\lib.win32-2.7\pysqlite2\test
    copying lib\test\userfunctions.py -> build\lib.win32-2.7\pysqlite2\test
    copying lib\test\__init__.py -> build\lib.win32-2.7\pysqlite2\test
    running build_ext
    building 'pysqlite2._sqlite' extension
    creating build\temp.win32-2.7
    creating build\temp.win32-2.7\Release
    creating build\temp.win32-2.7\Release\src
    C:\Users\Who Are You\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DMODULE_NAME=\"pysqlite2.dbapi2\" -I'{' -Iis -Inot -Irecognized -Ias -Ian -Iinternal -Ior -Iexternal -Icommand, -Ioperable -Iprogram -Ior -Ibatch -Ifile. -Ic:\python27\include -Ic:\python27\PC /Tcsrc/module.c /Fobuild\temp.win32-2.7\Release\src/module.obj
    module.c
    c:\users\who are you\appdata\local\temp\pip-build-0ju9tj\pysqlite\src\connection.h(33) : fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory
    error: command 'C:\\Users\\Who Are You\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status 2
    ----------------------------------------
Command "c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\whoare~1\\appdata\\local\\temp\\pip-build-0ju9tj\\pysqlite\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\whoare~1\appdata\local\temp\pip-0cieyz-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\whoare~1\appdata\local\temp\pip-build-0ju9tj\pysqlite\

屏幕截图为here

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,并设法通过以下方式解决了这个问题:

  1. 创建一个临时目录 C:\ sqlite
  2. 将文件 lib.exe link.exe mspdb80.dll 复制到 C:\ sqlite 从:
    • 对于X86构建:%LocalAppData%\ Programs \ Common \ Microsoft \ Visual C ++ for Python \ 9.0 \ VC \ bin
    • 对于X64构建:%LocalAppData%\ Programs \ Common \ Microsoft \ Visual C ++ for Python \ 9.0 \ VC \ bin \ amd64
  3. SQLite website下载用于Windows(32位或64位DLL文件)档案的混合源代码和预编译二进制文件
  4. 将二进制文件存档( sqlite3.dll sqlite3.def )提取到 C:\ sqlite
  5. C:\ sqlite 中打开Windows PowerShell并运行:
    • 对于X86构建:.\lib.exe /DEF:sqlite3.def /MACHINE:X86
    • 对于X64构建:.\lib.exe /DEF:sqlite3.def /MACHINE:X64
  6. 将创建的 sqlite3.lib 文件复制到 C:\ Python27 \ libs
  7. 从合并的源代码档案中提取 sqlite3.h sqlite3ext.h C:\ Python27 \ include
  8. 运行pip install pysqlite

答案 1 :(得分:-1)

据我所知,sqlite3内置于python2.x和python3.x