I’m a user of Pymc3 on Windows 10 using Anaconda and for the longest time that I can remember, it has been incredibly frustrating to get Pymc3 working correctly. Often this was due to the lack of consistent compilers being available on Windows. When they were available, say via Anaconda or Cygwin or Mingw or MSYS2, configuration was a nightmare. Or a working install would break with package upgrades!!! My instructions are geared towards a beginner/intermediate level user in setting up these tools and environments on Windows. Assumes you will not try to fix an existing installation of Pymc3. Assumes you are going to do a fresh install. - Assumes you know the risk of playing with open-source tools
Here are the set of instructions that worked for me in getting Pymc3 working on Windows 10 and Anaconda.
Setting up Compilers using MSYS2 (current 11.2.0)
-
Download MSYS2 from here MSYS2 and follow the instructions exactly as given.
-
Once installation and post installation activities are completed do the following (You may need Admin level rights) - Search for Edit System Environment Variables. In the GUI interface,
-
Click on “Environment Variables” button
-
In the top part of the window meant for “User Variables” select “path” and then click on “Edit” button. You should see:
-
Click on “New” button. Add the path “C:\msys64\mingw64\bin” and move it to the top.
-
Next add the path “C:\msys64\usr\bin” and move it just under the previous path. Path in step 5 should be 1 and path in step 6 should be 2.
Note - Do not make this change in the System Variables. Make it only in the User Variable and I will explain why. If you are a R user like I’m using both R and Python for advanced analytics, making these changes in System Variables will mess up detection of your RTools by R/R-Studio. Hence you see that under my User Variables there is a “RTOOLS40_HOME” variable. RTools is also based on MSYS2 with gcc-8.3.0
version. Pymc3 will not work correctly with this version. You notice RTools location in not in the Users Path
variable but under a separate User Variable
** Download and Install Anaconda **
- Launch the Anaconda3 CMD Prompt. You should see:
(base) C:\Users\Your_User_Name>
- Run the command
g++ --version
at the previous prompt - If you have installed MSYS2 and set up user variables correctly then your output should look like:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-11.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-lto --enable-libgomp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --with-boot-ldflags='-pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high -Wl,--disable-dynamicbase -static-libstdc++ -static-libgcc' 'LDFLAGS_FOR_TARGET=-pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high' --enable-linker-plugin-flags='LDFLAGS=-static-libstdc++\ -static-libgcc\ -pipe\ -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high\ -Wl,--stack,12582912'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Rev2, Built by MSYS2 project)
- If you do not see this output with 11.2.0 version of
gcc
you have to go to your MSYS2 and User Variable setup.
Assuming your test shows gcc-11.2.0
proceed to create a new environment and install pymc3
using the following commands
** Pymc3 installation **
- Do not install
pymc3
in the base environment. Create a new environment using
(base) C:\Users\Your_User_Name>conda create -n pymc3_env -c conda-forge python libpython mkl-service numba python-graphviz scipy arviz
Key pieces of the installation are taken from Pymc3 Installation Guide (Windows)
here pymc3_env
is the new environment being created (you can use a name of your choice). If all goes well you should see this output
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate pymc3_env
#
# To deactivate an active environment, use
#
# $ conda deactivate
- Activate the new environment
(base) C:\Users\Your_User_Name>conda activate pymc3_env
- Your new prompt should look like:
(pymc3_env) C:\Users\Your_User_Name>
-
Next run the command
pip install pymc3
at the prompt -
There should be no errors and you should see at the very end the following message:
Installing collected packages: filelock, theano-pymc, semver, patsy, fastprogress, dill, cachetools, pymc3
Successfully installed cachetools-5.0.0 dill-0.3.4 fastprogress-1.0.0 filelock-3.4.2 patsy-0.5.2 pymc3-3.11.4 semver-2.13.0 theano-pymc-1.1.2
Make sure that this above message includes theano-pymc
and not theano
. Your pymc3
will not work correctly if theano
exists in your environment. It also means you are not installing into a fresh environment.
** Testing that Pymc3 Works **
- At the
pymc3_env
prompt, launchpython
shell by running the commandpython
(pymc3_env) C:\Users\Your_User_Name>python
- You should see:
Python 3.10.2 | packaged by conda-forge | (main, Jan 14 2022, 07:58:58) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
- Type the following commands one at a time and check you can run without any errors
a.>>>import numpy as np
b.>>>import pymc3 as pm
c.>>>import theano
d. >>>d = pm.Normal.dist(mu=0, sd=1)
(defining an instance of Normal Dist using pymc3 pm)
e. >>>d.dist()
(confirming the type of variable/object created)
<pymc3.distributions.continuous.Normal object at 0x0000027EE8043700>
[output]
f. >>>d.random(size=10) (drawing a sample of 10 values from the created distribution)
array([-0.73922894, 1.36053095, 1.06533255, 2.64590712, 1.24948074,
-0.82108831, -1.42403241, -1.16401114, -0.14718495, -0.37357477])
(Note - you will get different values from what I show since these are draws from a Normal Distribution)
g. >>>d.logp(0).eval() (calculating the Log Probability of the distribution)
array(-0.91893853)
(Note - The log probability should be the same as the value shown above since this is a Standard Normal Distribution)
-
If you are able to get all the commands to run correctly then you know your Pymc3 is working correctly.
-
You can exit this
python
shell withexit()
command. -
Your prompt should look like:
(pymc3_env) C:\Users\Your_User_Name>
- If you prefer to use either Jupyter Notebooks or Jupyter Lab for your
pymc3
example projects you can additionally install using
(pymc3_env) C:\Users\Your_User_Name>conda install -c conda-forge notebook
-
This command once run will install a whole lot of new packages. Once you get the prompt back you can run the command
jupyter-notebook
and it should launch in your default browser. You can get additional examples to run from the following extensive resources:
** Feedback and Q&A **
-
Just knowing how difficult and frustrating such a setup can be for Windows users, if you have questions or running into trouble with these instructions on a fresh installation and setup of Pymc3 on Windows, I will try my best to help and troubleshoot.
-
Hopefully you are trying all these things on a personal machine and not a mission critical work machine.
-
You are working with Open-source tools and Windows does not play nice with them and with the next upgrade of Windows or next version of Anaconda or next version of Pymc3 or your
gcc
tool or some other obscure package dependency, your Pymc3 install can and will break. -
I owe an incredible number of thanks to all those folks here and the Pymc3 github site for the amazingly patient help they have extended over the years to users such as I. Thanks all!