Skip to content

Commit 69a0944

Browse files
docs: add conda and venv activation steps to create-python-package (#818)
* docs: show conda and venv activation steps in "install your package locally" * docs: clarify why create-python-package uses pip instead of Hatch * Apply batched suggestions from code review Co-authored-by: Leah Wasser <leah@pyopensci.org> --------- Co-authored-by: Leah Wasser <leah@pyopensci.org>
1 parent 31535b5 commit 69a0944

1 file changed

Lines changed: 46 additions & 17 deletions

File tree

‎tutorials/create-python-package.md‎

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -318,26 +318,56 @@ At this point, you should have:
318318

319319
You are now ready to install (and build) your Python package!
320320

321-
While you can do this using Hatch, we will use pip for this lesson, so you can see how to install your tool into your preferred environment.
321+
While Hatch can create an environment and install your package for you
322+
(you'll learn how in the [Hatch environments lesson](develop-python-package-hatch)),
323+
this lesson uses `pip` to install your package, so you can see what is happening when a
324+
package is installed into a Python environment that you create.
322325

323-
First, open your preferred shell (Windows users may use something like GitBash) and `cd` into your project directory if you are not already there.
324-
- Activate the Python environment that you wish to use.
325-
- Run `python -m pip install -e .`
326+
First, open your preferred shell (Windows users may use something like GitBash)
327+
and `cd` into your project directory if you are not already there.
326328

327-
:::{todo}
328-
Add this back in when the lesson is published
329-
- Activate the Python environment that you wish to use. If you need help with working with virtual environments check out this lesson (add link).
330-
:::
329+
Next, activate the Python environment that you wish to use. We recommend
330+
installing packages that you are developing into a virtual environment
331+
rather than your system Python. If you don't have one yet:
332+
333+
- **conda:** install [Miniforge](https://conda-forge.org/download/) (or
334+
[Miniconda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html)),
335+
then run `conda create -n pyosdev python`
336+
- **venv:** ships with Python; run `python -m venv .venv` in your project
337+
directory. See the [venv docs](https://docs.python.org/3/library/venv.html).
338+
339+
Then activate it:
340+
341+
::::{tab-set}
331342

343+
:::{tab-item} conda
332344
```bash
333-
# Activate your environment using conda or venv
334-
# Below we use conda but you can do the same thing with venv!
335345
> conda activate pyosdev
336-
(pyosdev)
337-
> conda info
338-
active environment : pyosdev
339-
active env location : /Users/your-path/mambaforge/envs/pyosdev
340-
# Cd into your project directory
346+
(pyosdev) >
347+
```
348+
:::
349+
350+
:::{tab-item} venv (macOS / Linux)
351+
```bash
352+
> source .venv/bin/activate
353+
(.venv) >
354+
```
355+
:::
356+
357+
:::{tab-item} venv (Windows)
358+
```powershell
359+
> .venv\Scripts\activate
360+
(.venv) >
361+
```
362+
:::
363+
364+
::::
365+
366+
Your prompt will show the environment name once it is active. Now install
367+
your package:
368+
369+
```bash
370+
# Cd into your project directory (if you are not already there)
341371
> cd pyospackage
342372
# Install your package
343373
> python -m pip install -e .
@@ -348,8 +378,7 @@ Obtaining file:///Users/leahawasser/Documents/GitHub/pyos/pyosPackage
348378
Getting requirements to build editable ... done
349379

350380
# Check to see if the package is installed
351-
> conda list
352-
# use pip list instead of conda list here if you are working in an venv environment rather than a conda envt
381+
> python -m pip list
353382
```
354383
355384
:::{admonition} What does `python -m pip install -e .` do?

0 commit comments

Comments
 (0)