简体   繁体   English

如何在Windows 7上编译和安装python 2.7的pysqlcipher

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

I have recently installed Python 2.7 on Windows 7. I have also installed setuptools and pip for python, MinGW, Visual C++ for Python , and OpenSSL over the course of my trials. 我最近在Windows 7上安装了Python 2.7。我还在我的试用过程中安装了setuptools和pip for python,MinGW, Visual C ++ for Python和OpenSSL。 All have entries in my %PATH% and I have the environment variables VS90COMNTOOLS and VS100COMNTOOLS pointing to "C:\\Users\\username\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\bin". 所有条目都在我的%PATH%中,我有环境变量VS90COMNTOOLS和VS100COMNTOOLS指向“C:\\ Users \\ username \\ AppData \\ Local \\ Programs \\ Common \\ Microsoft \\ Visual C ++ for Python \\ 9.0 \\ VC \\ bin”。

I have tried several different ways to install this. 我尝试了几种不同的方法来安装它。 I will outline each below. 我将在下面概述每一个。 (all of there were run from an elevated command prompt.) (所有这些都是从提升的命令提示符运行的。)

  1. Download source and compile. 下载源码并编译。

    python setup.py install python setup.py安装

This gives the output: 这给出了输出:

running install
running build
running build_py
running build_ext
building 'pysqlcipher._sqlite' extension
error: Unable to find vcvarsall.bat
  1. Compile source using MinGW 使用MinGW编译源代码

Since after installing VS for Python I still got the same error, I decided to try: 从安装VS for Python后我仍然遇到同样的错误,我决定尝试:

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. 我安装了OpenSSL并再次尝试。 Still the same output. 产量仍然相同。 I also installed pyopenssl. 我还安装了pyopenssl。 Still the same error. 还是一样的错误。

  2. I tried going the easy way: 我尝试过简单的方法:

    easy_install pysqlcipher easy_install pysqlcipher

    pip install pysqlcipher pip install pysqlcipher

These also complain about not being able to find 'openssl/rand.h' 这些也抱怨无法找到'openssl / rand.h'

Does anyone have any ideas how to resolve this so I can compile this package for Windows? 有没有人有任何想法如何解决这个问题,所以我可以为Windows编译这个包? Thanks! 谢谢!

This is most common issue, I have faced. 这是我遇到的最常见的问题。 But I used pytools for Visual Studio 2012 to solve this. 但是我在Visual Studio 2012中使用了pytools来解决这个问题。 After installing pytools a new project category is added in New Project 安装pytools后,新项目中添加了一个新项目类别 在此输入图像描述

Select your python project. 选择你的python项目。 Add python environment from your project Solution Explorer, right click on it and select "Add / Remove Python Environment...". 从项目解决方案资源管理器中添加python环境,右键单击它并选择“添加/删除Python环境...”。 A window will appear with check box option, select your current python version (installed in your system). 将出现一个带复选框选项的窗口,选择当前的python版本(安装在您的系统中)。

在此输入图像描述

An environment will be added like (Here Python 2.7). 将添加一个环境,如(这里是Python 2.7)。 Again right click on it and select "Install Python Package" option. 再次右键单击它并选择“安装Python包”选项。 在此输入图像描述

A window is rise with pip and easy_install option. 使用pip和easy_install选项可以启动窗口。 Now just type your package name eg. 现在只需键入您的包名称,例如。 pyopenssl. pyopenssl。 Check run as administrator. 检查以管理员身份运行 Click ok button 单击确定按钮

在此输入图像描述

在此输入图像描述

Console output determines is your package installed perfectly or not. 控制台输出确定您的包安装是否完美。

I hope this'll help you. 我希望这对你有帮助。

Method 1 方法1

Install the Microsoft Visual C++ Compiler for Python 2.7 安装适用于Python 2.7Microsoft Visual C ++编译器

Update pip 更新点子

python -m pip install -U pip

Update setuptools 更新setuptools

pip install -U setuptools

Use pip to install pysqlcipher 使用pip安装pysqlcipher

pip install pysqlcipher

pip should be able to find your install of the Visual C++ Compiler, and compile the needed extensions. pip应该能够找到你的Visual C ++编译器的安装,并编译所需的扩展。

If for some reason you can't use pip, then try method 2 below. 如果由于某种原因你不能使用pip,那么尝试下面的方法2。


Method 2 方法2

Look in your setup.py If it is an older package it may be importing distutils.core.setup() rather than setuptools.setup() . 查看你的setup.py如果它是一个较旧的软件包,它可能会导入distutils.core.setup()而不是setuptools.setup()

I ran in to this (in 2015) with a combination of these factors: 我参与了这个(2015年)这些因素的组合:

  1. The Microsoft Visual C++ Compiler for Python 2.7 from http://aka.ms/vcpython27 来自http://aka.ms/vcpython27的Microsoft Visual C ++编译器Python 2.7

  2. An older package that uses distutils.core.setup() 使用distutils.core.setup()的旧包

  3. Trying to do python setup.py build rather than using pip . 尝试做python setup.py build而不是使用pip

If you use a recent version of pip, it will force (monkeypatch) the package to use setuptools, even if its setup.py calls for distutils. 如果你使用最新版本的pip,它将强制(monkeypatch)包使用setuptools,即使它的setup.py调用distutils。 However, if you are not using pip, and instead are just doing python setup.py build , the build process will use distutils.core.setup() , which does not know about the compiler install location. 但是,如果您不使用pip,而只是执行python setup.py build ,则构建过程将使用distutils.core.setup() ,它不知道编译器安装位置。

Step 1: Install the Microsoft Visual C++ Compiler for Python 2.7 步骤1:安装适用于Python 2.7Microsoft Visual C ++编译器

Step 2: Open the appropriate Visual C++ 2008 Command Prompt 步骤2:打开相应的Visual C ++ 2008命令提示符

Open the Start menu or Start screen, 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-bit). 打开“开始”菜单或“开始”屏幕,然后搜索“Visual C ++ 2008 32位命令提示符”(如果您的python是32位)或“Visual C ++ 2008 64位命令提示符”(如果您的python是64位) 。 Run it. 运行。 The command prompt should say Visual C++ 2008 ... in the title bar. 命令提示符应该在标题栏中显示Visual C ++ 2008 ....

Step 3: Set environment variables 第3步:设置环境变量

Set these environment variables in the command prompt you just opened. 在刚刚打开的命令提示符中设置这些环境变量。

SET DISTUTILS_USE_SDK=1
SET MSSdk=1

Reference http://bugs.python.org/issue23246 参考http://bugs.python.org/issue23246

Step 4: Build and install 第4步:构建并安装

cd to the package you want to build, and run python setup.py build , then python setup.py install . cd到你想要构建的包,并运行python setup.py build ,然后运行python setup.py install If you want to install in to a virtualenv, activate it before you build. 如果要安装到virtualenv中,请在构建之前将其激活。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM