Hi @michaelosthege - here is the first version of the Installation Reference. Let me know what changes may be needed.
For Pymc3 Windows users who may not have a programming background or have comfort with tool chains and such, the installation instructions on this page (https://github.com/pymc-devs/pymc3/wiki/Installation-Guide-(Windows)) may not be sufficient. The instructions posted below go beyond the basic installation process posted at the above link.
In addition, there are a large community of users, who use both R and Python (Anaconda). The RTools mingw tool chain
has to be first on the System Environment variables so that R packages that need compilation such as rstan, brms
will run correctly. In this situation, the compilation of pymc3
models will break and additional post-install User Environment Variables
has to be done so pymc3
works correctly.
Versions and main components
- PyMC3 Version: 3.11.2
- Aesara/Theano Version: 1.1.2 ( using
theano-pymc
)
- Python Version: 3.7 / 3.8 using Anaconda3 64-bit
- Operating system: Windows 10 64-bit, with 1904 Update
- How did you install PyMC3: pip
- C & C++ compilers: Installed
m2w64 tool chain from conda-forge
- Microsoft VS C++ compiler(s) present? No
- Any Competing C++ compiler(s) present? Yes -
RTools mingw tool chain
on the System PATH
The essence of a solid PyMC3 installation on Windows is to install most of the dependencies through conda. The reason installation via PyPI is difficult is that Theano/Aesara require compilation against MKL, which is difficult to set up, while Conda comes with its own compilers and MKL installation.
⚠ Do not pip install without first installing dependencies with conda. ⚠
Method 1: Run conda env create -f environment.yml
to create a fresh environment in one step - use Notepad++, if possible to create the said environment.yml
file.
environment.yml (copy from name: pm3env
and ending with pymc3
and save it in C:\Users\Your_User_Name
)
channels:
- conda-forge
- defaults
dependencies:
- libpython
- blas
- mkl-service
- m2w64-toolchain
- numba
- pip
- python=3.8
- python-graphviz
- scipy
- pip:
- pymc3
You can change name to something meaningful for you such as pym3
or env_pym3
. You do not have to use pm3env
. Keep it simple and meaningful so you can use the environment with ease when using the command line.
Method 2: You can create pymc3
specific environment also directly from the Anaconda3 Command Prompt
using the following command:
conda create -n pm3env -c conda-forge "python=3.8" libpython mkl-service m2w64-toolchain numba python-graphviz scipy
After you have created the environment, you can test it has been created successfully by typing:
conda info --envs
- the output of the command will show all the environments that exist in the current Anaconda3 install. Hopefully you will see your environment for pymc3
Activate your environment by typing the command: conda activate pm3env
(or whatever name you chose)
Your command prompt will look like: (pm3env) C:\Users\Your_User_Name
Check Packages Installed using the command conda list
and all packages installed in pm3env
will be shown. Check if either one of theano
or theano-pymc
has been installed. Make note of it (It should not be)
Install Pymc3: Now you can install Pymc3 using the command: pip install pymc3
and then if all requirements are met, all packages from pip and their dependencies will be installed,. Of critical importance to note is whether theano-pymc
has been installed along with pymc3
- pymc3 will not run without this - Here theano-pymc
should be installed. In addition, in the pip
output check that dependencies such as arviz
(for working with pymc3
objects) and matplotlib
(for general purpose data graphing) have also been installed.
Sometimes these packages may not be installed in your new environment but will be installed likely in the location below on Windows 10: c:\users\your_user_name\appdata\roaming\python\python38\site-packages
- note the number 38 next to python38
in the folder name. This means that versions relevant for python3.8 have been installed here. These packages will not appear in the output of conda list
. Ensure that the python
you specified (python=3.8) matches what you see in the folder name here (python38)
[@michaelosthege The original instructions ask to install theano-pymc
using conda-forge
. However, I found that in the new dependency installation of pymc3
, theano-pymc
is being automatically being installed and it is working correctly. This is one where I need your input on whether we remove the note to update theano-pymc
. I think this is outdated]
Now there are additional ways to install ``pymc3and additional variants of
pymc3```. Refer to the next section, which may be more appropriate for advanced users.
Developer Installation
If you want to tinker with PyMC3 itself, first clone the repository and then make an "editable" installation:
(You need to have already installed git
for this to work, if not install git
first)
cd pymc3
pip install --editable .
Upgrading from Theano to Theano-PyMC - Just in case when you run conda list
at the pm3env
prompt and find that you have theano
instead of theano-pymc
(stranger things have and will happen!)
- Make a note of the channel where
theano
was installed from: it will show pypi or conda-forge.
- If you see pypi then use the command,
pip uninstall theano
- you should see a message stating theano
has been uninstalled
- If you see conda-forge use the command,
conda remove theano
- you should answer with a y if prompted for the removal of theano
- Install
theano-pymc
using the command, conda install -c conda-forge theano-pymc
.
- Once the installation is complete, run the command
conda list
and verify pymc3 & theano-pymc
are installed.
Optional Dependencies (before you install any packages, first check they have not been already installed using conda list
- The GLM submodule relies on Patsy. Patsy brings the convenience of "R-style formulas" to Python.
- pm.model_to_graphviz depends on Graphviz and pydot:
- Use the command
conda install -c conda-forge python-graphviz
and pip install pydot-ng
- In the package installations done so far,
Jupyter Notebook
or Jupyter Lab
are not installed. If you are working with Anaconda3, you install these two Jupyter tools from Anaconda3 Navigator or from the pm3env command prompt
using the command: conda install -c conda-forge notebook
Do Not Close the Command Prompt window of the pm3env - we have to use it later on.
Post Installation Checks - Do Not Skip This Step on Windows
A. Assumes you have installed Jupyter Notebook
B. Make note of whether you have R and in particular RTools installed on your laptop and location of its' install.
C. Assumes you have either Admin or Power-User rights on your laptop so that you can make changes to the environment variables at the User level.
-
Windows does not come pre-installed with C and C++ compilers (as Mac and Linux Distros do) so it is important to ensure your Anaconda3 environments are pointing to the correct internal compilers.
-
Going back to the original creation / installation of pm3env
environment, one of the packages installed is m2w64-toolchain
. Here things can get complex in terms of having compiler tools specific to the version of Python and to that of the environment. So generally speaking, try to keep your Anaconda3 environments to a minimum, when you are starting out with tools such as pymc3
. Also make sure you install a m2w64-toolchain
in each environment you create. Conda will ensure that you have the most appropriate version of the compilers for the version of Python in that environment. There are exceptions, but it gets beyond the scope of this document.
-
On Windows, search for "Edit System Environment Variables". You will be taken to the screen below
-
Click on the "Environment Variables" on the bottom right-hand corner and you will see a new window pop-up with the top Window for User variables and the bottom window for the System variables. Click on the entry labeled Path under User Variables for Your_User_Name and click edit. Here you should add the following Anaconda paths specific to your environment:
Note the location of where Anaconda3 is installed by default (as shown below). If you have changed the location during the installation of Anaconda3, please make the changes accordingly.
First: C:\ProgramData\Anaconda3\Library\mingw-w64\bin
Second: C:\ProgramData\Anaconda3\Library\bin
Third: C:\ProgramData\Anaconda3\Scripts
Move each of the entries so that they appear in the exact order as shown above at the top of the User Variables Path using the Move Up and Move Down buttons
Then click "OK" to accept the changes all the way.
-
Go back to the pm3env
Command Prompt window that is already open that displays (pm3env) C:\Users\Your_User_Name>
-
Type jupyter-notebook
at the prompt and (hopefully) a page should be opened in your Default Browser.
-
On the top right corner, click on the drop-down under New
-
Select Python 3 (ipykernel)
-
You should see a new Jupyter Notebook open that looks as follows:
-
Make sure that at the top right corner, the button says Trusted. If this is the first time you are using a Jupyter Notebook, it might show up as Not Trusted. Click on it if it says "Not Trusted" and select the option to make it "Trusted".
-
In the first Notebook cell, type import theano as tp
and click on the Run button.
-
You may see a warning as shown in the picture below (WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
)
-
In the next cell type the following commands and click Run
import pymc3 as pm
print(f"Running on PyMC3 v{pm.__version__}")
-
You should see an output as follows: Running on PyMC3 v3.11.2
-
You can now begin testing the full capabilities of Pymc3 by starting with the three examples from the Getting Started with Pymc3 - linked here - http://docs.pymc.io/notebooks/getting_started
Good luck with using Pymc3!
installation