安装pysqlcipher3的问题

8 人关注

So even though pip install pysqlcipher3 worked returned Successfully installed pysqlcipher3 , it did not.

从我的研究来看,这似乎是Windows用户试图安装Sqlcipher的一个常见问题。

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

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

However, I end up stuck with this error:

fatal error C1083: Cannot open include file: 'sqlcipher/sqlite3.h': No such file or directory .

我在某处看到(我想),我必须安装 SQLCipher 在安装之前 PySqlCipher3 .

经检查,我发现我必须付费获得预编译的可执行文件,或者自己构建。

So I tried to build it myself following 本教程 .

在安装了所有的要求后,按照步骤我又走到了一个死胡同。在最后一个步骤(第6步)中,当执行 nmake /f Makefile.msc 时我得到了这个错误。

fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory

我的问题是。

  • I read that I need libsqlcipher which might be the issue. Where can I find it (link to executable preferred).
  • How can I solve the issue in my first attempt ?
  • How can I solve the issue in my second attempt ?
  • 我的目标。 是安装了pysqlcipher3并且正在工作。

    EDIT 1 - solved 尝试#2 just to reach another issue

    因此,似乎我在Visual Studio中缺少一些C++功能和工具。因此,通过Visual Studio社区安装程序,我下载并安装了基本的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
        
    python
    installation
    sqlcipher
    pysqlcipher
    Programer Beginner
    Programer Beginner
    发布于 2019-04-01
    3 个回答
    gsbabil
    gsbabil
    发布于 2020-05-19
    已采纳
    0 人赞同

    首先, "Successfully installed pysqlcipher3" 是误导性的(至少到目前最新的 commit fd1b547407bcb7198107fe3c458105286a060b0d on the Github repository ).我刚刚浪费了自己的一些时间,我想我应该再清楚地说明一下。

    误导性的 "Successfully installed pysqlcipher3" 也出现在Linux系统上。如果你手头有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链接问题有解决方案。解决问题的基本步骤如下。

  • Download and install the required 32/64-bit version of OpenSSL from here
  • Make Visual Studio to use the OpenSSL include directory e.g. C:\OpenSSL-Win32\include
  • Make Visual Studio to use the OpenSSL library directory e.g. C:\OpenSSL-Win32\lib
  • Add the following libraries as additional-linker-dependencies in Visual Studio:
  •     - libeay32.lib
        - libeay32MTd.lib
        - libeay32MT.lib
        - libeay32MDd.lib
        - libeay32MD.lib
        - ssleay32.lib
        - ssleay32MTd.lib
        - ssleay32MT.lib
        - ssleay32MDd.lib
        - ssleay32MD.lib
        
    我已经有 sqlcipher 了【替换代码1 libsqlcipher-dev ,仍然面临同样的问题,它说已安装,但没有安装。
    kizuna meraki
    kizuna meraki
    发布于 2020-05-19
    0 人赞同

    在运行Catalina macOS 10.15.4的iMac上,当我试图安装pysqlcipher3时,它吐出了错误信息

    但后来我跑了

    $ brew install SQLCipher
    

    which worked successfully:

    $ brew install SQLCipher
    ==> Downloading https://homebrew.bintray.com/bottles/sqlcipher-4.4.0.catalina.bottle.tar.gz
    ==> Downloading from https://akamai.bintray.com/9e/9e860b50ec668ef30f61377f39954241c4eeda4c4a664fbe1340e289229336bf?__gda__=exp=1590256907~hmac=9bb692e78355e890ab
    ######################################################################## 100.0%
    ==> Pouring sqlcipher-4.4.0.catalina.bottle.tar.gz
    🍺  /usr/local/Cellar/sqlcipher/4.4.0: 13 files, 3.9MB
    

    现在,当我第二次尝试安装pysqlcipher3时,它也安装成功了。

    $ pip3 install pysqlcipher3
    Collecting pysqlcipher3
      Using cached pysqlcipher3-1.0.3.tar.gz (100 kB)
    Building wheels for collected packages: pysqlcipher3
      Building wheel for pysqlcipher3 (setup.py) ... done
      Created wheel for pysqlcipher3: filename=pysqlcipher3-1.0.3-cp37-cp37m-macosx_10_15_x86_64.whl size=61077 sha256=28e480d5999a13cf2446a262cff9d746853d0bf90541a76e473f66a7128ff877
      Stored in directory: /Users/kitzume/Library/Caches/pip/wheels/91/30/b9/1ee85dc50cddf37ecb5198dfa6279aa72eeb0148063b5ad0c6
    Successfully built pysqlcipher3
    Installing collected packages: pysqlcipher3
    Successfully installed pysqlcipher3-1.0.3
        
    MSM
    MSM
    发布于 2020-05-19
    0 人赞同

    我也几乎遇到了你所有的问题,所以我创建了下面这个指南,对我来说很有效。

    My build: windows 10 x64 v1909

  • Install python (if not already installed). I had v3.7 64 bit
  • Install Win64OpenSSL-1_0_2u . Make sure you get exactly this version since I first downloaded some other versions and they didn't work.
  • Add environment variable for both user and system SET OPENSSL_CONF=C:\OpenSSL-Win64\bin\openssl.cfg (change path as per yours)
  • Install ActiveTcl-8.6.9.8609.2-MSWin32-x64 . This was latest at this time and worked
  • Install visual studio (if not already installed). I had VS2019 v16.5.5
  • Get sqlcipher and extract to directory
  • Open visual studio x64 native tools and navigate to above extracted directory of sqlcipher
  • Run command nmake /f Makefile.msc . The final compilation will report an error, but it does not matter, we do not need a real compilation here, only need sqlite3.c
  • Get pysqlcipher3-1.0.3 , extract to directory and navigate to it
  • Create folder named amalgamation in it and create another folder named sqlcipher in amalgamation folder
  • Copy sqlite3.h and sqlite3.c created in Visual Studio step (in sqlcipher-master folder) to amalgamation folder and sqlcipher folder both
  • Open administrative command prompt and navigate to above extracted directory of pysqlcipher3-1.0.3
  • Run following command python setup.py build_amalgamation
  • This will give linkage errors as OP has stated. Now install Win32OpenSSL-1_0_2u . Earlier you installed x64 and now installing x32. I learnt this hack after multiple failures -:)
  • Adjust the environment variables for SSL to point to x32 installed location instead of x64 as done in point-3
  • Close and reopen admin CMD and retype the command python setup.py build_amalgamation . This time it should work well without any errors.
  • Now run following command python setup.py install
  • If all goes well then this command should work in cmd>>python>> from pysqlcipher3 import dbapi2
  • Some Useful Links for me 1 , 2 , 3 , 4 , 5

    如果将来由于链接断了,你没有得到和我一样的准确版本,你可以发表评论,如果我当时有,我会上传到云盘。

    [UPDATE 27-APR-2021 for Python v3.9.4 x64]

  • 我试图对Python v3.9.4 x64重复上述步骤,但由于以下两个原因,又出现了一些错误

    1.1.一个宏 MODULE_NAME 在编译前没有被正确解析。 在评论中指出的。错误将如下。

    srcpython3\c(261): error C2017: illegal escape sequence

    1.2.由于删除了以下功能 some functions in python version 3.9

  • 对于第一个问题,由于该宏是一个预处理器指令(从setup.py文件中提供给cl.exe编译器),错误可以通过一个变通方法来消除,即用合适的替换代码替换所有出现的宏。对于我的系统配置,我将文件夹 pysqlcipher3-1.0.4/src/python3 中所有出现的 MODULE_NAME 替换为 pysqlcipher3.dbapi2 ,从而解决了问题

  •