# Windows notes

## 1 Notes on Windows

This page serves as a collection of notes I've made while using Windows. It's meant to be a resource to help others and myself when performing common tasks in Windows.

## 2 Manual deletion of drivers with PnPUtil

In the past I have had trouble with FTDI USB chips and needed to completely wipe the Windows driver store of these drivers. It is not recommended to manually delete the files from the driver store (besides, overriding the permissions is a big pain in the butt). Instead, Microsoft recommends using the tool PnPUtil.

To print a list of installed drivers, enter the following command from a command prompt:

pnputil -e > C:\drivers.txt

This will print information about all the installed drivers to C:\drivers.txt.

To delete a specific driver, you can look inside the file, find the associated oemXX.inf (where XX is a specific number for each driver) and issue the following command:

pnputil -d oemXX.inf

You may also need to issue a -f flag to force a deletion if the device is still in use:

pnputil -f -d oemXX.inf

## 3 Disabling CheckDisk (CHKDSK) on startup

Windows check disk causes me all sorts of pain at work. I can disable it for certain drives by adding /k:<drive letter> before the asterisk in the BootExecute Windows registry key at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\. I disabled the F:\ and M:\ drives by adding /k:M and /k:F before the *.

## 4 Bash prompt in Windows

Information sources

UPDATE DECEMBER 2016: A reader recently informed me that the directions below are for MSYS 1.0. There is however a newer (and independent) version 2.0 available: https://msys2.github.io/. I cannot at this point verify whether these instructions will translate for MSYS2.0.

I really wanted a bash shell in Windows. I knew that Git for Windows implemented one, and I found that it's part of MSYS, a collection of packages for MinGw, the Minimalist GNU for Windows package.

I downloaded the MinGW installer from SourceForge, which is linked to from the MinGw site. This downloads a GUI based system for installing various packages to C:\MinGw. I installed the following packages, found under the Basic Setup menu accessed in the left-most pane of the MinGW Installation Manager:

1. mingw32-base (includes the gcc compiler)
2. mingw32-gcc-g++
3. msys-base (includes the bash shell)

After installing these packages, I added the following directories to my system PATH environment variable:

C:\MinGW\bin;C:\MinGW\msys\1.0\bin

If you don't do this, bash can't find the other associated programs, like ls and date.

### 4.1 Terminal emulators in emacs

Sources

UPDATE DECEMBER 2016: See my note above about using MSYS 2.0. The directions below might work with MSYS 2.0 by changing the path to bash.exe to the appropriate one in the MSYS 2.0 directory tree, but I have not verified this myself.

Once I had the shell working, I wanted to also use it in Emacs on Windows through a terminal emulator. Unfortunately, I don't think that this is possible, based on the StackOverflow discussion linked to above. However, I can run bash.exe in Emacs' shell mode.

To do this, I added the following lines to my init.el file:

(setq explicit-shell-file-name "C:/MinGW/msys/1.0/bin/bash.exe")
(setq shell-file-name "bash")
(setenv "SHELL" shell-file-name)

This allowed me to use bash as the default shell.

## 5 Python in Windows

### 5.1 Python shell and IPython in Emacs + Windows

Sources

I can get a basic Python shell within Emacs on Windows by adding the following line to my init.el file:

(setq python-shell-interpreter "C:/Python34/python.exe")

However, I can't print graphs through matplotlib from within this shell.

After installing IPython, I could in fact print graphs using plt.show() and changing python-shell-interpreter and python-shell-interpreter-args as follows:

(setq
python-shell-interpreter "C:\\Python34\\python.exe"
python-shell-interpreter-args
"-i C:\\Python34\\Scripts\\ipython-script.py console --matplotlib"
python-shell-prompt-regexp "In \$[0-9]+\$: "
python-shell-prompt-output-regexp "Out\$[0-9]+\$: "
python-shell-completion-setup-code
"from IPython.core.completerlib import module_completion"
python-shell-completion-module-string-code
"';'.join(module_completion('''%s'''))\n"
python-shell-completion-string-code
"';'.join(get_ipython().Completer.all_completions('''%s'''))\n")

Note that this configuration is specific to Windows and configures python.el, which is built into Emacs 24.2+. I also made slight modifications to the variable python-shell-interpreter-args to include the argument console –matplotlib (see source 4 above). Finally, I installed the package pyzmq using pip. These steps were crucial to get interactive plotting to work in an emacs python shell.

To get colors working in IPython on Windows, simply use pip to install PyReadline.

### 5.2 Installing pymacs in Windows with Emacs 24.3.1

Sources

Pymacs is easily installed on Windows. I first cloned the repository in a GitShell(version 0.25 on May 8, 2014)

git clone git://github.com/pinard/Pymacs

Following this, I ran the command make check in the folder containing the cloned repository. I could run make on Windows because I use MinGW and these binaries were on my system PATH environment variable. My system passed 166 tests but failed 1. It didn't seem to matter in the end though; the failure was a Python assertion error related to the version of Pymacs I downloaded.

Note: The directories that contained my emacs and Python binaries were on my system PATH environment variable. If they are not, the make check utility may not locate the binaries.

I next ran make install and then ran python setup.py install. Both ran without any problems. However, I could not import Pymacs into Python. I changed line 299 of Pymacs.py from except ProtocolError, exception: to except ProtocolError as exception: and then I could import the file.

Finally, I copied pymacs.el into my ~/.emacs.d/my-packages/ directory and added the following lines to init.el:

;;; Pymacs

The last two lines are commented out and are only needed if I have pymacs code in a directory that should be searched first in the Python import search path.

### 5.3 Installing python-mode.el 6.1.3 in Windows with Emacs 24.3.1

python-mode.el has a few things that I like over python.el, which is included in Emacs 24.2+.

python-mode.el is very easily installed. I downloaded version 6.1.3 from https://launchpad.net/python-mode and unpackaged the .tar.gz file into ~/.emacs.d/my-packages/python-mode.el-6.1.3.

Then, I added the following lines to my init.el file:

;;; python-mode.el
(setq py-install-directory "~/.emacs.d/my-packages/python-mode.el-6.1.3")
(require 'python-mode)

Python-mode does some insane things with Window splitting in emacs on Windows when executing code. I just stopped window splitting altogether by adding (setq py-split-windows-on-execute-p nil) after the (require 'python-mode) line.

### 5.4 Setup pip to use the gcc compiler

Information sources

The Python package repository, pip, will typically try to use Visual Studio as its compiler on Windows. I've run into a lot of errors and tedious customizations to get Visual Studio working with pip however.

Instead, I configured pip to use the gcc compiler in MinGw. After installing MingGw, I created a text file called pydistutils.cfg in C:\Users\douglass that contained the following lines:

[build]
compiler = mingw32

### 5.5 Installing numpy, scipy, matplotlib, etc…

Sources

I have found that pip is not very good at resolving package dependencies. For example, I ran into issues installing numpy using pip because I didn't have BLAS already installed. I've read that conda is pretty good with resolving dependencies, but I really didn't want to download/install another package manager.

Many 64-bit binaries can be found at the website above. I downloaded the 64 bit binaries matching my Python version (3.4) for numpy, scipy, and matplotlib here. Next, I moved the binaries to C:\Python34\Scripts and installed each with easy_install.exe:

easy_install numpy-MKL-1.8.1.win-amd64-py3.4.exe
easy_install scipy-0.14.0.win-amd64-py3.4.exe
easy_install matplotlib-1.3.1.win-amd64-py3.4.exe

I had no troubles installing Pillow (for image processing) with pip3.