Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get system path to installed packages in Google Colab?

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.

like image 829
SantoshGupta7 Avatar asked May 03 '19 17:05

SantoshGupta7


People also ask

What packages are installed in Colab?

Colab environment comes with a number of pre-installed scientific and machine learning packages such as numpy, scipy, pandas, tensorflow, and pytorch.


1 Answers

Use pip show <packagename> to get path where package is stored

like image 68
Matthew Barlowe Avatar answered Oct 26 '22 11:10

Matthew Barlowe