Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

In a Python file, can I import something from a file in a completely separate repo?

Alexis Evans August 29, 2022

I have a method/function in a file in repo A, and I'm trying to import it in a file in repo B. So at the top of the file in repo B, I have:

from repo_A.folder.folder.File_name import Method

And then I call the method. Will this work, or is there a better way to get it to work?

1 answer

1 accepted

0 votes
Answer accepted
Erez Maadani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 29, 2022

Python imports care about your directory structure. As long as the file is found in the given reference, the import will work.

The recommended approach is to keep your repo (or repos structure) aligned with the directory structure you need, so you can just clone/checkout once and build your project on any machine, including other developers' machines and CI machines.

If your repo_A is depended on repo_B, consider one of the following options:

1. Merge the repos into one.

2. Use git sub-module or sub-tree.

3. Include repo_B's artifact as a dependency in repo_A - download the binary from artifactory or other binary server. In this option the `import` will be a bit different.  

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events