Installing PyOpenCL on Windows
[[!toc ]]
Before you try building PyOpenCL for Windows yourself, you may want to consider trying:
- the binary version distributed by Christoph Gohlke (see the additional notes below)
- the pyopencl plugin for Python(x, y) which works with either Python(x, y) or the standard 32-bit CPython 2.7 distribution
Installation from binary
Windows Vista Professional
- Install PyOpenCL
- from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopencl
- get pyopencl-0.92.win-amd64-py2.7.?exe
- install And that worked right away without any further installation or modification.
Christoph Bussler
Windows 7/8 and Python 3.3 (32bit)
Using the (32bit) appropriate exe-packages from www.lfd.uci.edu/~gohlke/pythonlibs/ under (a 32bit) Py3.3 on Windows (v7, 64bit, and also v8, 32bit) worked fine for me, except that pytools need the "decorator" module (https://pypi.python.org/pypi/decorator) which then isn't present, and so I used the pytools package directly from pypi with the standard "python setup.py install" command which then pulls in "decorator" automagically. Then "import pyopencl" worked. Later I also had to install the mako package to get some actual code running (IIRC). Thanks, Sven.
Installation from source
Windows 10 64 bit, Python 3.8, PyOpenCL 2019.1.2, Visual Studio 2015 Update 3, Community Edition , NVidia CUDA 10.2
- Downloaded sources from https://pypi.org/project/pyopencl/#files
- Unzipped sources in a temporary folder
- Opened the x64 Native Tools Command Prompt of VS 2015
- CDed into the source folder
- run "python configure.py"
- edited siteconf.py setting:
- CL_INC_DIR = ['C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include']
- CL_LIB_DIR = ['C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\lib\x64']
- run python "python setup.py build
- watched many warning and errors in despair :-)
- ... but the process apparently terminated succesfully
- run "python setup.py install"
- tested on the example script on the landing page https://documen.tician.de/pyopencl/
- the script runs fine!
- voilá , pyopencl is served ...
Windows 10 64 bit, Python 3.4, PyOpenCL/Git Master, MingWPy, Nvidia CUDA 7.5
- Install Nvidia's CUDA 7.5 Tool kit
- Install MingWPy using
> pip install -i https://pypi.anaconda.org/carlkl/simple mingwpy
- Clone a copy of PyOpenCL from Github
- Edit .\src\c_wrapper\wrap_constants.cpp and add "#undef CONST" after include statements, i.e.
#include "wrap_cl.h"
#include <iostream>
#undef CONST
extern "C"
...
- Edit ".\pyopencl\compyte\ndarray\gen_elemwise.py" and ".\pyopencl\compyte\ndarray\test_gpu_ndarray.py" and convert most Python 2.x style print statements to python 3 syntax. Basically wrap print arguments in brackets "(..)" and ignore any lines containing StringIO ">>" operator.
- Run
> python configure.py
- Edit siteconf.py to following:
CL_TRACE = False
CL_ENABLE_GL = False
CL_INC_DIR = ['c:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v7.5\\include']
CL_LIB_DIR = ['C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v7.5\\lib\\x64']
CL_LIBNAME = ['OpenCL']
CXXFLAGS = ['-std=c++0x']
LDFLAGS = []
- Run following commands.
> python setup.py build_ext --compiler=mingw32
> python setup.py install
Tip: when meet error "Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat).". Please Edit
1.以python3.4为例子,安装路径: C:\Python34。‘msvc9compiler.py’ 文件位于 C:\Python34\Lib\distutils 。
2.用python自带的IDE编辑,找到
def query_vcvarsall(version, arch="x86"):
3.在代码 ‘if vcvarsall is None:’ 前面,添加一个 vcvarsall 变量,指向 vcvarsall.bat文件
- 例如:本机路径是 "E:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"
- Before:
def query_vcvarsall(version, arch="x86"):
。。。。。
result = {}
if vcvarsall is None:
。。。。。
- After:
def query_vcvarsall(version, arch="x86"):
。。。。。
result = {}
vcvarsall = r"E:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"
if vcvarsall is None:
。。。。。
- Please don't use Mingwpy , user Visual Studio compiler, can support Visual Studio 2017,请直接使用下面的命令,不使用上面的命令编译
> python setup.py build_ext
> python setup.py install
- 尝试 import pyopencl,看是否成功安装。(适用window10 ,vs2017 ,不需要安装 mingw )
Windows 7 64bit, Python 2.7, Visual Studio 2010, CUDA 4.1
After a conversation with Andreas and reading the suggestions in this wiki, I was able to use the above configuration following these steps:
- Installed Python 2.7 (Active Python Community Edition 2.7.5.2 64bit) - downloaded from http://www.activestate.com/activepython/downloads
- Installed NumPy from 1.6.1 (numpy-MKL-1.6.1.win-amd64-py2.7.exe) - kindly provided in binary format at http://www.lfd.uci.edu/~gohlke/pythonlibs/
- Downloaded PyOpenCL doing: git clone http://git.tiker.net/trees/pyopencl.git (this step produces "pyopencl" directory at the current location)
- ```txt
cd pyopencl git submodule init git submodule update
* the above step is necessary, w.r.t to downloading PyOpenCL 2011.2, as the git repository contains some fixes which results otherwise in phtread.h missing
* edit `C:\Python27\Lib\distutils\msvc9compiler.py` and add after line 641 (which reads "ld_args.append ('/IMPLIB:' + implib_file)") a new line which reads "ld_args.append('/MANIFEST')" - this fixes problems with the use of Visual Studio 2010
* open now your Visual Studio 2010 64bit Command prompt with administrator rights
* cd into your pyopencl directory
* issue the command "python configure.py"
* edit the siteconf.py file to be:
```txt
BOOST_INC_DIR = []
BOOST_LIB_DIR = []
BOOST_COMPILER = 'gcc43'
BOOST_PYTHON_LIBNAME = ['boost_python']
USE_SHIPPED_BOOST = True
CL_TRACE = False
CL_ENABLE_GL = True
CL_ENABLE_DEVICE_FISSION = True
CL_INC_DIR = [r'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.1\include', r'C:\Program Files\Microsoft SDKs\Windows\v7.1\Include']
CL_LIB_DIR = [r'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.1\lib\x64', r'C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64']
CL_LIBNAME = ['OpenCL']
CXXFLAGS = ['/EHsc']
LDFLAGS = ['/FORCE']
- type "set VS90COMNTOOLS=%VS100COMNTOOLS%"
- type python setup.py install
- let the compiler compile PyOpenCL, no error messages should appear, after the installation process is terminated you can remove the pyopencl directory
Windows 7 64bit, Python 2.7, Visual Studio 2010, Intel OpenCL SDK 1.5
Intel SDK currently supports a range of CPUs (Core 2, i3, i5, i7, maybe others ?) and can be used for OpenCL development and testing where access to a GPU is not possible (e.g. many laptops)
Please follow the above instructions for Win 7 64bith with CUDA 4.1, with the only exception that the siteconf.py should be:
BOOST_INC_DIR = []
BOOST_LIB_DIR = []
BOOST_COMPILER = 'gcc43'
BOOST_PYTHON_LIBNAME = ['boost_python']
USE_SHIPPED_BOOST = True
CL_TRACE = False
CL_ENABLE_GL = True
CL_ENABLE_DEVICE_FISSION = True
CL_INC_DIR = [r'C:\Program Files (x86)\Intel\OpenCL SDK\1.5\include', r'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1\Include']
CL_LIB_DIR = [r'C:\Program Files (x86)\Intel\OpenCL SDK\1.5\lib\x64', r'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1\Lib\x64']
CL_LIBNAME = ['OpenCL']
CXXFLAGS = ['/EHsc']
LDFLAGS = ['/FORCE']
Building PyOpenCL with Visual Studio 2010
Python 2.6 is built with VS2008, but we can make some small changes to make it work with VS2010.
VS2010 requires you specify /MANIFEST to link.exe if you want a manifest file. So edit your Python26\Lib\distutils\msvc9compiler.py, and add the following to line 636
ld_args.append('/MANIFEST')
Then type the below before running python setup.py install, to trick Python in to using VS2010
set VS90COMNTOOLS=%VS100COMNTOOLS%
You'll need to build Boost with VS2010. To build boost, from the boost directory type
bjar --build-type=complete --with-python install
then edit the siteconf.py to point to the new .lib files in c:\boost\lib, and run python setup.py install
Windows 7
This is similar to Windows XP but with a couple changes.
Installing Visual Studio C++ 2008 Express didn't provide all the necessary headers such as windows.h. To get these I had to download the Microsoft Windows SDK and add its paths to the siteconf too. Here was my siteconf.py:
BOOST_INC_DIR = [r'C:\Program Files (x86)\boost\boost_1_39']
BOOST_LIB_DIR = [r'C:\Program Files (x86)\boost\boost_1_39\lib']
BOOST_COMPILER = 'msvc'
BOOST_PYTHON_LIBNAME = ['boost_python-vc90-mt-1_39']
#BOOST_THREAD_LIBNAME = ['boost_thread-vc90-mt-1_39']
USE_SHIPPED_BOOST = False
CL_TRACE = False
CL_ENABLE_GL = False
CL_INC_DIR = [r'C:\Program Files (x86)\ATI Stream\include',
r'C:\Program Files\Microsoft SDKs\Windows\v6.0\Include']
CL_LIB_DIR = [r'C:\Program Files (x86)\ATI Stream\lib\x86',
r'C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib']
CL_LIBNAME = ['OpenCL']
CXXFLAGS = ['/EHsc', '/DBOOST_PYTHON_NO_PY_SIGNATURES']
LDFLAGS = ['/FORCE']
Boost is not required but PyOpenCL wouldn't compile for me without it.
Windows 7, VS2010, Python 3.4, OpenCL
Assumes you've built boost using:
b2.exe toolset=msvc-10.0 variant=release threading=multi
Be sure to find the correct version of boost_python*.lib and plug it into BOOST_PYTHON_LIBNAME,
BOOST_INC_DIR = ['C:/local/boost_1_56_0']
BOOST_LIB_DIR = ['C:/local/boost_1_56_0/stage/lib']
BOOST_COMPILER = 'msvc'
BOOST_PYTHON_LIBNAME = ['boost_python3-vc100-mt-1_56']
USE_SHIPPED_BOOST = False
CL_TRACE = False
CL_ENABLE_GL = False
CL_ENABLE_DEVICE_FISSION = True
CL_INC_DIR = ['C:/Program Files (x86)\AMD APP SDK/3.0-0-Beta/include']
CL_LIB_DIR = ['C:/Program Files (x86)\AMD APP SDK/3.0-0-Beta/lib/x86_64']
CL_LIBNAME = ['OpenCL']
CXXFLAGS = ['/EHsc','/DBOOST_PYTHON_NO_PY_SIGNATURES']
LDFLAGS = ['/FORCE']
Windows XP Installation
I followed Windows 7 instructions below on Windows XP with python 2.7 and the installation worked. But then I got this error, when tried to import pyopencl. The error was resolved by installing pyopencl on python 2.6.4. (Not sure if the error was because of version mismatch or because of installing python 2.7 before Boost.) Ghasem 2011-09-30 00:00:17
Installation of PyOpenCL is similar to installation of PyCUDA, with some obvious modifications.
The following were installed prior to installing PyOpenCL:
- Microsoft Visual Studio C++ 2008 Express
- ATI Stream SDK v2 Beta or Nvidia's OpenCL GPU driver and OpenCL SDK
- Python 2.6.4
- Numpy 1.3 and SciPy 0.7.1 (not sure if SciPy is really needed)
- Boost 1.39 precompiled version (Multithreaded DLLs and libraries, compiled against MSVC 9.0, including DateTime, Python and Thread)
- Python setuptools 0.6c9 (installation from egg requires ez_setup.py from source; google for more info) Run "python configure.py" in the pyopencl directory to get a sample siteconfig.py, then edit as appropriate. Here's my edited siteconfig.py:
BOOST_INC_DIR = [r'C:\Program Files\boost\boost_1_39']
BOOST_LIB_DIR = [r'C:\Program Files\boost\boost_1_39\lib']
BOOST_COMPILER = 'msvc'
BOOST_PYTHON_LIBNAME = ['boost_python-vc90-mt-1_39']
BOOST_THREAD_LIBNAME = ['boost_thread-vc90-mt-1_39']
CL_TRACE = False
SHIPPED_CL_HEADERS = False
USE_SHIPPED_BOOST = False
CL_INC_DIR = [r'C:\Program Files\ATI Stream\include']
CL_LIB_DIR = [r'C:\Program Files\ATI Stream\lib\x86']
CL_LIBNAME = ['OpenCL']
CXXFLAGS = ['/EHsc', '/DBOOST_PYTHON_NO_PY_SIGNATURES']
LDFLAGS = ['/FORCE']
Then run "python setup.py install" in the pyopencl directory.
After driver installation, copy all boost dlls into windows/system32 directory or add the path to it. You minimally need boost_python-vc90-mt-1_39.dll and boost_thread-vc90-mt-1_39.dll.
Finally, add a HOME environment variable in Windows: it doesn't matter what it is, so you can make it "123456" or your My Documents directory, etc.
A user was kind enough to supply a PDF installation manual, which might be of help.
*Edit: Was able to get pyopencl working in Win7 64 Bit, VS2010, and Py2.7 using options given for XP. Thanks for that. Had to run setup.py twice since it didn't go through completely due to mt.exe error (some one needs to add quotes for all paths). Now, import pyopencl as cl works like a charm.