Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7

The purpose is to do GPU calculations with PyCUDA and Theano. I shouldn't develop 64-bit Python on Windows by any means, but I tried to build a development environment on my laptop. You'll be happier if you buy a used laptop with an old GeForce graphics board and install Ubuntu. I mainly work by referring to the following sites.

Windows GCC environment

There are various ways to use GCC on Windows, but this time I chose the following combination.

Python 2.7

From Python 2.7 Release to python-2.7.amd64.msi Download and run the python-2.7.amd64.msi) installer. Add the folder to the environment variable PATH.

C:\Python27;C:\Python27\Scripts

MinGW and MSYS

From MinGW to [mingw-get-setup.exe](http://sourceforge.net/projects/mingw/files/Installer/mingw-get-setup.exe/ Download) installer and run it. Install separately folders to prepare 32bit and 64bit GCC environment.

After the installation is complete, edit profile.xml to change the folder structure.

c\mingw\32\var\lib\mingw-get\data\profile.xml


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<profile project="MinGW" application="mingw-get">
  <repository uri="http://prdownloads.sourceforge.net/mingw/%F.xml.lzma?download"/>
  <system-map id="default">
    <sysroot subsystem="mingw32" path="%R" />
    <sysroot subsystem="MSYS" path="%R/../msys" />
  </system-map>
</profile>

Build a 32-bit environment with the mingw-get command

Edit fstab and switch to 32bit environment.

\mingw\msys\etc\fstab


c:/mingw/32   /mingw

Use the mingw-get command to install the required packages.

$ mingw-get install msys-core msys-base msys-vim msys-wget msys-patch msys-flex msys-bison msys-unzip

Install the 32-bit gcc environment.

$ mingw-get install gcc g++ gfortran

Edit fstab and set it to use the 64-bit environment by default.

c\mingw\msys\etc\fstab


c:/mingw/64   /mingw

Create shortcut for msys.bat

Create a shortcut on your desktop to launch mysy.

Change the icon.

TDM-GCC and MinGW-w64

From the Download Page of TDM-GCC, [tdm-gcc] of TDM64 MinGW-w64 edition -4.9.2.exe](http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm-gcc-4.9.2.exe/download) is downloaded.

Check the system environment variable PATH and delete c: \ mingw \ 64 \ bin if it is included.

Double-click msys.bat on your desktop to see the version of gcc.

$ gcc --version
gcc.exe (tdm64-1) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

TDM-GCC can change the target by specifying the option of 32bit and 64bit. Edit c: \ mingw \ msys \ home \ masato \ .profile in your MSYS home directory to show the build environment when you start MSYS.

~/.profile


#!/bin/bash
# we use the reported architecture of the 'gcc' in our path to 
# determine which Python and other utilities we will be using.
_arch=`gcc -dumpmachine`
#echo "ARCH=$_arch"
if grep "^x86_64-" <<< "$_arch" >/dev/null ; then
	echo "MINGW 64 BIT BUILD ENVIRONMENT"
	_pydir="/c/Python27"
else
	echo "MINGW 32 BIT BUILD ENVIRONMENT"
	_pydir="/c/Python27_32"
fi

export PATH=$PATH:$_pydir:$_pydir/Scripts

# note that mingw-get will still install all its stuff to c:\mingw\32,
# because of the contents of its profile.xml file.
alias mingw-get="/c/mingw/32/bin/mingw-get"

Fortran

I installed it because it seems to be necessary for building SciPy. Actually, I decided to use a custom installer, so it may not be necessary. Fortran is not installed by default in TDM-GCC.

Download tdm-gcc-webdl.exe. Press the Manage button to change the configuration of the installed environment.

SCons

Install the build tool for SCons. Start mysy.bat created on the desktop.

$ cd ~
$ wget http://prdownloads.sourceforge.net/scons/scons-2.3.4.tar.gz
$ tar zxf scons-2.3.4.tar.gz
$ cd scons-2.3.4
$ python setup.py bdist_wininst

Launch the GUI installer.

$ start dist/scons-2.3.4.win-amd64.exe 

Copy it to the Scripts folder.

