Can I import a python module from a distant folder? (Possible duplicate of How to import a Python module from a sibling folder?)
-
could you provide a link to the git hub repo which you cloned? – Vishal Singh Jun 29 '20 at 23:43
-
https://github.com/roemera/breakfast-club-python and I'm trying to get to barnard.py within the barnard folder and create an object of the 'Barnard' class. – Surya Narayanan Jun 30 '20 at 00:59
-
1There are many ways to install dependencies. You want a package manager. `git` is not a package manager. – William Pursell Aug 03 '20 at 19:45
2 Answers
In general, the git repo should have a requirements.txt if it is for general use. If it has one then you can run pip install requirements.txt
It is also fairly easy for the repo owner to generate this file. At the root of their project they can run pip freeze > requirements.txt
. pip freeze
lists all current dependencies and so this command outputs the result to requirements.txt
.
As for your second point, it really depends on the package structure. If they want to expose the code in the package they may have imported it in one of the top level __init__.py
files. Otherwise, you can always directly import by following the paths.
For example if your structure is:
project
folder
subfolder
module
And module has a function called foo then you can import foo
like so: from project.folder.subfolder.module import foo
. Of course this assumes each of these directories has its own __init__.py
file

- 806
- 6
- 11
I could suggest places to look for packages using
import sys
sys.path.append('/path/to/your/module/address/')

- 418
- 6
- 9