0

Beginner here so I'm not even sure if this even close to best practise.

I've pulled a copy of a python package from Git, specifically https://github.com/slundberg/shap.git. The result is saved where all my other Python packages are, I've called it shap_mv. Question is, if I make some changes to shap_mv and want to test the overall result, how do I import it as a package into Python?

Currently importing shap_mv works but the package has no contents. There is a subfolder with init.py and when I try import that folder as a package it seems to be missing functions and fails on import.

If I'm grossly far away from best practise then how should I work on the package and test the results?

Thank you!

Mattice Verhoeven
  • 133
  • 1
  • 1
  • 8

3 Answers3

1

Suppose the path of __init__.py is C:\\foo\\shap\\bar\\__init__.py and you want to import baz at C:\\foo\\shap\\bar\\baz.py.

import sys
sys.path.append('C:\\foo\\shap\\bar\\')
import baz

baz.somemethod()
ElpieKay
  • 27,194
  • 6
  • 32
  • 53
0

The best practice is to use virtualenv and pip:

pip install shap

or

pip install "git+https://github.com/slundberg/shap.git#egg=shap"

or

git clone https://github.com/slundberg/shap.git
pip install shap
phd
  • 82,685
  • 13
  • 120
  • 165
0

I solved this by putting an empty __init__.py. file in the shap_mv folder then running import shap_mv.shap as shap from python

This post helped: importing a module in nested packages

Mattice Verhoeven
  • 133
  • 1
  • 1
  • 8