We recommend installing Python via the Anaconda Distribution. Be sure to use the "Python 3.6.x" version or later. We will use the Conda Package Management System within the Anaconda Distribution. From the documentation:
Conda is an open source package management system and environment management system that runs on Windows, macOS and Linux. Conda quickly installs, runs and updates packages and their dependencies. Conda easily creates, saves, loads and switches between environments on your local computer.
After the installation run python --version
in a terminal window (in "Anaconda Prompt" if you are using Windows). If the output show "Python 3.6.x" or later (and "Anaconda") you are good to go.
The course code is hosted on the code-sharing platform GitHub (where you now are reading this). If you do not have a GitHub account already you should make one now. We recommend that you are using the platform for you own projects during the course. https://github.com/join.
After you have successfully installed Anaconda, go through the following steps (if you are using Windows, be at the "Anaconda Prompt").
conda install git
git clone https://github.com/oercompbiomed/CBM101
cd CBM101
NB! Before executing the next command, we recommend you temporarily deactivate your antivirus (AV) software. Some software conflates python.exe with a virus (IDP.generic), and will corrupt your install. If your AV gives this warning, delete your environment (conda remove --name cbm101 --all --yes
), deactivate the AV and run the commands below.
conda env update
You should now reactivate the AV.
conda activate cbm101
If you are using Linux or MacOS and the command above fails, type
source ~/.bash_profile
and try conda activate cbm101
again. If this fails, activate the environment by typing source activate cbm101
instead.
python -m ipykernel install --user --name cbm101 --display-name "CBM101"
Go through the notebook 1.0-python-basics.ipynb
in the B_Python_and_friends
directory:
cd B_Python_and_friends
jupyter notebook
(Tip: you can auto complete the name of a file/directory by pressing Tab, so you won't have to write out the
full name.) Jupyter notebook only supports Firefox, Safari and Chrome. Unless you have set one of these as your default browser,
you should do so, or alternatively you can run jupyter notebook --no-browser
and paste the link into a supported browser.
You can also use JupyterLab: jupyter lab
.
The code and environment will be updated during the course. Run the following commands regularly:
- Update code:
git pull
- Update environment:
conda activate cbm101
conda env update
Sometimes git pull
will throw an error message as it would overwrite any local changes you have made. This
problem can be solved by:
i) Make a copy of the notebook (.ipynb) files before working through them.
OR
ii)
git fetch --all
git reset --hard origin/master
WARNING: option ii) will permanently delete any personal changes you have made to any of the original files (but not the copied ones).
These notebooks requires an R kernel to run the R scripts. We recommend to install the latest R version (https://www.r-project.org/), open an R console and then follow the instructions in https://irkernel.github.io/installation.
at the local CBM101 root directory, and have installed R version 3.5.1 (say), type:
CBM101>conda deactivate
CBM101>"C:\Program Files\R\R-3.5.1\bin\R.exe"
Now you got the R command prompt >
. Then type
> install.packages('IRkernel')
> IRkernel::installspec()
> quit()
at the local CBM101 root directory, and have installed R version 3.6.0 (say), type:
CBM101>conda deactivate
CBM101>/usr/local/bin/R
Now you got the R command prompt >
. Then type
> install.packages('IRkernel')
> IRkernel::installspec()
> quit()
at the local CBM101 root directory, and have installed R version 3.6.1 (say), type:
CBM101>conda deactivate
CBM101>/usr/bin/R
Now you got the R command prompt >
. Then type
> install.packages('IRkernel')
> IRkernel::installspec()
> quit()
Then: Go to the E_Biostatistics
folder, and start the Jupyter notebook, i.e.
CBM101/E_Biostatistics>jupyter notebook
and you will load the R kernel
when opening an .ipynb
notebook, say ProbsAndDistr.ipynb
in the Probabilities-and-Distributions
folder.
Using Anaconda for the R programming language in Jupyter Notebookhttps see: https://docs.anaconda.com/anaconda/navigator/tutorials/r-lang
More features and a user-friendly environment to run R scripts outside jupyter are available through RStudio
Install the necessary libraries (only needed once) by executing (shift-enter), e.g.`
install.packages("MASS", repos='http://cran.us.r-project.org')
The Atom text editor has a live-preview mode for markdown files. The keyboard shortcut is CTRL+SHIFT+M.