Python 安装pysqlcipher3时出现的问题

Python 安装pysqlcipher3时出现的问题,python,installation,sqlcipher,pysqlcipher,Python,Installation,Sqlcipher,Pysqlcipher,因此,即使pip安装pysqlcipher3成功地安装了pysqlcipher3,它也没有成功 根据我的研究,这似乎是Windows用户试图安装Sqlcipher的常见问题 尝试#1 首先,我尝试从github下载pysqlcipher3,并通过cmd手动构建和安装它(使用python setup.py build和python seetup.py install) 在执行python3 setup.py build时,我遇到了一些错误(缺少一些要求,环境变量中没有OPENSSL_CONF…等等

因此,即使
pip安装pysqlcipher3
成功地安装了pysqlcipher3,它也没有成功

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

尝试#1

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

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

但是,我最终遇到了这个错误:

致命错误C1083:无法打开包含文件:“sqlcipher/sqlite3.h”:没有此类文件或目录

尝试#2

我在某个地方读到(我想)我必须在安装PySqlCipher3之前安装SQLCipher

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

所以我试着自己建造它

在安装了所有需求之后,按照这些步骤,我到达了另一个死胡同。在前一个步骤(步骤6)中,当执行
nmake/f Makefile.msc时,我得到了以下错误:

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
致命错误C1083:无法打开包含文件:“stdio.h”:没有此类文件或目录


我的问题是:

  • 我读到我需要
    libsqlcipher
    ,这可能就是问题所在。我在哪里可以找到它(链接到可执行文件优先)
  • 我如何在第一次尝试时解决这个问题
  • 如何在第二次尝试时解决此问题
  • 我的目标:是安装pysqlcipher3并使其正常工作


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

    <>看起来我在VisualStudio中缺少了一些C++特性和工具。因此,通过VisualStudio社区安装程序,我下载并安装了基本C++的东西,并修复了错误。 我得到了另一个错误,我通过将
    OpenSSL-Win64\include
    文件夹复制到
    C:\ProgramFiles(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
    
    首先,
    “成功安装pysqlcipher3”
    具有误导性(至少是最新版本)。我只是浪费了我自己的一些时间,我想我应该再次澄清

    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上,
    未解析的外部符号RAND_bytes
    (编译器/链接器错误的第一行)基本上意味着您在Windows上的链接器找不到必要的
    OpenSSL

    看看这些帖子,然后。他们有解决这个OpenSSL链接问题的解决方案。解决问题的基本步骤如下:

  • 从下载并安装所需的32/64位版本的OpenSSL
  • 使Visual Studio使用
    OpenSSL
    include目录,例如
    C:\OpenSSL-Win32\include
  • 使Visual Studio使用
    OpenSSL
    目录,例如
    C:\OpenSSL-Win32\lib
  • 在Visual Studio中添加以下库作为其他链接器依赖项:

  • 我也有你几乎所有的问题,所以我在下面创建了这个指南,它对我有用

    我的版本:windows 10 x64 v1909

  • 安装python(如果尚未安装)。我有v3.7 64位
  • 安装。确保你得到的正是这个版本,因为我第一次下载了一些其他版本,但它们不起作用
  • 为用户和系统添加环境变量
    设置OPENSSL\u CONF=C:\OPENSSL-Win64\bin\OPENSSL.cfg
    (根据您的更改路径)
  • 安装。这是最新的一次,而且奏效了
  • 安装visual studio(如果尚未安装)。我有VS2019 v16.5.5
  • 获取并解压缩到目录
  • 打开visual studio x64本机工具并导航到上面提取的
    sqlcipher
  • 运行命令nmake/f Makefile.msc
  • 。最终的编译将报告一个错误,但这并不重要,我们这里不需要真正的编译,只需要
    sqlite3.c
  • 获取、解压缩到目录并导航到它
  • 在其中创建名为
    mergation
    的文件夹,并在
    mergation
    文件夹中创建另一个名为
    sqlcipher
    的文件夹
  • 将在Visual Studio步骤中创建的
    sqlite3.h
    sqlite3.c
    复制到
    mergation
    文件夹和
    sqlcipher
    文件夹
  • 打开管理命令提示符并导航到上面提取的目录
    pysqlcipher3-1.0.3
  • 运行以下命令
    python setup.py build\u migration
  • 如OP所述,这将产生联动误差。现在安装。之前安装的是x64,现在安装的是x32。在多次失败后,我学会了这种技巧——:)
  • 调整SSL的环境变量,使其指向x32安装位置,而不是第3点中的x64
  • 关闭并重新打开admin CMD,然后重新键入命令
    python setup.py build\u migration
    。这一次,它应该运行良好,没有任何错误
  • 现在运行以下命令
    python setup.py install
  • 如果一切顺利,那么这个命令应该可以在pysqlcipher3 import dbapi2的cmd>>python>>
    中运行
  • 一些对我有用的链接

    如果你没有得到确切的版本,因为我的链接中断
    $ brew install SQLCipher