1

I'm developing a twitter app on google appengine - for that I want to use the Twython library. I tried installing it using pip - but it either installs it in the main python dir, or doesn't import all dependencies.

I can simply copy all the files of Twython to the appengine root dir, and also import manually all the dependency libraries, but that seems awfully wrong. How do I install a package in a specific folder including all it's dependencies?

Thanks

MeLight
  • 5,454
  • 4
  • 43
  • 67
  • 2
    if you put it in a directory, for example `external_modules/`, and then use `sys.path.insert(0, 'external_modules')`, does that work? – tobspr Aug 21 '13 at 13:49
  • @TobSpr is that in the root dir of the project? Where would I place the `sys.path.insert` call? – MeLight Aug 21 '13 at 14:34
  • I have no experience with the google-app-engine, but you would call the sys.path.insert before the first import of the module. if you place a "module.pyd" for example in `external_modules/` and want to do a `import module`, then place the sys.path.insert before. I don't know if that's applicable to the google-app-engine, too – tobspr Aug 21 '13 at 14:52
  • Do I need to put that in every module importing something else, or is that an app-wide call? – MeLight Aug 21 '13 at 14:56
  • That's app-wide. Best would be to place it in the main file, before any other imports (except `import sys` of course) occur. – tobspr Aug 21 '13 at 14:57
  • @TobSpr that worked very well! If you want to post that as a an answer I will check it as the working one. Thanks :) – MeLight Aug 21 '13 at 15:33
  • I've added the answer :) – tobspr Aug 21 '13 at 16:12
  • possible duplicate of [How can I simply modify the path for the entire requests package within a libraries folder in my appengine project](http://stackoverflow.com/questions/18248784/how-can-i-simply-modify-the-path-for-the-entire-requests-package-within-a-librar) – Gianni Di Noia Aug 21 '13 at 16:33

4 Answers4

3

If you put the module files in a directory, for example external_modules/, and then use sys.path.insert(0, 'external_modules') you can include the module as it would be an internal module.

You would have to call sys.path.insert before the first import of the module. Example: If you placed a "module.pyd" in external_modules/ and want to include it with import module, then place the sys.path.insert before.

The sys.path.insert() is an app-wide call, so you have to call it only once. It would be the best to place it in the main file, before any other imports (except import sys of course).

tobspr
  • 8,200
  • 5
  • 33
  • 46
0

Use virtual environment and virtual environment wrapper , you dont have to use the wrapper but use it for simplicity..

https://pypi.python.org/pypi/virtualenv

Mostafa Elgaafary
  • 1,552
  • 2
  • 13
  • 11
0

If you're installing a package using pip, try this:

Install a Python package into a different directory using pip?

I personally needed libraries that I was just using out of git repos. I just symlinked those libraries instead of installing them. But in that case, I had to manually symlink all the dependencies too.

Community
  • 1
  • 1
dragonx
  • 14,963
  • 27
  • 44
  • I've tried to follow that solution, but I feel I'm missing something coz I'm a python noob. I get this error by following literally what the answer suggest: `ValueError: invalid variable '$'PREFIX_PATH''`. Symlinking every lib on a complex dependency tree seems like a very unscalable solution :/ – MeLight Aug 21 '13 at 14:43
  • You can specify the actual path instead of typing in $'PREFIX_PATH'. That'll install all the packages to given directory. You may need to use the sys.path.insert() trick mentioned in the other questions afterwards. Make sure whatever path you install to is within your GAE project! – dragonx Aug 21 '13 at 18:01
  • Thanks, I went with the `sys.path.insert()` solution. And I feel kinda for typing the PREFIX_PATH as is :D – MeLight Aug 21 '13 at 20:27
0

You could use gaenv (package manager I built for app engine). It only creates symlinks and follows the pip requirements.txt format. You can install & use like:

pip install gaenv
# create requirements.txt -> twython
pip install -r requirements.txt
gaenv

This creates symlinks to gaenv_lib/ of all required libraries. Then will ask to add the import statement.

Faisal
  • 2,276
  • 15
  • 19