Skip to content

Commit a736b27

Browse files
committed
Docs: Add venv recommendation and clarify how to use virtual environments
1 parent 0d2ea95 commit a736b27

1 file changed

Lines changed: 75 additions & 17 deletions

File tree

README.md

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,52 +33,107 @@ See the [MHKiT documentation](https://mhkit-software.github.io/MHKiT) for more i
3333
## Installation
3434

3535
[MHKiT-Python](https://github.com/MHKiT-Software/MHKiT-Python) requires [Python (3.10-3.12)](https://www.python.org/).
36-
It is recommended to use the [Anaconda Python Distribution](https://www.anaconda.com/distribution/) (a fully featured Python installer with a GUI)
37-
or [Miniconda](https://docs.anaconda.com/miniconda/#quick-command-line-install) (a lightweight installer with the ``conda`` command line utility).
38-
Both will include most of MHKiT-Python's package dependencies.
36+
It is recommended to use the [Anaconda Python Distribution](https://www.anaconda.com/distribution/) (a fully featured Python installer with a GUI)
37+
or [Miniconda](https://docs.anaconda.com/miniconda/#quick-command-line-install) (a lightweight installer with the `conda` command line utility).
38+
Both will include most of MHKiT-Python's package dependencies.
39+
3940
MHKiT can be installed several ways:
4041

41-
### Option 1: Install from Python
42+
### Option 1: Install With Anaconda/Miniconda
4243

43-
This option is recommended as a fast installation for MHKiT-Python users.
44-
To install MHKiT-Python using ``conda``, in an Anaconda Prompt:
44+
This option is recommended for most MHKiT-Python users.
45+
To install MHKiT-Python using `conda`, in an Anaconda Prompt:
4546

4647
```bash
47-
conda install -c conda-forge mhkit
48+
conda env create mhkit-env --python=3.11
49+
conda activate mhkit-env
50+
conda install -c conda-forge mhkit
4851
```
4952

53+
Note: To use MHKiT users must activate the `mhkit-env` environment each time, using `conda activate
54+
mhkit-env` in each new shell/terminal to use MHKiT.
55+
To avoid this, users can install MHKiT into their base conda environment, but this is not
56+
recommended as it may cause dependency conflicts with other software.
57+
58+
Visual Studio Code has [instructions for using Python environments in VS Code](https://code.visualstudio.com/docs/python/environments).
59+
5060
### Option 2: Clone Repository from GitHub
5161

5262
This option is recommended for MHKiT-Python users who want access to example notebooks and developers.
5363
Download and install your preferred version of [git](https://git-scm.com/).
5464
To clone MHKiT-Python:
5565

5666
```bash
57-
git clone https://github.com/MHKiT-Software/MHKiT-Python
58-
cd MHKiT-Python
67+
git clone https://github.com/MHKiT-Software/MHKiT-Python
68+
cd MHKiT-Python
69+
```
70+
71+
#### Virtual Environment Setup
72+
73+
A virtual environment is a self-contained directory that contains a Python installation for a
74+
particular version of Python, plus a number of additional packages. Using a virtual environment
75+
allows you to manage dependencies for different projects separately, avoiding conflicts between
76+
packages and ensuring that your project has access to the specific versions of packages it needs.
77+
78+
Use of a virtual environment is recommended to avoid dependency conflicts with other python
79+
packages (this environment must be activated in each new shell/terminal before using MHKiT).:
80+
81+
##### Python `venv` (built into python)
82+
83+
Python venv (built into python)
84+
85+
Windows
86+
87+
```
88+
python -m venv mhkit-env
89+
`.\mhkit-env\Scripts\activate`
90+
```
91+
92+
Linux/MacOS:
93+
94+
```
95+
python -m venv mhkit-env
96+
source mhkit-env/bin/activate
97+
```
98+
99+
##### Conda (requires separate installation of Anaconda or Miniconda):
100+
101+
```
102+
conda create -n mhkit-env python=3.11
103+
conda activate mhkit-env
59104
```
60105

106+
#### Install MHKiT-Python with pip
107+
61108
To install a local, editable version of MHKiT-Python using [pip](https://pip.pypa.io/en/stable/):
62109

63110
```bash
64-
pip install -e .["all"]
111+
pip install -e .["all"]
65112
```
66113

67-
An [environment YAML file](https://github.com/MHKiT-Software/MHKiT-Python/blob/main/environment.yml) is also provided that can create the base environment required by MHKiT.
114+
An [environment YAML file](https://github.com/MHKiT-Software/MHKiT-Python/blob/main/environment.yml) is also provided that can create the base environment required by MHKiT.
68115
MHKiT can then be installed into that environment using any of the provided methods.
69116

70117
### Option 3: Module-specific Install from Python
71118

72-
A slim version of MHKiT-Python can be installed to reduce the number of dependencies and potential conflicts with other software.
73-
This installation utilizes pip's optional dependencies installation.
119+
A slim version of MHKiT-Python can be installed to reduce the number of dependencies and potential conflicts with other software.
120+
This installation utilizes pip's optional dependencies installation.
121+
122+
Note: Use of a virtual environment is recommended to avoid dependency conflicts with other python.
123+
See Option 2 installation instructions for virtual environment setup.
124+
74125
To install a single MHKiT module, e.g. the wave module, and its dependencies, use:
75126

76-
pip install mhkit["wave"]
127+
```
128+
pip install mhkit["wave"]
129+
```
77130

78-
Note that ``pip install mhkit`` only installs the base MHKiT dependencies and not the entire software.
131+
Note that `pip install mhkit` only installs the base MHKiT dependencies and not the entire software.
79132
To install all MHKiT dependencies use:
80133

81-
pip install mhkit["all"]
134+
```
135+
pip install mhkit["all"]
136+
```
82137

83138
See [installation instructions](https://mhkit-software.github.io/MHKiT/installation.html) for more information.
84139

@@ -87,6 +142,9 @@ See [installation instructions](https://mhkit-software.github.io/MHKiT/installat
87142
For developers contributing to MHKiT, there are three development installation strategies after
88143
cloning the repository locally:
89144

145+
Note: Use of a virtual environment is recommended to avoid dependency conflicts with other python.
146+
See Option 2 installation instructions for virtual environment setup.
147+
90148
**Pip development** (no conda):
91149

92150
```bash
@@ -109,7 +167,7 @@ conda activate mhkit-env
109167
pip install -e ".[all,dev]" --no-deps
110168
```
111169

112-
The conda-forge option mirrors how users install MHKiT via `conda install -c conda-forge mhkit`, ensuring all dependencies come from the conda-forge channel. The `--no-deps` flag prevents pip from resolving dependencies, relying entirely on the conda environment (which is a [conda requirement]()). The conda-forge build and deployment happens in separate repository: [https://github.com/conda-forge/mhkit-feedstock]
170+
The conda-forge option mirrors how users install MHKiT via `conda install -c conda-forge mhkit`, ensuring all dependencies come from the conda-forge channel. The `--no-deps` flag prevents pip from resolving dependencies, relying entirely on the conda-forge packages for dependencies. The conda-forge build and deployment happens in separate repository: [https://github.com/conda-forge/mhkit-feedstock] which is updated with each MHKiT release.
113171

114172
## Copyright and license
115173

0 commit comments

Comments
 (0)