$ cp /c/Python27/Scripts/scons.py /c/Python27/Scripts/scons

Check the version.

$ scons --version
SCons by Steven Knight et al.:
        script: v2.3.4, 2014/09/27 12:51:43, by garyo on lubuntu
        engine: v2.3.4, 2014/09/27 12:51:43, by garyo on lubuntu
        engine path: ['c:\\Python27\\Lib\\site-packages\\scons-2.3.4\\SCons']
Copyright (c) 2001 - 2014 The SCons Foundation

Dependency Walker

Install Dependency Walker. Dependency Walker can inspect Windows module dependencies. Download the zip and unzip it to / c / mingw / 64 / bin.

$ wget http://www.dependencywalker.com/depends22_x64.zip
$ unzip depends22_x64.zip -d /c/mingw/64/bin
Archive:  depends22_x64.zip
  inflating: /c/mingw/64/bin/depends.chm
  inflating: /c/mingw/64/bin/depends.dll
  inflating: /c/mingw/64/bin/depends.exe

SWIG

SWIG is a tool for calling C / C ++ libraries from various languages. Download the zip and install it in / c / mingw / msys / opt.

$ wget http://prdownloads.sourceforge.net/swig/swigwin-3.0.5.zip
$ mkdir -p /c/mingw/msys/opt
$ unzip swigwin-3.0.5.zip -d /c/mingw/msys/opt

Edit ~ / .profile and add it to your PATH.

~/.profile


export PATH=$PATH:/opt/swigwin-3.0.5

Restart msys.bat to check the version.

$ swig -version

SWIG Version 3.0.5

Compiled with i586-mingw32msvc-g++ [i586-pc-mingw32msvc]

Configured options: +pcre

Please see http://www.swig.org for reporting bugs and further information

GTK+

Install the GUI toolkit for GTK +. Download and run the installer.

$ wget http://sourceforge.net/projects/ascend-sim/files/thirdparty/gtk%2B-2.22.1-20101229-x64-a4.exe/download
$ start gtk+-2.22.1-20101229-x64-a4.exe

Edit ~ / .profile and add it to your PATH.

~/.profile


export PATH=$PATH:/c/Program\ Files/GTK+-2.22/bin/

Restart msys.bat and check the installation. Running gtk -domo will launch the GUI.

$ gtk-demo

Subversion

Subversion is available from SlikSVN to Slik-Subversion-1.8.11-x64.msi .11-x64.msi) Download and install.

Edit ~ / .profile and add it to your PATH.

~/.profile


export PATH=$PATH:/c/Program\ Files/SlikSvn/bin

Restart msys.bat and check the version.

$  svn --version
svn, version 1.8.11-SlikSvn-1.8.11-X64 (SlikSvn/1.8.11) X64
   compiled Dec  9 2014, 13:44:31 on x86_64-microsoft-windows6.2.9200

Copyright (C) 2014 The Apache Software Foundation.

Rebuild python27.lib

Make the necessary preparations when building Python extensions in a 64-bit environment. Since python27.lib does not work with MinGW-w64, rebuild it using gendef.

$ svn co  svn://svn.code.sf.net/p/mingw-w64/code/trunk/mingw-w64-tools/gendef -r5774 ~/gendef
$ cd ~/gendef 
$ ./configure --prefix=/mingw
$ make -j4 && make install
$ cd
$ gendef --help
Usage: gendef [OPTION]... [DLL]...
Dumps DLL exports information from PE32/PE32+ executables
...

Open Explorer and copy python27.dll.

Refer to Creating a 64 bit development environment with MinGW on Windows Build python27.lib. Launch the mysy.bat shortcut on your desktop.

$ cd /c/Python27/libs
$ mv python27.lib old_python27.lib
$ gendef python27.dll
 * [python27.dll] Found PE+ image
$ dlltool --dllname python27.dll --def python27.def --output-lib python27.lib

Open c: \ Python27 \ include \ pyconfig.h and cut the following 3 lines from the 141st line.

c\Python27\include\pyconfig.h


#ifdef _WIN64
#define MS_WIN64
#endif

Paste the three cut lines above the #ifdef _MSC_VER on line 107.

