Creating an environment launch script (Windows)

Windows users will need to be particularly careful that both their Visual Studio and Anaconda Python environment variables are set up correctly in order to use PyCUDA; otherwise, Python will not be able to find NVIDIA's nvcc CUDA compiler or Microsoft's cl.exe C++ compiler. Fortunately, batch scripts are included that will set up these environments for us automatically, but we will have to be careful that these are executed each and every time we want to do GPU programming.

We will, therefore, create a batch script that will launch an appropriate IDE or command-line environment by calling these other two scripts in succession. (This script is also available at https://github.com/PacktPublishing/Hands-On-GPU-Programming-with-Python-and-CUDA/blob/master/2/launch-python-cuda-environment.bat.)

Be sure to first open up Windows Notepad, and follow along:

First, find where your vcvars.bat file for Visual Studio is; in the case of Visual Studio 2015, it is at C:Program Files (x86)Microsoft Visual Studio 14.0VCvcvarsall.bat.

Type the following line into your text editor, and then press Enter

call "C:Program Files (x86)Microsoft Visual Studio 14.0VCvcvarsall.bat" amd64

We now need to call the Anaconda's activate.bat script to set up the Anaconda Python environment variables; the standard path is Anaconda2Scriptsactivate.bat. We have to further indicate where the Anaconda libraries are with an argument to this script. In my case, the second line in my launch script would be call "C:Users\%username%Anaconda2Scriptsactivate.bat" C:Users\%username%Anaconda2.

Finally, the last line of our batch script will launch whatever environment—IDE or command-line prompt—you prefer to program in, which will inherit all of the necessary environment and system variables the prior two scripts will set up. If you prefer the old standard DOS-style Command Prompt, this line should just be cmd. If you like to work from PowerShell, change this to powershell. It will be necessary to use the command line in some cases, particularly for accessing the command line pip and conda for updating your Python library.

Finally, save this file to your desktop with the filename launch-python-cuda-environment.batYou can now launch our Python GPU programming environment by double-clicking this file.

(Keep in mind that if you wish to use the Jupyter Notebook or Spyder Python IDEs, you can simply launch these from the command line with jupyter-notebook or spyder, or alternatively, you can make a batch script that just replaces cmd with the appropriate IDE launch command.)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.42.116