Install PyMC3 and Theano Windows 10

It’s been a while since I’ve used PyMC3 and now I cannot seem to get a working installation. I’m running into various issues with Theano. Is there a concrete, step-by-step guide for installing PyMC3 on Windows 10 64-bit? Is there a specific version of Python I should use? A specific distribution?

Thanks!

What kind of error you are seeing? There are a few threads on the discourse related to Windows install, for example: Errors in importing pymc3 - maybe give this a try?

my issue seems to be with getting Theano installed and working properly. after installing pymc3 as recommended, I get the errors below when trying to import theano

(base) PS C:\WINDOWS\system32> conda install -c conda-forge pymc3

Collecting package metadata (repodata.json): done
Solving environment: done

Package Plan

environment location: C:\Users\amarion\AppData\Local\Continuum\anaconda3

added / updated specs:
- pymc3

The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
ca-certificates-2019.11.28 |       hecc5488_0         182 KB  conda-forge
certifi-2019.11.28         |           py36_0         148 KB  conda-forge
conda-4.8.0                |           py36_1         3.0 MB  conda-forge
libgpuarray-0.7.6          |    hfa6e2cd_1003         314 KB  conda-forge
mako-1.1.0                 |             py_0          57 KB  conda-forge
openssl-1.1.1d             |       hfa6e2cd_0         4.7 MB  conda-forge
pygpu-0.7.6                |py36h452e1ab_1000         583 KB  conda-forge
pymc3-3.7                  |             py_0         649 KB  conda-forge
theano-1.0.4               |py36h6538335_1000         3.7 MB  conda-forge
vs2015_win-64-14.0.25420   |      h55c1224_11           6 KB
------------------------------------------------------------
                                       Total:        13.3 MB

The following NEW packages will be INSTALLED:

libgpuarray conda-forge/win-64::libgpuarray-0.7.6-hfa6e2cd_1003
mako conda-forge/noarch::mako-1.1.0-py_0
pygpu conda-forge/win-64::pygpu-0.7.6-py36h452e1ab_1000
pymc3 conda-forge/noarch::pymc3-3.7-py_0
theano conda-forge/win-64::theano-1.0.4-py36h6538335_1000
vs2015_win-64 pkgs/main/win-64::vs2015_win-64-14.0.25420-h55c1224_11

The following packages will be UPDATED:

ca-certificates pkgs/main::ca-certificates-2019.11.27~ --> conda-forge::ca-certificates-2019.11.28-hecc5488_0

The following packages will be SUPERSEDED by a higher-priority channel:

certifi pkgs/main --> conda-forge
conda pkgs/main --> conda-forge
openssl pkgs/main::openssl-1.1.1d-he774522_3 --> conda-forge::openssl-1.1.1d-hfa6e2cd_0

Proceed ([y]/n)? y

Downloading and Extracting Packages
vs2015_win-64-14.0.2 | 6 KB | ################################################################################################################################################################################################# | 100%
libgpuarray-0.7.6 | 314 KB | ################################################################################################################################################################################################# | 100%
mako-1.1.0 | 57 KB | ################################################################################################################################################################################################# | 100%
pymc3-3.7 | 649 KB | ################################################################################################################################################################################################# | 100%
ca-certificates-2019 | 182 KB | ################################################################################################################################################################################################# | 100%
pygpu-0.7.6 | 583 KB | ################################################################################################################################################################################################# | 100%
certifi-2019.11.28 | 148 KB | ################################################################################################################################################################################################# | 100%
theano-1.0.4 | 3.7 MB | ################################################################################################################################################################################################# | 100%
openssl-1.1.1d | 4.7 MB | ################################################################################################################################################################################################# | 100%
conda-4.8.0 | 3.0 MB | ################################################################################################################################################################################################# | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(base) PS C:\WINDOWS\system32> python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import theano

