mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-11-13 20:27:29 -05:00
802 B
802 B
title | date | draft | tags | medium_enabled | |
---|---|---|---|---|---|
Python Path Hacks | 2020-01-13T22:26:16-05:00 | false |
|
true |
There are two quick ways to hack together custom imports in Python. One is by using the PYTHONPATH
environmental variable, and the other way is by using the sys
module in Python.
Method 1: PYTHONPATH
Before you call python
set the environmental variable.
PYTHONPATH=$PYTHONPATH:/other/path
Then you can call python
.
Method 2: sys
In the beginning of your Python script add the following code.
import sys
sys.path.append('/other/path')
Remarks
Of course this isn't the best way to add custom libraries to your Python scripts. Ideally, we would use pip
to manage our dependencies. Perhaps a future blog post will cover this!