`

python安装插件方法

 
阅读更多

Compiling Python 2.7 Modules on Windows 32 and 64 using MSVC++ 2008 Express

 

Hello,

On this post i will explain how to build, compile, install and distribute python modules on Windows using Microsoft Visual C++ Express Edition.
This post will be constantly updated to cover future updates of python, windows and msvc++ versions.

For this example i will use the  PyCrypto – http://pycrypto.org   because this is an example that don’t have packages for windows x64 on the web.

Observation: Don’t use Microsoft Visual C++ Express Edition 2010 to build python modules, because this will not work due to Python 2.7 was built using the 2008 version. This is an error that occurs when you try to build PyCrypto and Paramiko using the 2010 version and execute the import module:

>>> import paramiko
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\paramiko\__init__.py", line 69, in <module>
    from transport import SecurityOptions, Transport
  File "C:\Python27\lib\site-packages\paramiko\transport.py", line 32, in <module>
    from paramiko import util
  File "C:\Python27\lib\site-packages\paramiko\util.py", line 32, in <module>
    from paramiko.common import *
  File "C:\Python27\lib\site-packages\paramiko\common.py", line 98, in <module>
    from Crypto import Random
  File "C:\Python27\lib\site-packages\Crypto\Random\__init__.py", line 28, in <module>
    import OSRNG
  File "C:\Python27\lib\site-packages\Crypto\Random\OSRNG\__init__.py", line 34, in <module>
    from Crypto.Random.OSRNG.nt import new
  File "C:\Python27\lib\site-packages\Crypto\Random\OSRNG\nt.py", line 28, in <module>
    import winrandom
ImportError: DLL load failed: The specified module could not be found.

1 – Building and Installing PyCrypto Module for Windows 7 64 bits:

1.1 -   You must have installed the Python 64 bits version:  http://www.python.org/ftp/python/2.7.1/python-2.7.1.amd64.msi

1.2 -   You should install the C Compiler for Windows –  Microsoft Visual C++ Express Edition 2008 : available here:http://www.microsoft.com/express/Downloads/#Visual_Studio_2008_Express_Downloads

ISO File to Download:  http://www.microsoft.com/express/Downloads/#2008-All

1.3 -   You should install the  Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 : available here:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c17ba869-9671-4330-a63e-1fd44e0e2505

ISO File To Download (64 bits):  http://download.microsoft.com/download/2/E/9/2E911956-F90F-4BFB-8231-E292A7B6F287/GRMSDKX_EN_DVD.iso

This is required because the Express Edition 2008 C++ don’t contains the 64 bits compiler. This is required only for Windows 7 64 bits version.

Important: Don’t use the “Microsoft Windows SDK for Windows 7 and .NET Framework 4″ because it’s not compatible with msvc++ express 2008 edition.

1.4 -   Install the Python Setup Tools available here:  http://pypi.python.org/pypi/setuptools#downloads

1.5 -   Include in your Advanced Variables Environment the binaries of Python. Right click at “My Computer” icon -> Properties -> Advanced Environment and edit your Path Variable including this two directories there:
Path = C:\Python27\Scripts;C:\Python27; + Path

1) C:\Python27\Scripts
2) C:\Python27

1.6 -   Copy this file:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat

To this follow folder and rename the file (vcvars64.bat to vcvarsamd64.bat):

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat

1.7 -   Edit the file  msvc9compiler.py   inside of directory  C:\Python27\Lib\distutils\msvc9compiler.py

After the line 651 approximately, find this line: –  ld_args.append(‘/MANIFESTFILE:’ + temp_manifest)
Add the following line after the above line:

ld_args.append('/MANIFEST')

1.8 -   Edit the file  msvccompiler.py   inside of directory  C:\Python27\Lib\distutils\msvccompiler.py

At line 153 approximately, insert this line:  return 9.0 , as following, in this piece of code:

def get_build_version():
    """Return the version of MSVC that was used to build Python.

    For Python 2.3 and up, the version number is included in
    sys.version.  For earlier versions, assume the compiler is MSVC 6.
    """
    return 9.0
    prefix = "MSC v."
    i = string.find(sys.version, prefix)
    if i == -1:
        return 6

1.9 -   Certify that exists the follow environment variable in your system, if don’t exist create a new one:

Name: VS90COMNTOOLS
Value: C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\

1.10 -   Extract the file pycrypto-2.3.tar.gz that you downloaded before, open a dos command and access the pycrypto-2.3 folder

1.11 -   Execute this command to compile, build and install the module:

python setup.py build --compiler msvc
python setup.py install

1.12 -   Test if the package was generated successfully executing an  import Crypto   at Python shell.

1.13 -   It’s finish. Optionally, you can distribute your compiled modules as an windows executable (.exe) file, executing this simple command on folder of your module, this case is pycrypto-2.3:

python setup.py bdist_wininst

As a result you will get a executable file with graphical interface created inside of folder “dist” and other people can install this executable file without to prepare a complex environment for build your own module. This is my result file of this process.  http://arquivos.victorjabur.com/python/modules/pycrypto-2.3.win-amd64-py2.7.exe

2 – Building and Installing PyCrypto Module for Windows All Versions 32 bits:

2.1 -   You must have installed the Python 32 bits version:  http://www.python.org/ftp/python/2.7.1/python-2.7.1.msi

2.2 -   You should install the C Compiler for Windows –  Microsoft Visual C++ Express Edition 2008 : available here:http://www.microsoft.com/express/Downloads/#Visual_Studio_2008_Express_Downloads

ISO File to Download:  http://www.microsoft.com/express/Downloads/#2008-All

2.3 -   Install the Python Setup Tools available here:  http://pypi.python.org/pypi/setuptools#downloads

2.4 -   Include in your Advanced Variables Environment the binaries of Python. Right click at “My Computer” icon -> Properties -> Advanced Environment and edit your Path Variable including this two directories there:
Path = C:\Python27\Scripts;C:\Python27; + Path

1) C:\Python27\Scripts
2) C:\Python27

2.5 -   Edit the file  msvc9compiler.py   inside of directory  C:\Python27\Lib\distutils\msvc9compiler.py

After the line 651 approximately, find this line: –  ld_args.append(‘/MANIFESTFILE:’ + temp_manifest)
Add the following line after the above line:

ld_args.append('/MANIFEST')

2.6 -   Edit the file  msvccompiler.py   inside of directory  C:\Python27\Lib\distutils\msvccompiler.py

At line 153 approximately, insert this line:  return 9.0 , as following, in this piece of code:

def get_build_version():
    """Return the version of MSVC that was used to build Python.

    For Python 2.3 and up, the version number is included in
    sys.version.  For earlier versions, assume the compiler is MSVC 6.
    """
    return 9.0
    prefix = "MSC v."
    i = string.find(sys.version, prefix)
    if i == -1:
        return 6

2.7 -   Certify that exists the follow environment variable in your system, if don’t exist create a new one:

Name: VS90COMNTOOLS
Value: C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\

2.8 -   Extract the file pycrypto-2.3.tar.gz that you downloaded before, open a dos command and access the pycrypto-2.3 folder

2.9 -   Execute this command to compile, build and install the module:

python setup.py build --compiler msvc
python setup.py install

2.10 -   Test if the package was generated successfully executing an  import Crypto   at Python shell.

2.11 -   It’s finish. Optionally, you can distribute your compiled modules as an windows executable (.exe) file, executing this simple command on folder of your module, this case is pycrypto-2.3:

python setup.py bdist_wininst

As a result you will get a executable file with graphical interface created inside of folder “dist” and other people can install this executable file without to prepare a complex environment for build your own module. This is my result file of this process.  http://arquivos.victorjabur.com/python/modules/pycrypto-2.3.win32-py2.7.exe

Credits and References to this post:

http://nukeit.org/compile-python-2-7-packages-with-visual-studio-2010-express/
http://yorickdowne.wordpress.com/2010/12/22/compiling-pycrypto-on-win7-64/
http://www.lfd.uci.edu/~gohlke/pythonlibs/
http://www.fuyun.org/2009/12/install-mysql-for-python-on-windows/
http://mattptr.net/2010/07/28/building-python-extensions-in-a-modern-windows-environment/

Good Bye.
Victor Jabur

分享到:
评论

相关推荐

    python安装及插件.zip

    另外,"Eclipse Python插件安装.doc"文档很可能是提供更详细的PyDev安装步骤和使用指南。用户应仔细阅读该文档,以确保正确安装并充分利用PyDev的所有功能。 在使用PyDev进行Python开发时,你可以创建新的Python...

    python安装工具及安装步骤.zip

    python安装工具及安装步骤python安装工具及安装步骤python安装工具及安装步骤 python安装工具及安装步骤 python安装工具及安装步骤 python安装工具及安装步骤python安装工具及安装步骤python安装工具及安装步骤...

    PythonOCC的安装

    #### 三、PythonOCC的安装方法 PythonOCC的安装有多种途径,其中最简便的方式之一是通过Anaconda环境进行安装。下面是详细的安装步骤: #### 四、安装Anaconda Anaconda是一款非常方便的科学计算软件包管理系统及...

    PythonScript插件用于notepad++的

    安装PythonScript插件的过程相当简单。首先,你需要下载与Notepad++版本兼容的PythonScript插件包,例如提供的"PythonScript_1.0.8.0.msi"文件。这通常是一个安装程序,可以双击运行。按照安装向导的指示进行操作,...

    Python 3.11.4(64-bit)软件安装

    Python 3.11.4(64-bit)软件安装指南 Python 是一种广泛使用的高级编程语言,具有简洁的语法和强大的功能。安装 Python 软件是使用 Python 语言进行开发的第一步骤。下面是 Python 3.11.4(64-bit)软件安装指南。 ...

    Eclipse安装python插件

    Eclipse安装python插件

    python和scons安装

    Python和SCons是两个在软件开发领域常用的工具。Python是一种高级编程语言,以其简洁明了的语法和强大的功能而受到广泛欢迎。SCons则是一个构建工具,它使用Python编写,用于自动化软件构建过程,替代传统的Make工具...

    python2.7安装以及所有的软件

    本资源是Python2.7.10版本的安装软件,以及安装过程中遇到问题的所有讲解

    Pycharm安装python库的方法

    到此这篇关于Pycharm安装python库的方法的文章就介绍到这了,更多相关Pycharm安装python库内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网! 您可能感兴趣的文章:Pycharm中...

    计算机二级Python考试软件安装包及安装说明

    该软件安装包内含有一系列综合性功能,旨在为考生提供一个与正式考试尽可能相似的界面和操作体验。通过本软件,用户可以熟悉官方的考试流程、题型和界面布局,以减少在实际考试中因不熟悉环境带来的不必要的紧张情绪...

    Python PIP安装软件

    该资源主要是Python的PIP安装软件,主要包括四个文件: python-2.7.8.amd64.msi,这个你可以在官网下载适合自己的版本。 另一个是pip-Win_1.7.exe软件,但强烈推荐大家安装完Python环境后,双击get-pip.py软件即可...

    为eclipse安装Python插件

    本文将详细介绍如何在Eclipse中安装Python插件,以便在Eclipse中愉快地编写Python代码。 首先,你需要了解Eclipse的扩展性是通过插件机制实现的。Eclipse拥有一个庞大的插件市场,其中包含了许多针对不同编程语言的...

    sublime python插件+安装方法+将sublime添加到右键

    下面将详细介绍如何安装Python插件以及如何将Sublime Text添加到Windows系统的右键菜单,以便快速打开文件。 首先,安装Python插件通常通过Sublime Text的包管理器——Package Control来完成。Package Control是...

    python64 位安装32位python

    ---python64 位安装32位python 原来安装的是64位,打包出来的程序也是64,到WIN7 32 上运行不了,需要安装32位python. 安装步骤如下: 1:安装32位python python-3.7.2_x86.exe 安装路径如下,添加到系统path C:\...

    notepad++下PythonScript插件

    写在前面:该插件可以直接在notepad++插件管理器中安装,如果安装完之后,运行出现: Unknown exception和python script plugin did not accept the script的报错提示,一般在window7/8/10 64位系统报错。...

    aix7.1的python安装.rar

    AIX的软件更新可以通过`installp -u`命令进行,但Python的更新可能需要重复上述安装步骤。 7. 开发和运行Python应用: 现在你已经在AIX 7.1上安装了Python,可以开始编写和运行Python代码了。你可以使用`python`或...

    ida7.0插件Python_editor全部安装包

    比如你的python安装目录是C:\python27-x64 添加环境变量 PYTHONHOME=C:\python27-x64 QT_QPA_PLATFORM_PLUGIN_PATH=C:\python27-x64\Lib\site-packages\PyQt5\plugins\platforms 修改IDA 7.0目录\plugins\plugins....

    学习Eclipse安装python插件.pdf

    在本文中,我们将详细介绍如何在Eclipse中安装Python插件PyDev,以便于在Eclipse环境中进行Python开发。Eclipse是一款强大的集成开发环境(IDE),通过安装PyDev插件,我们可以获得针对Python语言的专门支持,包括...

    Python安装教程

    验证安装是否成功的方法是在命令行输入 `python` 进入 Python 解释器,再输入 `import zope.interface`,若没有错误提示,则表示安装成功。 - **安装 pyOpenSSL** 访问 https://pypi.python.org/pypi/pyOpenSSL/ ...

    电子-python插件安装说明.rar

    本教程将详细讲解如何在STM32-F0/F1/F2系列微控制器上安装和使用Python插件,以提升开发效率和功能实现。 首先,我们要明确Python在嵌入式环境中的应用通常指的是MicroPython或CircuitPython等轻量级版本,它们是...

Global site tag (gtag.js) - Google Analytics