You can find the C code in this temporary file: C:\Users\ADMIN-~2\AppData\Local\Temp\theano_compilation_error_44wsaxn_
Traceback (most recent call last):
File “C:\Users\amarion\AppData\Local\Continuum\anaconda3\lib\site-packages\theano\gof\lazylinker_c.py”, line 81, in
actual_version, force_compile, _need_reload))
ImportError: Version check of the existing lazylinker compiled file. Looking for version 0.211, but found None. Extra debug information: force_compile=False, _need_reload=True

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Users\amarion\AppData\Local\Continuum\anaconda3\lib\site-packages\theano\gof\lazylinker_c.py”, line 105, in
actual_version, force_compile, _need_reload))
ImportError: Version check of the existing lazylinker compiled file. Looking for version 0.211, but found None. Extra debug information: force_compile=False, _need_reload=True

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\amarion\AppData\Local\Continuum\anaconda3\lib\site-packages\theano_init_.py”, line 110, in
from theano.compile import (
File “C:\Users\amarion\AppData\Local\Continuum\anaconda3\lib\site-packages\theano\compile_init_.py”, line 12, in
from theano.compile.mode import *
File “C:\Users\amarion\AppData\Local\Continuum\anaconda3\lib\site-packages\theano\compile\mode.py”, line 11, in
import theano.gof.vm
File “C:\Users\amarion\AppData\Local\Continuum\anaconda3\lib\site-packages\theano\gof\vm.py”, line 674, in
from . import lazylinker_c
File “C:\Users\amarion\AppData\Local\Continuum\anaconda3\lib\site-packages\theano\gof\lazylinker_c.py”, line 140, in
preargs=args)
File “C:\Users\amarion\AppData\Local\Continuum\anaconda3\lib\site-packages\theano\gof\cmodule.py”, line 2396, in compile_str
(status, compile_stderr.replace(’\n’, '. ‘)))
. C:/Users/amarion/AppData/Local/Continuum/anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1470: undefined reference to __imp_PyExc_. C:/Users/amarion/AppData/Local/Continuum/anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1476: undefined reference to _imp_PyExc. C:/Users/amarion/AppData/Local/Continuum/anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1481: undefined reference to __imp_PyCaps. C:/Users/amarion/AppData/Local/Continuum/anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1482: undefined reference to _imp_PyExc. C:/Users/amarion/AppData/Local/Continuum/anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1497: undefined reference to __imp_PyExc_. C:/Users/amarion/AppData/Local/Continuum/anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1505: undefined reference to _imp_PyExc. C:/Users/amarion/AppData/Local/Continuum/anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1511: undefined reference to __imp_PyExc_. C:/Users/amarion/AppData/Local/Continuum/anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1521: undefined reference to _imp_PyExc. C:\Users\ADMIN-~2\AppData\Local\Temp\ccOxLJig.o:C:/Users/amarion/AppData/Local/Continuum/anaconda3/lib/site-packages/numpy/core/include/numpy/_multiarray. C:/Users/amarion/AppData/Local/Continuum/anaconda3/lib/site-packages/numpy/core/include/numpy/npy_3kcompat.h:460: undefined reference to `__imp_PyCapsule_T. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:\Users\ADMIN-~2\AppData\Local\Temp\ccOxLJig.o:C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:\Users\ADMIN-~2\AppData\Local\Temp\ccOxLJig.o:C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:\Users\ADMIN-~2\AppData\Local\Temp\ccOxLJig.o:C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. C:/Users/admin-amarion/AppData/Local/Theano/compiledir_Windows-10-10.0.17763-SP0-Intel64_Family_6_Model_158_Stepping_10_GenuineIntel-3.6.5-64/lazylinker_ex. collect2.exe: error: ld returned 1 exit status_TrueStruct’

I was able to get everything set up but it was a bit of a challenge. I’ll share the process here if it can help others

I have Python 3.7.3 installed with the Anaconda distribution. Also, if you are doing this behind a firewall or on a work machine, you may need to disable SSL verification, and, run the Anaconda Powershell in admin mode. If you run Anaconda Powershell in admin mode you may need to add some PATH variables for Anaconda

First step is to get Theano installed and tested. I did not set up Theano for GPU.

  1. Install g++ compiler. There is a great walk through here
    https://www.instructables.com/id/How-to-Install-MinGW-GCCG-Compiler-in-Windows-XP78/
  2. Add the g++ PATH variable in windows (instructions in link above)
  3. Install Theano prerequisites via conda

conda install numpy scipy mkl-service libpython m2w64-toolchain nose

  1. Install “parameterized” package to run Theano tests

pip install parameterized

  1. Next install Theano. First try using Conda, but for me I was getting a missing module error during testing and had to then uninstall the conda installation and reinstall use Pip

pip install Theano

  1. Test Theano. You may get some deprecation and minor warnings, those are ok

python -c “import theano; theano.test()”

  1. If Theano tests run ok then you can install PyMC3.

conda install -c conda-forge pymc3

Some of these steps I had to go through multiple times to finally get a working installation. I’m still running into some issues with the plots but will figure those out hopefully

4 Likes

Reviving this thread to share my experience in case it benefits anyone. The solution above installing MinGW didn’t work for me, and from the looks of things the author themselves had problems with a Windows install several months later. I tried a bunch of different methods and all failed in one way or another (see here).

I’ve got PyMC3 and Theano running smoothly now on Windows 10 by … installing Ubuntu on Windows and running the packages using Miniconda in there. Not an ideal solution for everyone, but I’m actually liking it a lot better than dealing with Windows messiness.

I wrote up my full process here, but here’s the brief step-by-step in case it benefits anyone:

1. Install WSL and Ubuntu

2. Install g++ and Miniconda in Ubuntu

  • sudo apt-get install g++
  • wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
  • bash Miniconda3-latest-Linux-x86_64.sh
  • rm Miniconda3-latest-Linux-x86_64.sh

3. Create a fresh environment and install your packages

  • conda create -n pm3 python
  • conda activate pm3
  • conda install mkl-service numpy scipy jupyter
  • conda install -c conda-forge pymc3

Optional Steps for Jupyter Notebooks

I also created a folder in Ubuntu linked to my Jupyter Notebook folder in Windows, and automatically set-up the notebooks to open in my Windows browser based on this GitHub gist.

3 Likes

Just a footnote on WSL2 and Ubuntu 20. When we specify the number of cores in pm.sample, in our set-up it’s ignored and all cores end up being used for some reason. This makes execution unstable. FYI. Will post a solution if we find one.

1 Like