You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 12-virtual-environments.md
+6-67Lines changed: 6 additions & 67 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -483,67 +483,6 @@ six 1.16.0
483
483
To uninstall a package installed in the virtual environment do: `python3 -m pip uninstall <package-name>`.
484
484
You can also supply a list of packages to uninstall at the same time.
485
485
486
-
### Installing Our Local Project as a Package Using `pip`
487
-
488
-
Often when working on a Python project, the project itself will be a Python package (like `numpy` or `matplotlib` above) or at the very least it might be useful to treat it like a package.
489
-
Said another way, it is usually the case we want a convenient way to call the Python code we are writing from another location, and making this code accessible as a package is the best way to do this.
490
-
We will save the details of Python packaging for [a future episode](43-software-release.md), and for the meantime we can use the minimal package setup that our project already comes with, which is contained in the `pyproject.toml` file.
491
-
Once again, we can use `pip` to install our local package:
492
-
493
-
```bash
494
-
python3 -m pip install --editable .
495
-
```
496
-
497
-
::::::::::::::::::::::::::::::::::::::::: spoiler
498
-
499
-
### This command fails for me
500
-
501
-
If your `pip` installation is older than version 21.3, then this command will probably fail for you.
502
-
This is because these older versions of `pip` do not support `pyproject.toml` as the package metadata.
503
-
Given these versions of `pip` are now over 4 years old, we strongly recommend that you update `pip` if you can:
504
-
505
-
```bash
506
-
python3 -m pip install --upgrade pip
507
-
```
508
-
509
-
:::::::::::::::::::::::::::::::::::::::::
510
-
511
-
This is similar syntax to above, with two important differences:
512
-
513
-
1. The `--editable` or `-e` flag indicates that the package we are specifying should be an "editable" install.
514
-
An "editable" install is one that allows the package in our environment to change dynamically based on source code locally.
515
-
This is very convenient when we are developing the package because we can instantly see changes when we call the code from within our virtual environment, rather than having to install the local package again to get the updates.
516
-
2. The argument `'.'` indicates that the package we want to install is located in the current directory.
517
-
The `pyproject.toml` file located in this directory then handles the rest.
518
-
519
-
520
-
521
-
If we reissue the `pip list` command we should now see our local package with the name `python-intermediate-inflammation` in the output:
### Exporting/Importing Virtual Environments Using `pip`
548
487
549
488
You are collaborating on a project with a team so, naturally,
@@ -552,11 +491,12 @@ so they can easily 'clone' your software project with all of its dependencies
552
491
and everyone can replicate equivalent virtual environments on their machines.
553
492
`pip` has a handy way of exporting, saving and sharing virtual environments.
554
493
555
-
To export your active environment use the `python3 -m pip freeze --exclude-editable` command to produce a list of packages installed in the virtual environment.
494
+
To export your active environment -
495
+
use `python3 -m pip freeze` command to produce a list of packages installed in the virtual environment.
556
496
A common convention is to put this list in a `requirements.txt` file:
@@ -578,7 +518,6 @@ The first of the above commands will create a `requirements.txt` file in your cu
578
518
Yours may look a little different,
579
519
depending on the version of the packages you have installed,
580
520
as well as any differences in the packages that they themselves use.
581
-
Also, we need to use the `--exclude-editable` command so that our local package is not included in the output, otherwise pip will try to pull from a specific commit at the time we made the editable install, which is not what we want.
582
521
583
522
The `requirements.txt` file can then be committed to a version control system
584
523
(we will see how to do this using Git in one of the following episodes)
@@ -587,10 +526,10 @@ They can then replicate your environment
587
526
and install all the necessary packages from the project root as follows:
As your project grows you may need to update your environment for a variety of reasons.
532
+
As your project grows - you may need to update your environment for a variety of reasons.
594
533
For example, one of your project's dependencies has just released a new version
595
534
(dependency version number update),
596
535
you need an additional package for data analysis (adding a new dependency)
@@ -665,7 +604,7 @@ to customize the command line.
665
604
- Use `venv` to create and manage Python virtual environments.
666
605
- Use `pip` to install and manage Python external (third-party) libraries.
667
606
-`pip` allows you to declare all dependencies for a project in a separate file (by convention called `requirements.txt`) which can be shared with collaborators/users and used to replicate a virtual environment.
668
-
- Use `python3 -m pip freeze --exclude-editable > requirements.txt` to take snapshot of your project's dependencies.
607
+
- Use `python3 -m pip freeze > requirements.txt` to take snapshot of your project's dependencies.
669
608
- Use `python3 -m pip install -r requirements.txt` to replicate someone else's virtual environment on your machine from the `requirements.txt` file.
Copy file name to clipboardExpand all lines: 23-continuous-integration-automated-testing.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -128,10 +128,10 @@ Let us say we want to add more detail to our list of initial ascenders:
128
128
...
129
129
first_scaled_by:
130
130
- name: Hans Meyer
131
-
date_of_birth: 22-03-1858
131
+
date_of_birth: 1858-03-22
132
132
nationality: German
133
133
- name: Ludwig Purtscheller
134
-
date_of_birth: 22-03-1858
134
+
date_of_birth: 1858-03-22
135
135
nationality: Austrian
136
136
```
137
137
@@ -200,7 +200,7 @@ jobs:
200
200
- name: Install Python dependencies
201
201
run: |
202
202
python3 -m pip install --upgrade pip
203
-
python3 -m pip install -r requirements.txt .
203
+
python3 -m pip install -r requirements.txt
204
204
205
205
- name: Test with PyTest
206
206
run: |
@@ -244,7 +244,7 @@ Each of these steps are:
244
244
In order to locally install our `inflammation` package
245
245
it is good practice to upgrade the version of pip that is present first,
246
246
then we use pip to install our package dependencies.
247
-
Notice that it is fine to omit the `--editable` flag in this case because the source code will be static and therefore we don't need this to be an "editable" install like when we are developing locally.
247
+
Once installed, we can use `python3 -m pip install -e .` as before to install our own package.
248
248
We use `run` here to run theses commands in the CI shell environment
249
249
- **Test with PyTest:** lastly, we run `python3 -m pytest`,
Copy file name to clipboardExpand all lines: 43-software-release.md
+1-12Lines changed: 1 addition & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,7 +82,7 @@ Poetry can also handle virtual environments for us,
82
82
so in order to behave similarly to how we used them previously,
83
83
let us change the Poetry config to put them in the same directory as our project:
84
84
85
-
```bash
85
+
```bash, bash
86
86
$ poetry config virtualenvs.in-project true
87
87
```
88
88
@@ -111,17 +111,6 @@ although use your own contact details!*
111
111
**NB: When you get to the questions about defining our dependencies,
112
112
answer no, so we can do this separately later.**
113
113
114
-
::::::::::::::::::::::::::::::::::::::::: callout
115
-
116
-
## It's Not Interactive?
117
-
118
-
If you're using Git Bash for Windows, depending on your configuration, you may find after typing this command that you don't have an interactive set of questions displayed.
119
-
Instead, you may find the `pyproject.toml` file is simply generated with a set of default values.
120
-
121
-
If this happens, you can edit the `pyproject.toml` file and change the values in this file, similarly to how we have in the output below.
0 commit comments