How to compile and install pysqlcipher for python 2.7 on Windows 7

I recently installed Python 2.7 on Windows 7. I also installed setuptools and pip for python, MinGW, Visual C ++ for Python, and OpenSSL during my testing. They all have entries in my% PATH% and I have VS90COMNTOOLS and VS100COMNTOOLS environment variables pointing to "C: \ Users \ username \ AppData \ Local \ Programs \ Common \ Microsoft \ Visual C ++ for Python \ 9.0 \ VC \ bin ".

I tried several different ways to set this up. I'll describe each below. (All of these were executed from an elevated command prompt.)

  • Download the source code and compile.

    installing python setup.py

This gives the result:

running install
running build
running build_py
running build_ext
building 'pysqlcipher._sqlite' extension
error: Unable to find vcvarsall.bat

      

  1. Compile source with MinGW

Since after installing VS for Python I still got the same error, I decided to try:

setup.py install build --compiler=mingw32

      

Output:

running install
running build
running build_py
running build_ext
building 'pysqlcipher._sqlite' extension
D:\Developer\MinGW\bin\gcc.exe -mdll -O -Wall -DMODULE_NAME=\"pysqlcipher.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABL
E_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Iamalgamation -ID:\Developer\Pyth
on27\include -ID:\Developer\Python27\PC -c src/module.c -o build\temp.win32-2.7\Release\src\module.o
D:\Developer\MinGW\bin\gcc.exe -mdll -O -Wall -DMODULE_NAME=\"pysqlcipher.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABL
E_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Iamalgamation -ID:\Developer\Pyth
on27\include -ID:\Developer\Python27\PC -c src/connection.c -o build\temp.win32-2.7\Release\src\connection.o
src/connection.c: In function '_pysqlite_final_callback':
src/connection.c:787:15: warning: variable 'aggregate_class' set but not used [-Wunused-but-set-variable]
     PyObject* aggregate_class;
               ^
D:\Developer\MinGW\bin\gcc.exe -mdll -O -Wall -DMODULE_NAME=\"pysqlcipher.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABL
E_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Iamalgamation -ID:\Developer\Pyth
on27\include -ID:\Developer\Python27\PC -c src/cursor.c -o build\temp.win32-2.7\Release\src\cursor.o
src/cursor.c: In function 'pysqlite_cursor_dealloc':
src/cursor.c:129:9: warning: variable 'rc' set but not used [-Wunused-but-set-variable]
     int rc;
         ^
D:\Developer\MinGW\bin\gcc.exe -mdll -O -Wall -DMODULE_NAME=\"pysqlcipher.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABL
E_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Iamalgamation -ID:\Developer\Pyth
on27\include -ID:\Developer\Python27\PC -c src/cache.c -o build\temp.win32-2.7\Release\src\cache.o
D:\Developer\MinGW\bin\gcc.exe -mdll -O -Wall -DMODULE_NAME=\"pysqlcipher.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABL
E_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Iamalgamation -ID:\Developer\Pyth
on27\include -ID:\Developer\Python27\PC -c src/microprotocols.c -o build\temp.win32-2.7\Release\src\microprotocols.o
D:\Developer\MinGW\bin\gcc.exe -mdll -O -Wall -DMODULE_NAME=\"pysqlcipher.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABL
E_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Iamalgamation -ID:\Developer\Pyth
on27\include -ID:\Developer\Python27\PC -c src/prepare_protocol.c -o build\temp.win32-2.7\Release\src\prepare_protocol.o

D:\Developer\MinGW\bin\gcc.exe -mdll -O -Wall -DMODULE_NAME=\"pysqlcipher.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABL
E_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Iamalgamation -ID:\Developer\Pyth
on27\include -ID:\Developer\Python27\PC -c src/statement.c -o build\temp.win32-2.7\Release\src\statement.o
src/statement.c: In function 'pysqlite_statement_dealloc':
src/statement.c:408:9: warning: variable 'rc' set but not used [-Wunused-but-set-variable]
     int rc;
         ^
