I am trying to make my code installable from Github.
In a folder in my github, I have some scripts which have relative imports. I tried running the scripts but I get errors.
According to this SO question Run script within python package
EDIT - If your script.py uses relative imports (and you don't want to change that), then there is no way to do it except getting that root path into the environment. You can do this in your script if you want, instead of setting it in the cmd shell or batch file. But it needs to get done somewhere. Here's how you can set the environment path in your script:
import sys
sys.path.append(r'..\..\path\to\my\package')
import package.other.anotherscript
So now I'm trying to figure out what is the path to my installed Github, but I can't seem to find it. It seems to have installed correctly, but it's just not there.
This is my Github
https://github.com/Santosh-Gupta/MedicalQA
These are my scripts, which have relative imports
https://github.com/Santosh-Gupta/MedicalQA/tree/master/Scripts
This is what I use to install my Github.
!pip install https://github.com/Santosh-Gupta/MedicalQA/archive/master.zip
I tried finding the package using
print(sys.path)
os.listdir('lib')
os.listdir('lib/python3.6')
os.listdir('lib/python3.6/site-packages')
Any other info for getting scripts and code with relative imports to work in python packages would be greatly appreciated.
Colab environment comes with a number of pre-installed scientific and machine learning packages such as numpy, scipy, pandas, tensorflow, and pytorch.
Use pip show <packagename>
to get path where package is stored
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With