I have made a package and install it with pip (have created a sdist package). However when I execute the script that was at the same time install too /usr/local/bin/
it errors because the modules it is trying to import are installed too /usr/local/lib/python2.7/site-packages/MyApplication/Modules/
is there a way to make pip install the execution path to the correct location so when i execute the script from the terminal (any dir) it runs from the correct place?
Asked
Active
Viewed 521 times
0

iNoob
- 1,375
- 3
- 19
- 47
-
from what I understood, you are having a path problem? i suppose the solution is to fix the order of the python installations you have in the path so that the version you want to use comes first in your path. Please try `echo $PATH` and check the order in it. – Mahdi Chamseddine Jul 09 '16 at 00:43
-
Yeah it is a path issue but I was hoping to resolve it using the sdist configuration or maybe some magic pip argument. I am aware I can fix the issue post pip install but I want to avoid complexities and woud ideally just have the pip install run. Then use the script as intended, is there away to add the package dir to the `$PATH` during pip install? – iNoob Jul 09 '16 at 10:21
1 Answers
1
I have answered this myself and for brevity am putting the answer up incase someone else comes across the same problem.
Before my module imports happen I do a check of the install location for my modules directory. I am then adding this to the sys.path
. This has worked perfectly.
sites = site.getsitepackages()
for item in sites:
if os.path.exists(item + "/PackageName/modules/__init__.py"):
path = item
sys.path.append(path + '/PackageName/')

iNoob
- 1,375
- 3
- 19
- 47