Skip to main content
 首页 » 编程设计

python之安装 pysqlcipher3 时出现问题

2024年11月24日7kevingrace

所以即使 pip install pysqlcipher3 工作返回 Successfully installed pysqlcipher3,但它没有。

根据我的研究,这似乎是尝试安装 Sqlcipher 的 Windows 用户的常见问题。

尝试#1

首先,我尝试从 github 下载 pysqlcipher3 并通过 cmd 手动构建和安装它(使用 python setup.py build 和 python seetup.py install)。

在执行 python3 setup.py build 时,我遇到了一些错误(缺少一些要求,环境变量中没有 OPENSSL_CONF 等),但我修复了大部分错误。

然而,我最终陷入了这个错误:

fatal error C1083:无法打开包含文件:“sqlcipher/sqlite3.h”:没有这样的文件或目录。

尝试#2

我在某处(我认为)读到我必须在安装 PySqlCipher3 之前安装 SQLCipher。

检查后,我发现我要么付费获得预构建的可执行文件,要么自己构建。

所以我尝试按照 this tutorial 自己构建它.

安装完所有要求并按照步骤操作后,我进入了另一个死胡同。在最后一步之前(第 6 步),在执行 nmake/f Makefile.msc 时出现此错误:

fatal error C1083:无法打开包含文件:“stdio.h”:没有这样的文件或目录


我的问题是:

  1. 我读到我需要 libsqlcipher,这可能是问题所在。我在哪里可以找到它(首选链接到可执行文件)。
  2. 如何在我的第一次尝试中解决问题?
  3. 如何在第二次尝试中解决问题?

我的目标:是安装并运行 pysqlcipher3。


编辑 1 - 解决了尝试 #2 只是为了解决另一个问题

看来我在 Visual Studio 中缺少一些 C++ 功能和工具。因此,通过 Visual Studio Community 安装程序,我下载并安装了基本的 C++ 内容并修复了错误。

我遇到了另一个错误,我通过将 OpenSSL-Win64\include 文件夹复制到 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\来修复该错误MSVC\14.16.27023\include.

但是,现在我遇到了这个错误:

sqlite3.c(77701): warning C4389: '!=': signed/unsigned mismatch 
    lib.exe /NOLOGO /MACHINE:x64 /OUT:libsqlite3.lib sqlite3.lo  
    echo EXPORTS > sqlcipher.def 
    dumpbin /all libsqlite3.lib  | tclsh .\tool\replace.tcl include "^\s+1 _?(sqlite3(?:session|changeset|changegroup|rebaser)?_[^@]*)(?:@\d+)?$" \1  | sort >> sqlcipher.def 
    link.exe /DEBUG   /NOLOGO /MACHINE:x64  /DLL /DEF:sqlcipher.def /OUT:sqlcipher.dll sqlite3.lo sqlite3res.lo   
   Creating library sqlcipher.lib and object sqlcipher.exp 
sqlite3.lo : error LNK2019: unresolved external symbol RAND_bytes referenced in function sqlcipher_openssl_random 
sqlite3.lo : error LNK2019: unresolved external symbol RAND_add referenced in function sqlcipher_openssl_add_random 
sqlite3.lo : error LNK2019: unresolved external symbol OBJ_nid2sn referenced in function sqlcipher_openssl_get_cipher 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_MD_size referenced in function sqlcipher_openssl_get_hmac_sz 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_CIPHER_nid referenced in function sqlcipher_openssl_get_cipher 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_CIPHER_block_size referenced in function sqlcipher_openssl_get_block_sz 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_CIPHER_key_length referenced in function sqlcipher_openssl_get_key_sz 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_CIPHER_iv_length referenced in function sqlcipher_openssl_get_iv_sz 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_CipherInit_ex referenced in function sqlcipher_openssl_cipher 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_CipherUpdate referenced in function sqlcipher_openssl_cipher 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_CipherFinal_ex referenced in function sqlcipher_openssl_cipher 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_CIPHER_CTX_new referenced in function sqlcipher_openssl_cipher 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_CIPHER_CTX_free referenced in function sqlcipher_openssl_cipher 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_CIPHER_CTX_set_padding referenced in function sqlcipher_openssl_cipher 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_sha1 referenced in function sqlcipher_openssl_get_hmac_sz 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_sha256 referenced in function sqlcipher_openssl_get_hmac_sz 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_sha512 referenced in function sqlcipher_openssl_get_hmac_sz 
sqlite3.lo : error LNK2019: unresolved external symbol EVP_get_cipherbyname referenced in function sqlcipher_openssl_activate 
sqlite3.lo : error LNK2019: unresolved external symbol PKCS5_PBKDF2_HMAC referenced in function sqlcipher_openssl_kdf 
sqlite3.lo : error LNK2019: unresolved external symbol HMAC_CTX_new referenced in function sqlcipher_openssl_hmac 
sqlite3.lo : error LNK2019: unresolved external symbol HMAC_CTX_free referenced in function sqlcipher_openssl_hmac 
sqlite3.lo : error LNK2019: unresolved external symbol HMAC_Init_ex referenced in function sqlcipher_openssl_hmac 
sqlite3.lo : error LNK2019: unresolved external symbol HMAC_Update referenced in function sqlcipher_openssl_hmac 
sqlite3.lo : error LNK2019: unresolved external symbol HMAC_Final referenced in function sqlcipher_openssl_hmac 
sqlcipher.dll : fatal error LNK1120: 24 unresolved externals 

请您参考如下方法:

首先,"Successfully installed pysqlcipher3" 具有误导性(至少到当前最新的 commit fd1b547407bcb7198107fe3c458105286a060b0d 在 Github repository 上)。我刚刚浪费了一些自己的时间,我想我应该再说清楚。

Linux 系统上也会出现误导性的 “成功安装 pysqlcipher3”。如果您手边有 Ubuntu/Debian 系统,下面的内容将助您一臂之力。基本上,您需要在 pip3 命令之前安装 SQLCipher 库和开发文件。

$ sudo apt install sqlcipher libsqlcipher0 libsqlcipher-dev 
$ sudo -H pip3 install pysqlcipher3 
 
$ python3 -c 'import pysqlcipher3; print(pysqlcipher3.__path__)' 
['/usr/local/lib/python3.7/dist-packages/pysqlcipher3'] 

因为你在 Windows 上,unresolved external symbol RAND_bytes(编译器/链接器错误的第一行)基本上意味着 Windows 上的链接器找不到必要的 OpenSSL 图书馆。

看看帖子here , here , 和 here .他们有解决这个确切的 OpenSSL 链接问题的方法。解决问题的基本步骤如下:

  1. 从 here 下载并安装所需的 32/64 位版本的 OpenSSL
  2. 使 Visual Studio 使用 OpenSSL include 目录,例如C:\OpenSSL-Win32\include
  3. 使 Visual Studio 使用 OpenSSL library 目录,例如C:\OpenSSL-Win32\lib
  4. 在 Visual Studio 中添加以下库作为附加链接器依赖项:
    - libeay32.lib 
    - libeay32MTd.lib 
    - libeay32MT.lib 
    - libeay32MDd.lib 
    - libeay32MD.lib 
    - ssleay32.lib 
    - ssleay32MTd.lib 
    - ssleay32MT.lib 
    - ssleay32MDd.lib 
    - ssleay32MD.lib