因此,即使pip install pysqlcipher3
工作成功返回Successfully installed pysqlcipher3
,也没有成功。
根据我的研究,看来Windows用户尝试安装Sqlcipher是一个常见问题。
尝试#1
首先,我尝试从github下载pysqlcipher3并通过cmd手动构建和安装(使用python setup.py build
和python 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
我的问题是:
libsqlcipher
,这可能是问题所在。在哪里可以找到它(首选链接到可执行文件)。我的目标:是要安装并运行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
答案 0 :(得分:3)
我几乎也遇到了您的所有问题,因此我在下面创建了适用于我的本指南
我的构建:Windows 10 x64 v1909
SET OPENSSL_CONF=C:\OpenSSL-Win64\bin\openssl.cfg
添加环境变量(根据您的情况更改路径)sqlcipher
目录中nmake /f Makefile.msc
。最终编译将报告错误,但这没关系,我们在这里不需要真正的编译,只需要sqlite3.c
amalgamation
的文件夹,并在sqlcipher
文件夹中创建另一个名为amalgamation
的文件夹sqlite3.h
文件夹中创建的sqlite3.c
和sqlcipher-master
复制到amalgamation
文件夹和sqlcipher
文件夹中pysqlcipher3-1.0.3
目录python setup.py build_amalgamation
python setup.py build_amalgamation
。这次应该可以正常工作了,没有任何错误。python setup.py install
from pysqlcipher3 import dbapi2
如果由于将来链接断开而无法获得确切的版本,则可以发表评论,如果那时我有,我将上传到云驱动器。
答案 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
库。
查看帖子here,here和here。他们有解决此确切的OpenSSL链接问题的方法。解决问题的基本步骤如下:
OpenSSL
include 目录,例如C:\OpenSSL-Win32\include
OpenSSL
库目录,例如C:\OpenSSL-Win32\lib
- 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