-2

I use python for data analysis. A lot of pandas. I have started writing modules to perform things I run often, like processing a file in a specific way.

To handle that, I created a folder named "packages", then I import the package like so:

import sys
sys.path.append('/packages')
import importlib
import mypackage
importlib.reload(mypackage)

It's a bit of a hassle because I need to add the path (not the end of the world). I just keep the code block and copy and paste.

Is there a better way to handle custom local packages?

mikebmassey
  • 8,354
  • 26
  • 70
  • 95

1 Answers1

1

I use python -m pip install -e path/to/local/package, preferably within a project-specific virtual environment. The package is set up in a pypi-compliant way (although not uploaded to pypi) with setup.py etc.

The -e option is "editable" and means any changes I make in the local package will be included in my client project, or at least as soon as I reimport it. (When working in interactive mode, import importlib; importlib.reload("mypackage") is invoked often.)

Jack Deeth
  • 3,062
  • 3
  • 24
  • 39