Skip to content

Commit

Permalink
differences for PR #11
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 28, 2024
1 parent 09c93db commit d2682cf
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 1 deletion.
141 changes: 141 additions & 0 deletions accessing-packages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
title: 'Accessing Packages'
teaching: 30
exercises: 2
---

:::::::::::::::::::::::::::::::::::::: questions

- What are the different ways of downloading python packages?
- What are package managers?
- How can I use my own package?

::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::: objectives

- Learn about package managers such as PIP
- Install packages using PIP
- Install packages from source

::::::::::::::::::::::::::::::::::::::::::::::::


## Introduction

Due to Pythons popularity as a language, it is quite likely that you won't be the first person to set off on solving any particular task.
Many others have worked on common problems and then shared their solution in the form of a pacakge, which you can conveniently integrate into your own code and use!

::: callout

### Popular Packages
Some of the most popular packages you may have heard of are:

- Numpy
- Pandas
- Tensorlow
- Matplotlib
- Requests

:::

## Python Package Index (PyPI)

The Python Package Index or PyPI is an online repository of Python packages hosting over 500,000 packages! While there are alternatives such as [conda-forge](https://conda-forge.org), PyPI is by far the most commonly used and likely to have all you need.

::: challenge

### Exercise 1: Explore PyPI

Explore [PyPI](https://pypi.org/project/pip/) to get familiar with it, try searching for packages that are relevant to your research domain / role!

:::

::: callout
## pip

pip (package installer for Python) is the standard tool for installing packages from PyPI.
You can think of PyPI being the supermarket full of packages and pip being the delivery van bringing it to your installation.

:::


### Using pip

pip itself is a python package that can be found on [PyPI](https://pypi.org/project/pip/), however it comes preinstalled with most python installations, for example [python.org](https://python.org) and inside virtual environments.

The most common way to use pip is from the command line. At the top of a package page on PyPI will be the example line you need to install the package

```
py -m pip install numpy
```

The above will install [numpy](https://pypi.org/project/numpy/) from PyPI, a popular scientific computing package enabling a wide range of mathematical and scientific functions.


::: challenge
### Exercise 2: Create venv and install Numpy

Step 1: Create a venv using the command `py -m venv .venv`

and activate it with

::: tab

### Windows

`.\.venv\Scripts\activate`



### macOS / Linux

`source .venv/bin/activate`


:::

Step 2: Install Numpy into your new environment

Step 3: Check your results with `py -m pip list`

Step 4: Deactivate your environment with `deactivate`

:::

::: spoiler

### Virtual Environments

Check out [this documentation](https://docs.python.org/3/l[PyPI](https://pypi.org/project/pip/)ibrary/venv.html) or the FAIR4RS course on virtual environments to learn more!

:::


pip can also be used to install packages from source, this means all the files for the package are on your local computer and pip installs it following the packaging instructions into your local environment ready to use. This is especially handy for packages either not on PyPI or for your own packages you're developing.

```
py -m pip install .
```

::: instructor

The above command should be universal on both windows and mac/unix setups. It may be worth checking with the class at this point that they are all familiar with the -m notation, and what the above command does exactly

:::

Here the `.` means to install your current directory as a Python package. For this to work the directory your command line interface is currently in needs to have a packaging file, i.e. `setup.py` or `pyproject.toml`.



::: keypoints
- pip can be used to download and install Python packages
- PyPI is an online package repository which pip downloads from
- pip can also install local packages like your own
:::






4 changes: 3 additions & 1 deletion md5sum.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"file" "checksum" "built" "date"
"CODE_OF_CONDUCT.md" "c93c83c630db2fe2462240bf72552548" "site/built/CODE_OF_CONDUCT.md" "2024-05-28"
"LICENSE.md" "b24ebbb41b14ca25cf6b8216dda83e5f" "site/built/LICENSE.md" "2024-05-28"
"config.yaml" "42f57814700f8dfad44dc9df247cfed3" "site/built/config.yaml" "2024-05-28"
"config.yaml" "81a1fdd0a29647e526fd764ef5b478bc" "site/built/config.yaml" "2024-05-28"
"index.md" "a02c9c785ed98ddd84fe3d34ddb12fcd" "site/built/index.md" "2024-05-28"
"links.md" "8184cf4149eafbf03ce8da8ff0778c14" "site/built/links.md" "2024-05-28"
"episodes/introduction.md" "6c55d31b41d322729fb3276f8d4371fc" "site/built/introduction.md" "2024-05-28"
"episodes/package-file-history.Rmd" "7e70e2133c8c61dbfaca95ec89604ce6" "site/built/package-file-history.md" "2024-05-28"
"episodes/accessing-packages.md" "ece8d4d0d6881a9677dd6ef86ad0bbbe" "site/built/accessing-packages.md" "2024-05-28"
"instructors/instructor-notes.md" "cae72b6712578d74a49fea7513099f8c" "site/built/instructor-notes.md" "2024-05-28"
"learners/reference.md" "1c7cc4e229304d9806a13f69ca1b8ba4" "site/built/reference.md" "2024-05-28"
"learners/setup.md" "5456593e4a75491955ac4a252c05fbc9" "site/built/setup.md" "2024-05-28"
"profiles/learner-profiles.md" "60b93493cf1da06dfd63255d73854461" "site/built/learner-profiles.md" "2024-05-28"
"renv/profiles/lesson-requirements/renv.lock" "4e0911013d95218c0b3a4a044828f62e" "site/built/renv.lock" "2024-05-28"

0 comments on commit d2682cf

Please sign in to comment.