Pro*_*ner 6 python installation sqlcipher pysqlcipher
所以即使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: Cannot open include file: 'sqlcipher/sqlite3.h': No such file or directory.
尝试#2
我在某处读到(我认为)我必须在安装PySqlCipher3之前安装SQLCipher。
经过检查,我发现我必须付费才能获得预构建的可执行文件或自己构建它。
所以我尝试按照本教程自己构建它。
安装完所有要求并按照步骤操作后,我到达了另一个死胡同。在最后一步(第 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 社区安装程序,我下载并安装了基本的 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
Run Code Online (Sandbox Code Playgroud)
首先,"Successfully installed pysqlcipher3"具有误导性(至少截至Github 存储库上当前最新提交 fd1b547407bcb7198107fe3c458105286a060b0d)。我刚刚浪费了一些自己的时间,我想我应该再把话说清楚。
这种误导"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']
Run Code Online (Sandbox Code Playgroud)
由于您使用的是 Windows,unresolved external symbol RAND_bytes(编译器/链接器错误的第一行)基本上意味着 Windows 上的链接器找不到必要的OpenSSL库。
请查看此处、此处和此处的帖子。他们有针对这个 OpenSSL 链接问题的解决方案。解决问题的基本步骤如下:
OpenSSL 包含目录,例如C:\OpenSSL-Win32\includeOpenSSL 库目录,例如C:\OpenSSL-Win32\lib - libeay32.lib
- libeay32MTd.lib
- libeay32MT.lib
- libeay32MDd.lib
- libeay32MD.lib
- ssleay32.lib
- ssleay32MTd.lib
- ssleay32MT.lib
- ssleay32MDd.lib
- ssleay32MD.lib
Run Code Online (Sandbox Code Playgroud)
我也遇到了几乎所有的问题,所以我创建了下面的指南,它对我有用
我的版本:Windows 10 x64 v1909
SET OPENSSL_CONF=C:\OpenSSL-Win64\bin\openssl.cfg(根据您的更改路径)sqlciphernmake /f Makefile.msc。最终编译会报错,不过没关系,我们这里不需要真正的编译,只需要sqlite3.camalgamationin 的文件夹,并创建另一个名为sqlcipherin 的amalgamation文件夹sqlite3.h并sqlite3.c在 Visual Studio 步骤(在sqlcipher-master文件夹中)中创建到amalgamation文件夹和sqlcipher文件夹pysqlcipher3-1.0.3python setup.py build_amalgamationpython setup.py build_amalgamation。这次应该可以正常工作,不会出现任何错误。python setup.py installfrom pysqlcipher3 import dbapi2如果由于将来链接损坏而导致您无法获得与我的确切版本,您可以发表评论,如果当时我有它们,我将上传到云驱动器。
我尝试对 Python v3.9.4 x64 重复上述步骤,但由于以下两个原因出现了更多错误
1.1. MODULE_NAME正如 @ProfP30 在注释中指出的那样,在编译之前未正确解析宏。错误将如下:
src\python3\cache.c(261): 错误 C2017: 非法转义序列
1.2. 由于Python 3.9版本中删除了一些函数的功能
对于第一个问题,由于该宏是一个预处理器指令(从 setup.py 文件提供给 cl.exe 编译器),因此可以通过解决方法将所有出现的错误替换为合适的替换,从而消除错误。对于我的系统配置,我替换了解决问题的MODULE_NAME文件夹中pysqlcipher3-1.0.4/src/python3出现的所有内容pysqlcipher3.dbapi2
对于第二个问题,解决方案是手动提供从 Python v>3.8 中删除的所有函数的替换。这对我来说很烦人。幸运的是,pysqlcipher3 1.0.4几天前(21年4月25日)刚刚发布的版本已经解决了这个问题并提供了替代品。因此,更好的方法是使用源文件,pysqlcipher3 1.0.4而不是像pysqlcipher3 1.0.3上面第 9 点那样。
为了避免编译 pysqlcipher3 的所有麻烦,我在此链接中放置了 Python v3.9.4 x64 的预编译二进制文件以及说明。(免责声明:由于存储限制,该链接将来可能会被删除。)
| 归档时间: |
|
| 查看次数: |
4189 次 |
| 最近记录: |