The second article in this series focuses on the build environment and compilation process of the Windows environment.
Compilation Environment Selection:
1. Microsoft Visual C + + Compiler for Python 2.7 is used by the compiler as a god. The reason for not choosing vs is that it's too big for me to like the idea of comprehensive rollup. There's no choice here. Announcing Visual C + + Build Tools 2015 as a compilation environment because there is no offline installation package, in many places there is no offline installation method can be said that simply cannot be used.
2. Compile using the VCBuild method. There is no choice for MSBuild to compile because Microsoft Visual C + + Compiler for Python 2.7 is a lite version of Vs2008, and in 2008 there is no vcbuild change to msbuild mode. Both of these approaches are a good way to do this, except that the Vs2015 Lite (announcing Visual C + + Build Tools 2015) does not have the option of Msbuil.
3. It is also a challenge to compile using the command line method. Because in the concept of everyone compiled on Windows must use the interface of the VS, there is less information on the network. So, here is a challenge. However, in the process of using command-line compilation, it is found that the whole compilation environment of VS is more comprehensive and flexible, which gives the VS command-line compilation process a good liking.
Environment Construction:
0. The operating system is WIN10 64-bit system, Python source code version of the current version of the latest 2.7.11.
1. Download and install the Microsoft Visual C + + Compiler for Python 2.7 that exists like God, adding include and libpath to environment variables.
2. Download and install the Microsoft Visual C + + Redistributable Package (x64) and Microsoft Visual C + + Redistributable Package (x86).
3. Download and install the ActivePerl and check that the environment variables are in effect.
4. Download and install the NASM.
5. Download the SQLite 3.6.21 and extract the SQLite source code into the Externals directory under the Python source code directory.
6. Download bzip2-1.0.6.tar.gz. And extract the BZ source code into the Python source code directory under the Externals directory.
7. Download openssl-1.0.2d.tar.gz. And extract the OpenSSL source code into the Python source code directory under the Externals directory.
On the other, each East meaning is: the basis of the compilation environment. 3,4 is required for OpenSSL to compile on windows. 5,6,7 is a python-related open source project.
Compile process:
0. Start first, you can find the Readme.txt from the Pcbuild directory, which you can see
1 Quick Start Guide2-----------------3 4 1. Install Microsoft Visual Studio -, any edition.5 2. Install Microsoft Visual Studio ., any edition, or Windows SDK7.16And any version of Microsoft Visual Studio newer than ..7 3. Install Subversion, and MakeSure'Svn.exe'is on your PATH.8 4. Run"build.bat-e"To build Pythoninch +-bit Release configuration.9 5. (Optional, but recommended) Run the test suite with"Rt.bat-q".
You can see that the latest Python source code supports VS2010 for compiling. In addition, you can see:
Legacy Support--------------You canFindBuild Directories forolder versions of Visual Studio andvisual C++inchThe PC directory. The project filesinchPc/vs9.0/arespecific to Visual Studio -, and would be fully supported forThe lifeof Python2.7. The following legacy build directories is no longer maintained and maynot work out of the box. PC/vc6/Visual C++6.0PC/vs7.1/Visual Studio2003(7.1) PC/vs8.0/Visual Studio2005(8.0)
Here you can see that vs2008 is a now also supported, but under the pc/vs9.0 directory.
2. To Pc/readme.txt, the process of compiling is basically starting from BUILD.bat. So go to pc/vs9.0 to find the BUILD.bat directly. Open BUILD.bat can see this is a relatively simple script, according to parameters to fill in parameters, call BUILD.bat basic can be.
3. Code Visual C + + 64-bit Command Prompt, switch to the Python code directory under pc/vs9.0. Perform
Build.bat-c release-p x64-t Rebuild
Direct error, the hint can not find the CL command, and the target is 64 bits, compiled out is 32 bits. Workaround:
Build.bat-c release-p x64-t rebuild/useenv/logcommands/platform:x64
Add the following three parameters, these three parameters are vcbuid parameters, parameter meaning see: VCBUILD option.
The final BUILD.bat script explains:
"d:\\ Python-2.7.11\pc\vs9.0\pcbuild.sln " " release|x64 " /useenv/logcommands/platform:x64
4. Delete the sub-items we don't need:
_ctypes,_ctypes_test,_elementtree,_hashlib,_msi can be seen from the Pcbuild.sln,_multiprocessing,_socket,_testcapi,Pyexpat,Select,Unicodedata,WinSound,_bsddb,_bz2,_ssl,_sqlite3,_tkinter,w9xpopen
In the previous article it was said that the requirement does not use TK to speak TK delete. Bsddb compared to the old DB standard, it is now estimated that no one is used or deleted. _ssl,_hashlib are all using OpenSSL, in Windows compile OpenSSL more troublesome to temporarily remove, then after the Windows compilation of OpenSSL to add in. W9xpopen is Win9x environmental support, also deleted.
5. Compile with the compile command above:
Found that there is still a compilation problem and that the entry function could not be found when compiling the DLL. After the survey found that the link DLL is missing parameter/dll, see: Linker Options
According to this survey, it was found that the Configurationtypes enumeration configured in the configuration in vcproj is correct. But still do not add the/dll parameter, find VCLinkerTool tag attribute found missing Linkdll parameter, add post compile often.
6. Compile the results:
Compile the Python.exe,pythonw.exe,python27.dll, and so on, double-click Python.exe:
Python2.7. One(Default, Feb9 .,Ten:Wuyi: A) [MSC v. the -bit (AMD64)] on Win32type" Help","Copyright","credits"Or"License" for Moreinformation.>>>Import OS>>>Print OS<module'OS'From'D:\\python-2.7.11\lib\os.pyc'>>>>
can be executed. The next article will detail the meaning of the compiled files in the compiled directory, as well as further add win API related.
Reference documents:
Https://docs.python.org/2/using/windows.html
Building C + + Projects in Visual Studio
https://msdn.microsoft.com/en-us/library/7s88b19e (v=vs.90). aspx
Building Reference
Https://msdn.microsoft.com/en-us/library/91621w01.aspx
Solutions and Projects in Visual Studio
Https://msdn.microsoft.com/en-us/library/b142f8e7.aspx
Solution (. SLN) File
https://msdn.microsoft.com/en-us/library/bb165951 (v=vs.90). aspx
Extending Solution Explorer
https://msdn.microsoft.com/en-us/library/bb166499 (v=vs.90). aspx
Property inheritance
Https://msdn.microsoft.com/en-us/library/tybz7dex (v=vs.90). aspx
Project Files
HTTPS://MSDN.MICROSOFT.COM/EN-US/LIBRARY/2208A1F2 (v=vs.90). aspx
Notes about the Vcproj file
Http://blog.sina.com.cn/s/blog_6288219501011nib.html
VCProject Properties
Https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcprojectengine.vcproject_properties (v=vs.90). aspx
Visual C + + Project Model
Https://msdn.microsoft.com/en-us/library/2eydyk57 (v=vs.90). aspx
Visual C + + Code Model
Https://msdn.microsoft.com/en-us/library/t41260xs (v=vs.90). aspx
Microsoft.VisualStudio.VCProjectEngine Namespace
Https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcprojectengine (v=vs.90). aspx
Configurationtypes Enumeration
Https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcprojectengine.configurationtypes (v=vs.90). aspx
VCLinkerTool Members
Https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcprojectengine.vclinkertool_members (v=vs.90). aspx
VCBUILD Options
Https://msdn.microsoft.com/zh-cn/library/cz553aa1 (vs.80). aspx
Linker Options
HTTPS://MSDN.MICROSOFT.COM/EN-US/LIBRARY/Y0ZZBYT4 (v=vs.90). aspx
RegOpenKey function
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724895 (v=vs.85). aspx
Self-release Python version production (ii) compilation