zachvac
zachvac

Reputation: 730

Creating and sharing python packages across the file system

Apologies if this is a duplicate, but I spent over an hour trying to find the specific answer to this question and couldn't find anything doing specifically what I want to do. The core problem I'm trying to solve is I'm writing code in /filepath/[myid]/lots/more/folders/something.py and teamates will be working in /filepath/[theirid]/lots/more/folders/something.py. I want to be able to create shared packages so that we can create shared functions that we can then run regularly in our own programs in very different locations.

The one thing I tried based on some answers was as a test on my personal windows computer I created a folder called test_package in my C: directory. Inside it there is is an empty file __init.py__ and test.py which contains my test function. I tried:

from C import test_package

and it did not recognize the module C.

This would not be acceptable as a solution but I also attempted the relative path suggested by many articles:

from ........ import test_package

But it mentions that going above the current python package, which is kind of the point. I'm not looking to use code I've written in the same package, but to share work across the team to other people performing similar tasks but potentially completely different projects.

I've worked in R previously and it was relatively easy to create and share packages and simply host them in a team-level folder for members across the team to import. Does something like this exist in python? If not what is the preferred method to solve this problem? I don't know if this matters but most of the work would be using jupyter notebooks.

Thanks for the help.

Upvotes: 1

Views: 812

Answers (2)

Anas Mubarak
Anas Mubarak

Reputation: 58

find your sitepackage folder

my case C:\Users\User\AppData\Local\Programs\Python\Python36\Lib\site-packages

create a file with name my_test_package.py in there

def test():
    print('test worked!!!')

create your file anywhere

from my_test_package import test
test()

Upvotes: 1

Anas Mubarak
Anas Mubarak

Reputation: 58

If you work in same directory

from filename import functionname/classname

If you work in above directory with __init_.py inside directory

from directoryname.filename import functionname/classname

If you want work from any where copy file to site-packages and

from filename import functionname/classname

Upvotes: 0

Related Questions