RJAH statistics course

Please follow the installation guidance below to install the software for the RJAH statistics course. Installation can be tricky, but it made easier using the miniconda open source distribution and package manager system.

1: Download Miniconda

Miniconda

2: Install miniconda python version 3.8 for Mac OSX or Windows according to the instructions

3: Create a conda environment for the statistics course

Mac OSX: Applications > Utilities > Terminal

Windows: Command Prompt

Windows users: when you install miniconda, the program may not be added to the path, so when you type conda at the command prompt you get the following error:

‘conda’ is not recognised as an internal or external command, operable program or batch file.

 To add miniconda to the path:

  • Press Windows key + R to open a run dialog box.
  • Type: sysdm.cpl and hit return to open the system properties screen.
  • Go to the Advanced tap and click Environment Variables
  • Select Path and then click .
  • Click on New
  • Type the path: c:\ProgramData\Miniconda3\condabin\
  • Click on New again
  • Type the path: c:\ProgramData\Miniconda3\Scripts\
  • Click OK

 Within Terminal / Command Prompt:

When conda has been installed, there is only one environment (base). You can list the available environments:

conda env list

# conda environments:

#

base                  *  /Users/paulcool/opt/miniconda3

Create an environment for the statistics course (rjah_stats) with python3.8 as program language:

conda create -n rjah_stats python=3.8

Enter ‘y’ to proceed and let conda create the environment.

Again, list the available environments:

conda env list

# conda environments:

#

base                  *  /Users/paulcool/opt/miniconda3

rjah_stats               /Users/paulcool/opt/miniconda3/envs/rjah_stats

(* indicates the active environment)

To activate the newly created environment:

conda activate rjah_stats

Again, check the available environments:

conda env list

# conda environments:

#

base                     /Users/paulcool/opt/miniconda3

rjah_stats            *  /Users/paulcool/opt/miniconda3/envs/rjah_stats

Within the newly created environment, the Python version should be 3.8:

Check the python version (please note two ‘-‘ without a space in between them):

python –version

Python 3.8.5

To leave the environment:

conda deactivate

But stay in the environment for now (or re-activate the rjah_stats environment if you have left the environment).

conda activate rjah_stats

4: Install Jupyter notebook (inside the rjah_stats environment)

Make sure the rjah_stats environment is activated (the command line should start with rjah_stats); so something like:

(rjah_stats) c:\Users\Paul                                                                  (Windows)

Or

(rjah_stats) paulcool@Pauls-MacBook-Pro-2:ttys000 /Users/paulcool%  (OSX)

Install Notebook:

conda install -c conda-forge jupyterlab

Windows users: also install pywin32:

conda install pywin32

and upgrade notebook to the latest version (6.1.3):

pip install notebook –upgrade

5: Open Notebook:

From the command prompt in the rjah_stats environment:

jupyter notebook

Notebook should now open in a browser window.

Keep the command prompt / terminal window open, otherwise Notebook will close.

However, the installed notebook will only be able to execute Python code as R software has not been installed yet.

Close Jupyter notebook and the terminal / command prompt.

6: install R from CRAN

 Download R from CRAN:

and follow the installation instructions.

7: Install the kernel to make notebook work with R

From within the rjah_stats environment install R and the IR kernel

conda install -c r r-irkernel

Follow the instructions here: https://irkernel.github.io/installation/

Mac Users: Open R from terminal NOT the application Icon.

In terminal (base environment), just enter R and hit return.

Follow the instructions (also below).

To quit R, enter q() and hit return.

Windows Users: within the rjah_stats environment enter R and hit return.

Follow the instructions (also below).

To quit R, enter q() and hit return.

Install the Kernel packages from within R:

install.packages(‘IRkernel’)

IRkernel::installspec(user = FALSE)

Now open Jupyter notebook from the rjah_stats environment and R should be available:

jupyter notebook

R should now be available (see top right corner in your notebook)

To start future sessions: 

Use terminal (Mac OSX) or command prompt (Windows)

Go to the conda environment created:

conda activate rjah_stats

Now open Jupyter:

jupyter notebook

Manoeuvre to your Dropbox folder with the assignments.

 

References:

https://docs.conda.io/en/latest/miniconda.html

https://cs205uiuc.github.io/guidebook/resources/python-miniconda.html

https://cran.r-project.org/

https://jupyter.org/

https://jupyter.org/install

https://irkernel.github.io/installation/

https://datatofish.com/r-jupyter-notebook/

 

 

ERRORS

 

Windows users may get a ‘NotImplementedError’

Solution:

Upgrade the version of notebook.

Still within the rjah_stats environment enter:

pip install notebook –upgrade

 

Windows users: can get a Failed to start Kernel error in the Right corner (red).

Click on the red rectangle with the Kernel error.

This may show an ImportError:

DLL failed while importing win32api: The specified module could not be found

Solution:

Close Notebook and the command prompt.

Open a New command prompt window:

conda activate rjah_stats

conda install pywin32