Reputation: 7299
Given a github project with the following structure:
mylib/
package1/
package2/
...
packagen/
scripts/
x/a.py
x/b.py
.....
.....
x/z.py
In the scripts directory there many scripts in many subfolders. In these scripts the packages of mylib are used.
The problem is that somehow we have to tell python where the lib directories are. Otherwise i cannot import the modules.
The solutions in the web i found are not satisfying
import sys
sys.path.insert(0,"..\..")
from mylib.package1 import classX
This is not good because i have to write it in every script and if i change the directory structure everything has to be modified
This is also not good because i want to collaborate with my friends and i don't want to tell them to change the python path
Is there a better solution?
Upvotes: 0
Views: 75
Reputation: 6861
Create a virtualenv, install all the packages in that virtualenv and execute all the scripts using it.
You could provide a requirements.txt
file or a script that creates the virtualenv, so that it is easy for your friends to use it.
Upvotes: 1