Problem installing torch audio on Windows 10 conda

username: Lars_Ericson
cooked: <p>In Anaconda Python 3.6.7 with PyTorch installed, on Windows 10, I do this sequence:</p>
<pre><code class="lang-auto">conda install -c conda-forge librosa
conda install -c groakat sox
</code></pre>
<p>then in a fresh download from <a href="https://github.com/pytorch/audio" rel="nofollow noopener">https://github.com/pytorch/audio</a> I do</p>
<p><code>python setup.py install</code></p>
<p>and it runs for a while and ends like this:</p>
<pre><code class="lang-auto">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
</code></pre>
<p>I think I’m almost there and this is doable.  Please help!</p>
<p>Note this is also an open GitHub issue of long standing: <a href="https://github.com/pytorch/audio/issues/50" rel="nofollow noopener">https://github.com/pytorch/audio/issues/50</a></p>

username: Kushaj
cooked: <p>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.</p>

username: Lars_Ericson
cooked: <p>Kushaj, I also cross-posted on StackOverflow and I got an answer over there which looks like a firm and definitive negative for Windows: <a href="https://stackoverflow.com/questions/54872876/how-to-install-torch-audio-on-windows-10-conda" rel="nofollow noopener">https://stackoverflow.com/questions/54872876/how-to-install-torch-audio-on-windows-10-conda</a></p>

username: Kushaj
cooked: <p>Can you do a check for me. Open terminal and import numpy or any conda package. Tell me if it works or not.</p>

username: Lars_Ericson
cooked: <p>It works fine:</p>
<pre><code class="lang-auto">&gt;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.
&gt;&gt;&gt; import numpy
</code></pre>
<p>This is an open, logged issue for Windows.  I’m hoping a PyTorch guru will take pity on Windows folks and fix it.</p>

username: Kushaj
cooked: <p>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.</p>

username: Lars_Ericson
cooked: <p>Other people have suggested WSL Linux on Windows but there are still problems accessing GPU with that: <a href="http://www.erogol.com/using-windows-wsl-for-deep-learning-development/" rel="nofollow noopener">http://www.erogol.com/using-windows-wsl-for-deep-learning-development/</a></p>
<p>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: <a href="https://github.com/simoninithomas/DNN-Speech-Recognizer" rel="nofollow noopener">https://github.com/simoninithomas/DNN-Speech-Recognizer</a></p>

username: Lars_Ericson
cooked: <p>For the record, I was trying to reproduce this OpenNMT-py speech training demo on Windows: <a href="http://opennmt.net/OpenNMT-py/speech2text.html" rel="nofollow noopener">http://opennmt.net/OpenNMT-py/speech2text.html</a></p>

username: maremoto
cooked: <p>Hi,</p>
<p>I managed to compile torchaudio with sox in Windows 10, but is a bit tricky.</p>
<p>Unfortunately the sox_effects are not usable, this error shows up:<br>
<code>RuntimeError: Error opening output memstream/temporary file</code></p>
<p>But you can use the other torchaudio functionalities.</p>
<p>The steps I followed for Windows 10 64bit are:</p>
<p>#############################</p>
<h1>TORCHAUDIO WINDOWS10 64bit</h1>
<p>#############################</p>
<p><strong>Note:</strong> I mix some command lines unix-like syntax, you can use file explorer or whatever</p>
<h3>preliminar arrangements</h3>
<ol>
<li>
<p>Download sox sources<br>
<code>$ git clone git://git.code.sf.net/p/sox/code sox</code></p>
</li>
<li>
<p>Download other sox source to get lpc10</p>
</li>
</ol>
<pre><code class="lang-auto">$ git clone https://github.com/chirlu/sox/tree/master/lpc10 sox2
$ cp -R sox2/lpc10 sox
</code></pre>
<ol start="3">
<li>IMPORTANT get VisualStudio2019 and BuildTools installed</li>
</ol>
<h3>lpc10 lib</h3>
<p>4.0. Create a VisualStudio CMake project for lpc10 and build it<br>
<em>Start window -&gt; open local folder -&gt; sox/lpc10</em><br>
<em>(it reads CMakeLists.txt automatically)</em><br>
<em>Build-&gt;build All</em></p>
<p>4.2. Copy lpc10.lib to sox</p>
<pre><code class="lang-auto">$ mkdir -p sox/src/out/build/x64-Debug
$ cp sox/lpc10/out/build/x64-Debug/lpc10.lib sox/src/out/build/x64-Debug
</code></pre>
<h3>gsm lib</h3>
<p>5.0. Create a CMake project for libgsm and compile it as before with lpc10</p>
<p>5.1. Copy gsm.lib to sox</p>
<pre><code class="lang-auto">$ mkdir -p sox/src/out/build/x64-Debug
$ cp sox/libgsm/out/build/x64-Debug/gsm.lib sox/src/out/build/x64-Debug
</code></pre>
<h3>sox lib</h3>
<p>6.0. Create a CMake project for sox in VS</p>
<p>6.1. Edit some files:</p>
<p>CMakeLists.txt: (add at the very beginning)</p>
<p><code> project(sox)</code></p>
<p>sox_i.h: (add under stdlib.h include line)</p>
<pre><code class="lang-auto">#include &lt;wchar.h&gt; /* For off_t not found in stdio.h */
#define UINT16_MAX  ((int16_t)-1)
#define INT32_MAX  ((int32_t)-1)
</code></pre>
<p>sox.c: (add under time.h include line)</p>
<pre><code>`#include &lt;sys/timeb.h&gt;`
</code></pre>
<p>6.2. Build sox with VisualStudio</p>
<p>6.3. Copy the libraries where python will find them, I use a <strong>conda environment</strong>:</p>
<pre><code class="lang-auto">$ cp sox/src/out/build/x64-Debug/libsox.lib envs\&lt;envname&gt;\libs\sox.lib
$ cp sox/src/out/build/x64-Debug/gsm.lib envs\&lt;envname&gt;\libs
$ cp sox/src/out/build/x64-Debug/lpc10.lib envs\&lt;envname&gt;\libs
</code></pre>
<h3>torchaudio</h3>
<p><code>$ activate &lt;envname&gt;</code></p>
<p>7.0. Download torchaudio from github<br>
<code>$ git clone https://github.com/pytorch/audio thaudio</code></p>
<p>7.1. Update setup.py, after the “else:” statement of “if IS_WHEEL…”<br>
<code>$ vi thaudio/setup.py</code></p>
<p><span class="hashtag">#if</span> IS_WHEEL…</p>
<pre><code class="lang-auto">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']
</code></pre>
<p>7.2. Edit sox.cpp from torchaudio because dynamic arrays are not allowed:</p>
<pre><code class="lang-auto">$ vi thaudio/torchaudio/torch_sox.cpp

 //char* sox_args[max_num_eopts];
 char* sox_args[20]; //Value of MAX_EFFECT_OPTS
</code></pre>
<p>7.3. Build and install</p>
<pre><code class="lang-auto">$ cd thaudio
$ python setup.py install
</code></pre>
<p>It will print out tons of warnings about type conversion and some library conflict with MSVCRTD but “works”.</p>
<p>And thats all.</p>