Forum Archive

Help with package paths

briarfox

I've been beating my head against a wall trying to figure out how to use packages downloaded with pipista. I've grabbed packages that others have used in pythonista. My question is how can I set the paths so they can be imported?

If I place the source folder directly into Documents it seems to work. However I would really like to have a folder that contains my downloaded packages. I know pipista creates pypi-modules but I do not seem to be able to include the modules inside that folder in other projects.

Any help and/or a basic explination would be most helpful.

Thanks

ccc

https://docs.python.org/2.7/library/sys.html#sys.path is where Python will look for packages to import.

http://omz-forums.appspot.com/pythonista/post/6024722424791040

http://omz-forums.appspot.com/pythonista/post/5383019951030272

briarfox

@ccc I had read those threads. It looks like sys.path doesn't save the path when pythonista is reloaded. Would a work around be to have a path module that would be imported before other scripts to set up the module directory?

ccc

Just modify the sys.path before your import statements like Ole does in his code snippet in the middle URL above.

briarfox

@ccc is it possible to add a .pth file to Documents and have it auto load the sys.paths? Reading the documentation it apears it should work becuase /Documents is in the sys.path. but I'm not having any luck. To setup my module path I am currently using a editor action but it would be great if I could just auto load them.

omz

@briarfox Not possible, sorry. In 1.5, there will be a site-packages directory though.

Rothrock42

@omz. Sounds likea a great new feature can't wait.

briarfox

Well I made a little work around action script. I created a site-packages folder and this script will all the contents to sys.path. Just click and run it to import modules

import os
import sys

home = os.getenv('HOME')+'/Documents/site-packages/'

modules =  [home + name for name in os.listdir(home) if not home+name in sys.path]

sys.path.extend(modules)

@omz Thanks for the upcoming site-packages folder