Problem installing torch audio on Windows 10 conda

In Anaconda Python 3.6.7 with PyTorch installed, on Windows 10, I do this sequence:

conda install -c conda-forge librosa
conda install -c groakat sox

then in a fresh download from https://github.com/pytorch/audio I do

python setup.py install

and it runs for a while and ends like this:

torchaudio/torch_sox.cpp(3): fatal error C1083: Cannot open include file: 'sox.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.15.26726\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2

I think I’m almost there and this is doable. Please help!

Note this is also an open GitHub issue of long standing: https://github.com/pytorch/audio/issues/50

Not a windows user. But I think the problem is with the environment setup. It is not able to locate the sox.h file, which is installed in your conda environment. You are facing this problem as you are currently not in the folder in which you installed conda. Try moving to the folder of your environment and run the command again.

Kushaj, I also cross-posted on StackOverflow and I got an answer over there which looks like a firm and definitive negative for Windows: https://stackoverflow.com/questions/54872876/how-to-install-torch-audio-on-windows-10-conda

Can you do a check for me. Open terminal and import numpy or any conda package. Tell me if it works or not.

It works fine:

>python
Python 3.6.7 (default, Feb 24 2019, 05:34:16) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy

This is an open, logged issue for Windows. I’m hoping a PyTorch guru will take pity on Windows folks and fix it.

1 Like

I checked the problem in some detail, I think for now you will not be able to do so on Windows. But if you want a trick, you can run an Ubuntu VM with the libraries installed and try to communicate between Windows and the VM.

Other people have suggested WSL Linux on Windows but there are still problems accessing GPU with that: http://www.erogol.com/using-windows-wsl-for-deep-learning-development/

For my purposes (training speech recognition in Swahili), I am giving up on PyTorch in favor of this Tensorflow-based project done for Udacity which has no missing pieces on Windows: https://github.com/simoninithomas/DNN-Speech-Recognizer

For the record, I was trying to reproduce this OpenNMT-py speech training demo on Windows: http://opennmt.net/OpenNMT-py/speech2text.html

Hi,

I managed to compile torchaudio with sox in Windows 10, but is a bit tricky.

Unfortunately the sox_effects are not usable, this error shows up:
RuntimeError: Error opening output memstream/temporary file

But you can use the other torchaudio functionalities.

The steps I followed for Windows 10 64bit are:

#############################

TORCHAUDIO WINDOWS10 64bit

#############################

Note: I mix some command lines unix-like syntax, you can use file explorer or whatever

preliminar arrangements

  1. Download sox sources
    $ git clone git://git.code.sf.net/p/sox/code sox

  2. Download other sox source to get lpc10

$ git clone https://github.com/chirlu/sox/tree/master/lpc10 sox2
$ cp -R sox2/lpc10 sox
  1. IMPORTANT get VisualStudio2019 and BuildTools installed

lpc10 lib

4.0. Create a VisualStudio CMake project for lpc10 and build it
Start window -> open local folder -> sox/lpc10
(it reads CMakeLists.txt automatically)
Build->build All

4.2. Copy lpc10.lib to sox

$ mkdir -p sox/src/out/build/x64-Debug
$ cp sox/lpc10/out/build/x64-Debug/lpc10.lib sox/src/out/build/x64-Debug

gsm lib

5.0. Create a CMake project for libgsm and compile it as before with lpc10

5.1. Copy gsm.lib to sox

$ mkdir -p sox/src/out/build/x64-Debug
$ cp sox/libgsm/out/build/x64-Debug/gsm.lib sox/src/out/build/x64-Debug

sox lib

6.0. Create a CMake project for sox in VS

6.1. Edit some files:

CMakeLists.txt: (add at the very beginning)

project(sox)

sox_i.h: (add under stdlib.h include line)

#include <wchar.h> /* For off_t not found in stdio.h */
#define UINT16_MAX  ((int16_t)-1)
#define INT32_MAX  ((int32_t)-1)

sox.c: (add under time.h include line)

`#include <sys/timeb.h>`

6.2. Build sox with VisualStudio

6.3. Copy the libraries where python will find them, I use a conda environment:

$ cp sox/src/out/build/x64-Debug/libsox.lib envs\<envname>\libs\sox.lib
$ cp sox/src/out/build/x64-Debug/gsm.lib envs\<envname>\libs
$ cp sox/src/out/build/x64-Debug/lpc10.lib envs\<envname>\libs

torchaudio

$ activate <envname>

7.0. Download torchaudio from github
$ git clone https://github.com/pytorch/audio thaudio

7.1. Update setup.py, after the “else:” statement of “if IS_WHEEL…”
$ vi thaudio/setup.py

#if IS_WHEEL…

else:
    audio_path = os.path.dirname(os.path.abspath(__file__))

    # Add include path for sox.h, I tried both with the same outcome
    include_dirs += [os.path.join(audio_path, '../sox/src')]
    #include_dirs += [os.path.join(audio_path, 'torchaudio/sox')]

    # Add more libraries

    #libraries += ['sox']
    libraries += ['sox','gsm','lpc10']

7.2. Edit sox.cpp from torchaudio because dynamic arrays are not allowed:

$ vi thaudio/torchaudio/torch_sox.cpp

 //char* sox_args[max_num_eopts];
 char* sox_args[20]; //Value of MAX_EFFECT_OPTS

7.3. Build and install

$ cd thaudio
$ python setup.py install

It will print out tons of warnings about type conversion and some library conflict with MSVCRTD but “works”.

And thats all.

1 Like