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.
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
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.
c: \ MinGW \ 32
uncheck a graphical user interfaceAfter 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>
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 a shortcut on your desktop to launch mysy.
c: \ mingw \ msys \ msys.bat
Change the icon.
c: \ mingw \ msys \ msys.ico
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.
c: \ mingw \ 64
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.
c: \ mingw \ 64
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.
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.
c: \ windows \ system32 \ python27.dll
c: \ Python27 \ libs \ 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