diff --git a/module4/ressources/resources.html b/module4/ressources/resources.html index 3651f60946b6b237e8e8da5f1851f4e7e255d30f..7a20bb9b409e23159e925bf71c3cd9ccc8a1772f 100644 --- a/module4/ressources/resources.html +++ b/module4/ressources/resources.html @@ -3,22 +3,36 @@

Table of Contents

-
-

Getting information about your Git repository

-
+
+

Getting information about your Git repository

+

When taking notes, it may be difficult to remember which version of the code or of a file was used. This is what version control is useful @@ -109,19 +123,23 @@ is the price to pay for running git from within the notebook itself.

-
-

Getting information about Python(3) libraries

-
+
+

Getting information about Python(3) libraries

+
-
-

Getting the list of installed packages and their version

-
+
+

Getting the list of installed packages and their version

+

This topic is discussed on StackOverflow. When using pip (the Python package installer) within a shell command, it is easy to query the version of all installed packages (note that on your system, you may have to use either pip or pip3 depending on how it is named and which -versions of Python are available on your machine. +versions of Python are available on your machine +

+ +

+Here for example how I get these information on my machine:

pip3 freeze
@@ -148,6 +166,41 @@ wcwidth==0.1.7
 webencodings==0.5
 
+

+In a Jupyter notebook, this can easily be done by using the %%sh +magic. Here is for example what you could do and get on the Jupyter +notebooks we deployed for the MOOC (note that here, you should simply +use the pip command): +

+
+
%%sh
+pip freeze
+
+
+ +
+alembic==0.9.9
+asn1crypto==0.24.0
+attrs==18.1.0
+Automat==0.0.0
+...
+numpy==1.13.3
+olefile==0.45.1
+packaging==17.1
+pamela==0.3.0
+pandas==0.22.0
+...
+webencodings==0.5
+widgetsnbextension==3.2.1
+xlrd==1.1.0
+zope.interface==4.5.0
+
+ +

+In the rest of this document, I will assume the correct command is pip +and I will not systematically insert the %%sh magic. +

+

Once you know which packages are installed, you can easily get additional information about a given package and in particular check @@ -155,9 +208,9 @@ whether it was installed "locally" through pip or whether it is installed system-wide. Again, in a shell command:

-
pip3 show pandas
+
pip show pandas
 echo "            "
-pip3 show statsmodels
+pip show statsmodels
 
@@ -184,10 +237,9 @@ Requires: patsy, pandas
- -
-

How to list imported modules?

-
+
+

How to list imported modules?

+

Without resorting to pip (that will list all available packages), you may want to know which modules are loaded in a Python session as well @@ -248,9 +300,9 @@ zlib 1.0

-
-

Setting up an environment with pip

-
+
+

Setting up an environment with pip

+

The easiest way to go is as follows:

@@ -267,12 +319,86 @@ dynamic libraries that are wrapped by Python though.

+
+

Installing a new package or a specific version

+
+

+The Jupyter environment we deployed on our servers for the MOOC is +based on the version 4.5.4 of Miniconda and Python 3.6. In this +environment you should simply use the pip command (remember on your +machine, you may have to use pip3). +

+ +

+If I query the current version of statsmodels in a shell command, +here is what I will get. +

+
+
pip show statsmodels
+
+
+ +
+Name: statsmodels
+Version: 0.8.0
+Summary: Statistical computations and models for Python
+Home-page: http://www.statsmodels.org/
+Author: Skipper Seabold, Josef Perktold
+Author-email: pystatsmodels@googlegroups.com
+License: BSD License
+Location: /opt/conda/lib/python3.6/site-packages
+Requires: scipy, patsy, pandas
+
+ +

+I can then easily upgrade statsmodels: +

+
+
pip install --upgrade statsmodels 
+
+
+ +

+Then the new version should then be: +

+
+
pip show statsmodels
+
+
+ +
+Name: statsmodels
+Version: 0.9.0
+Summary: Statistical computations and models for Python
+Home-page: http://www.statsmodels.org/
+Author: Skipper Seabold, Josef Perktold
+Author-email: pystatsmodels@googlegroups.com
+License: BSD License
+Location: /opt/conda/lib/python3.6/site-packages
+Requires: scipy, patsy, pandas
+
+ +

+It is even possible to install a specific (possibly much older) version, e.g.,: +

+
+
pip install statsmodels==0.6.1
+
+
+
+
-
-

Getting information about R libraries

-
+
+

Getting information about R libraries

+
+
+
+

Getting the list imported modules and their version

+

-The best way seems to be to rely on the devtools package. +The best way seems to be to rely on the devtools package (if this +package is not installed, you should install it first by running in R +the command install.packages("devtools")).

@@ -334,7 +460,11 @@ Some actually advocate that writing can be done by writing an R package. Those of you willing to have a clean R dependency management should thus have a look at Packrat.

- +
+
+
+

Getting the list of installed packages and their version

+

Finally, it is good to know that there is a built-in R command (installed.packages) allowing to retrieve and list the details of all @@ -588,4 +718,107 @@ packages installed.

+ +
+

Installing a new package or a specific version

+
+

+This section is mostly a cut and paste from the recent post by Ian +Pylvainen on this topic. It comprises a very clear explanation on how +to proceed. +

+
+ +
+

Installing a pre-compiled version

+
+

+If you're on a Debian or a Ubuntu system, it may be difficult to +access a specific version without breaking your system. So unless you +are moving to the latest version available in your Linux distribution, +we strongly recommend you to build from source. In this case, you'll +need to make sure you have the necessary toolchain to build packages +from source (e.g., gcc, FORTRAN, etc.). On Windows, this may require +you to install Rtools. +

+ +

+If you're on Windows or OS X and looking for a package for an older +version of R (R 2.1 or below), you can check the CRAN binary +archive. Once you have the URL, you can install it using a command +similar to the example below: +

+
+
packageurl <- "https://cran-archive.r-project.org/bin/windows/contrib/2.13/BBmisc_1.0-58.zip"
+install.packages(packageurl, repos=NULL, type="binary")
+
+
+
+
+
+

Using devtools

+
+

+The simplest method to install the version you need is to use the +install_version() function of the devtools package (obviously, you +need to install devtools first, which can be done by running in R the +command install.packages("devtools")). For instance: +

+ +
+
require(devtools)
+install_version("ggplot2", version = "0.9.1", repos = "http://cran.us.r-project.org")
+
+
+
+
+
+

Alternatively, you may want to install an older package from source

+
+

+If you devtools fails or if you do not want to depend on it, you can +install it from source via install.packages() directed to the right +URL. This URL can be obtained by browsing the CRAN Package Archive. +

+ +

+Once you have the URL, you can install it using a command similar to +the example below: +

+
+
packageurl <- "http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz"
+install.packages(packageurl, repos=NULL, type="source")
+
+
+ +

+If you know the URL, you can also install from source via the command +line outside of R. For instance (in bash): +

+
+
wget http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz
+R CMD INSTALL ggplot2_0.9.1.tar.gz
+
+
+
+
+
+

Potential issues

+
+

+There are a few potential issues that may arise with installing older +versions of packages: +

+
    +
  • You may be losing functionality or bug fixes that are only present +in the newer versions of the packages.
  • +
  • The older package version needed may not be compatible with the +version of R you have installed. In this case, you will either need +to downgrade R to a compatible version or update your R code to work +with a newer version of the package.
  • +
+
+
+
+