c\Python27\include\pyconfig.h


#ifdef _WIN64
#define MS_WIN64
#endif
#ifdef _MSC_VER

~/.profile

Finally, place the following ~ / .profile in the MSYS home directory (c: \ mingw \ msys \ home \ masato).

~/.profile


#!/bin/bash
# we use the reported architecture of the 'gcc' in our path to
# determine which Python and other utilities we will be using.
_arch=`gcc -dumpmachine`
#echo "ARCH=$_arch"
if grep "^x86_64-" <<< "$_arch" >/dev/null ; then
        echo "MINGW 64 BIT BUILD ENVIRONMENT"
        _pydir="/c/Python27"
        export PATH=$PATH:/c/Program\ Files/GTK+-2.22/bin/
else
        echo "MINGW 32 BIT BUILD ENVIRONMENT"
        _pydir="/c/Python27_32"
        export PATH=$PATH:/c/Program\ Files\ \(x86\)/GTK+-2.22/bin/
fi

export PATH=$PATH:$_pydir:$_pydir/Scripts

# note that mingw-get will still install all its stuff to c:\mingw\32 and c:\min
gw\msys.
# because of the contents of its profile.xml file. it is not affected by the con
tent of /etc/fstab.
alias mingw-get="/c/mingw/32/bin/mingw-get"

export PATH=$PATH:/opt/swigwin-3.0.5
export PATH=$PATH:/c/Program\ Files/SlikSvn/bin

Recommended Posts

Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
Build a Python environment on your Mac with Anaconda and PyCharm
Simply build a Python 3 execution environment on Windows
Build a python environment with ansible on centos6
Build Python environment on Windows
Build python environment on windows
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a Python extension for E-Cell 4 on Windows 7 (64bit)
Build a GVim-based Python development environment on Windows 10 (1) Installation
Build a python virtual environment with virtualenv and virtualenvwrapper
Create a decent shell and python environment on Windows
Install python2.7 on windows 32bit environment
Build mlpy with python3.3 (64bit) (windows 64bit)
Build a python3 environment on CentOS7
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Trial and error]
Build a GVim-based Python development environment on Windows 10 (2) Basic settings
Until you create a machine learning environment with Python on Windows 7 and run it
Python 2.7, 3.4, 3.5 extension module build environment on Windows
Build Python3 and OpenCV environment on Ubuntu 18.04
Build a python environment on MacOS (Catallina)
A memo with Python2.7 and Python3 on CentOS
Building a Python 3.6 environment with Windows + PowerShell
Creating a python virtual environment on Windows
Build Python environment with Anaconda on Mac
Build a python virtual environment with pyenv
Build a Python + OpenCV environment on Cloud9
Build a modern Python environment with Neovim
LaTeX and R (a little Python) environment construction with SublimeText3 (Windows)
Build a WardPress environment on AWS with pulumi
Build python environment with pyenv on EC2 (ubuntu)
Building a python environment with virtualenv and direnv
Build a Python environment on Mac (Mountain Lion)
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
[Python] Build a Django development environment with Docker
Create a python3 build environment with Sublime Text3
Build a Python development environment on your Mac
Build a virtual environment with pyenv and venv
Build a Python environment with OSX El capitan
Quickly build a Python Django environment with IntelliJ
Build PyPy and Python execution environment with Docker
Create a Python virtual development environment on Windows
Build a Python machine learning environment with a container
Build a Python development environment on Raspberry Pi
Build a python execution environment with VS Code
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Easy construction]
Steps to create a Python virtual environment with VS Code on Windows
Quickly build a python environment for deep learning and data science (Windows)
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Build Linux on a Windows environment. Steps to install Laradock and migrate
Install Python3 on Mac and build environment [Definitive Edition]
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Build a machine learning Python environment on Mac OS
Build a python environment for each directory with pyenv-virtualenv
Create a comfortable Python 3 (Anaconda) development environment on windows
Build python3 environment with ubuntu 16.04
I made a Python3 environment on Ubuntu with direnv.
How to build a Django (python) environment on docker
Build python environment with direnv
Build a Python development environment on Mac OS X
Build a Python environment on your Mac using pyenv