D:\Developer\MinGW\bin\gcc.exe -mdll -O -Wall -DMODULE_NAME=\"pysqlcipher.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABL
E_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Iamalgamation -ID:\Developer\Pyth
on27\include -ID:\Developer\Python27\PC -c src/util.c -o build\temp.win32-2.7\Release\src\util.o
D:\Developer\MinGW\bin\gcc.exe -mdll -O -Wall -DMODULE_NAME=\"pysqlcipher.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABL
E_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Iamalgamation -ID:\Developer\Pyth
on27\include -ID:\Developer\Python27\PC -c src/row.c -o build\temp.win32-2.7\Release\src\row.o
D:\Developer\MinGW\bin\gcc.exe -mdll -O -Wall -DMODULE_NAME=\"pysqlcipher.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABL
E_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Iamalgamation -ID:\Developer\Pyth
on27\include -ID:\Developer\Python27\PC -c amalgamation\sqlite3.c -o build\temp.win32-2.7\Release\amalgamation\sqlite3.o

amalgamation\sqlite3.c:13654:26: fatal error: openssl/rand.h: No such file or directory
 #include <openssl/rand.h>
                          ^
compilation terminated.
error: command 'D:\\Developer\\MinGW\\bin\\gcc.exe' failed with exit status 1

      

  1. I installed OpenSSL and tried again. All the same conclusion. I also installed pyopenssl. Still the same error.

  2. I tried to make a simple way:

    easy_install pysqlcipher

    pip install pysqlcipher

They also complain that they couldn't find "openssl / rand.h"

Does anyone have any ideas how to resolve this so that I can compile this package for Windows? Thank!

+3


source to share


2 answers


Method 1

Install Microsoft Visual C ++ Compiler for Python 2.7

Refresh pip

python -m pip install -U pip

      

Update setuptools

pip install -U setuptools

      

Use pip to install pysqlcipher

pip install pysqlcipher

      

pip

should be able to find your Visual C ++ compiler installation and compile the required extensions.

If for some reason you are unable to use pip, then try method 2. below.


Method 2

Look at setup.py

If this is an older package, it might import distutils.core.setup()

instead setuptools.setup()

.



I ran into this (in 2015) with a combination of these factors:

  • Microsoft Visual C ++ Compiler for Python 2.7 from http://aka.ms/vcpython27

  • An older package that uses distutils.core.setup()

  • Trying to do python setup.py build

    instead of using pip

    .

If you are using a recent version of pip, it will force (monkeypatch) the package to use setuptools even if setup.py

distutils calls it. However, if you are not using pip, but simply executing python setup.py build

, the build process will use distutils.core.setup()

that is unaware of where the compiler is installed.

Step 1: Install Microsoft Visual C ++ Compiler for Python 2.7

Step 2: Open the appropriate command line of Visual C ++ 2008

Open the Start or Start menu and search for "Visual C ++ 2008 32-bit Command Prompt" (if your python is 32-bit) or Visual C ++ 2008 64-bit Command Prompt (if your python is 64 -Little). Run it. The command line should specify Visual C ++ 2008 ... in the title bar.

Step 3: Set Environment Variables

Set these environment variables in the command line that just opened.

SET DISTUTILS_USE_SDK=1
SET MSSdk=1

      

Link http://bugs.python.org/issue23246

Step 4: Build and Install

cd

to the package you want to build and run python setup.py build

then python setup.py install

. If you want to install in virtualenv, activate it before building.

+1


source


This is the most common problem I've encountered. But I used pytools for Visual Studio 2012 to solve this problem. After installing pytools, a new new project category is added to New Projectenter image description here

Select your python project. Add the python environment from your Solution Explorer project, right click on it and select Add / Remove Python Environment .... A checkbox will appear, select your current python version (installed on your system).

enter image description here

An environment like (here Python 2.7) will be added. Right click on it again and select Install Python Package. enter image description here

The window grows with pip and easy_install option. Now just enter the name of your package eg. pyopenssl. Check startup as administrator. Click ok



enter image description here

enter image description here

The console output determines if your package is installed perfectly or not.

Hope this helps you.

+1


source







All Articles