安装pysqlcipher3

时间:2019-03-31 23:35:47

标签: python install sqlcipher pysqlcipher

因此,即使pip install pysqlcipher3工作成功返回Successfully installed pysqlcipher3,也没有成功。

根据我的研究,看来Windows用户尝试安装Sqlcipher是一个常见问题。

尝试#1

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

执行python3 setup.py build时出现了一些错误(缺少一些要求,环境变量中没有OPENSSL_CONF ...等),但是我修复了大多数错误。

但是,我最终陷于此错误:

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

尝试#2

我读到某个地方(我认为),必须先安装 SQLCipher ,然后再安装 PySqlCipher3

经检查,我发现我必须付费才能获得预构建的可执行文件,也可以自己构建。

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

在安装所有要求之后,并按照步骤进行操作,我又陷入了僵局。在最后一步(第6步)中,执行nmake /f Makefile.msc时出现此错误:

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


我的问题是:

  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

3 个答案:

答案 0 :(得分:3)

我几乎也遇到了您的所有问题,因此我在下面创建了适用于我的本指南

我的构建:Windows 10 x64 v1909

  1. 安装python(如果尚未安装)。我有v3.7 64位
  2. 安装Win64OpenSSL-1_0_2u。确保自我首次下载其他版本以来,您确实获得了该版本,而其他版本则无效。
  3. 为用户和系统SET OPENSSL_CONF=C:\OpenSSL-Win64\bin\openssl.cfg添加环境变量(根据您的情况更改路径)
  4. 安装ActiveTcl-8.6.9.8609.2-MSWin32-x64。这是最近一次并有效
  5. 安装Visual Studio(如果尚未安装)。我有VS2019 v16.5.5
  6. 获取sqlcipher并提取到目录
  7. 打开Visual Studio x64本机工具,然后导航到上面提取的sqlcipher目录中
  8. 运行命令nmake /f Makefile.msc。最终编译将报告错误,但这没关系,我们在这里不需要真正的编译,只需要sqlite3.c
  9. 获取pysqlcipher3-1.0.3,解压缩到目录并导航到它
  10. 在其中创建名为amalgamation的文件夹,并在sqlcipher文件夹中创建另一个名为amalgamation的文件夹
  11. 将在Visual Studio步骤(在sqlite3.h文件夹中创建的sqlite3.csqlcipher-master复制到amalgamation文件夹和sqlcipher文件夹中
  12. 打开管理命令提示符,然后导航到上面提取的pysqlcipher3-1.0.3目录
  13. 运行以下命令python setup.py build_amalgamation
  14. 如OP所述,这将导致链接错误。现在安装Win32OpenSSL-1_0_2u。之前安装了x64,现在安装了x32。多次失败后,我学会了这种技巧-:)
  15. 调整SSL的环境变量以使其指向x32安装位置,而不是像在第3点中那样指向x64
  16. 关闭并重新打开admin CMD,然后重新输入命令python setup.py build_amalgamation。这次应该可以正常工作了,没有任何错误。
  17. 现在运行命令python setup.py install
  18. 如果一切正常,则此命令应在cmd >> python >> from pysqlcipher3 import dbapi2
  19. 中运行

一些对我有用的链接12345

如果由于将来链接断开而无法获得确切的版本,则可以发表评论,如果那时我有,我将上传到云驱动器。

答案 1 :(得分:1)

首先,"Successfully installed pysqlcipher3"具有误导性(至少是commit fd1b547407bcb7198107fe3c458105286a060b0d上最新的Github repository)。我刚刚浪费了一些时间,并认为我应该再说一遍。

误导性的"Successfully installed pysqlcipher3"也出现在Linux系统上。万一您有一个Ubuntu / Debian系统,以下将帮助您。基本上,您需要在SQLCipher命令之前安装pip3库和开发文件。

$ 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库。

查看帖子hereherehere。他们有解决此确切的OpenSSL链接问题的方法。解决问题的基本步骤如下:

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

答案 2 :(得分:1)

在运行Catalina macOS 10.15.4的iMac上,当我尝试安装pysqlcipher3时,它会吐出错误消息

但是我跑了

$ brew install SQLCipher

工作成功:

$ 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
相关问题