pysqlcipher3_安装pysqlcipher3时出现问题

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

From my research, it seems that its a common issue for Windows user trying to install Sqlcipher.

Attempt #1

First, I try to download the pysqlcipher3 from github and build and install it manually via cmd (using python setup.py build and python seetup.py install).

Upon executing python3 setup.py build I got some error (missing few requirements, not having OPENSSL_CONF in environment variable...etc.) but I fix most of them.

However, I end up stuck with this error:

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

Attempt #2

I read somewhere (I think) that I have to install the SQLCipher before installing the PySqlCipher3.

Upon checking, I found out that I have to either pay to get a prebuild executable or build it myself.

So I tried to build it myself following this tutorial.

After installing all requirements, and following the steps I reach another dead end. In the before-last step (step number 6), when executing nmake /f Makefile.msc I got this error:

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

My question are:

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?

My goal: Is to have pysqlcipher3 installed and working.

EDIT 1 - solved Attempt #2 just to reach another issue

So it seems that I was missing some C++ features and tool in Visual Studio. So via Visual Studio Community installer, I download and install basic C++ stuff and it fixed the error.

I got another error which I fix by copying OpenSSL-Win64\include folder to C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include.

However, now I am stuck with this error:

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

解决方案

I also had almost all of your problems and so I created this guide below which worked for me

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

If you don't get exact versions as mine due to links broken in future, you can comment and if I have them at that time, I'll upload to a cloud drive.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值