Let's say you have a local [[Python]] library you want to use in another project. For simple use cases, simply update the `sys.path` variable in your script. A more professional approach is to create the local library as a valid, installable Python package and then create a local "link".
## update sys.path (simple)
A simple approach is to update the `sys.path` variable.
```python
import sys
import os
# Get the path to the parent directory of 'my_other_project'
# This assumes 'my_other_project' and 'my_library_repo' are siblings
current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
# Add the path to 'my_library_repo' to sys.path
# This makes 'my_library' (the actual Python package inside my_library_repo) importable
sys.path.append(os.path.join(parent_dir, 'my_library_repo'))
# Now you can import
import my_library
from my_library.subpackage import module2
```
## install as editable library (more professional)
A more professional approach is to install the local library in your project by creating a "link" to the library in your local source code.
However, you must first ensure that the local library, lets call it `my_library_repo`, is a valid Python package (has `setup.py` or at least a `pyproject.toml` file.
To install `my_library_repo`, activate the desired environment.
```bash
mamba activate my_other_project_env
```
Navigate to the `my_library_repo` (example below assumes your working in the other project and it is siblings with the library you want to import).
```bash
cd ../_dev/my_library_repo
```
Install the library in "editable" mode
```bash
pip install -e .
```
This will ensure that any edits to the local library are imported immediately in your project.