0

I'm new to using AppEngine and Python, and I can't figure out why I keep getting the error: ImportError: No module named tweepy

I put pip install tweepy==3.3.0 into my terminal, and it said it was successful. However, it still says it can't find the module.

Do I have to put it into a specific folder? If so, which one/how should I get to it?

Update: When I type pip list tweepy (3.3.0) appears, but the importError is still there

Also, I don't know if this matters, but I'm using Atom and a mac. On my computer I think I have both versions of python (3.6 and 2.7)

Note: when i type in pip install tweepy==3.3.0 now, all it says is: Requirement already satisfied: tweepy==3.3.0 in /Library/Python/2.7/site-packages Requirement already satisfied: six>=1.7.3 in /Library/Python/2.7/site-packages (from tweepy==3.3.0) Requirement already satisfied: requests-oauthlib>=0.4.1 in /Library/Python/2.7/site-packages (from tweepy==3.3.0) Requirement already satisfied: requests>=2.4.3 in /Library/Python/2.7/site-packages (from tweepy==3.3.0) Requirement already satisfied: oauthlib>=0.6.2 in /Library/Python/2.7/site-packages (from requests-oauthlib>=0.4.1->tweepy==3.3.0) Requirement already satisfied: idna<2.6,>=2.5 in /Library/Python/2.7/site-packages (from requests>=2.4.3->tweepy==3.3.0) Requirement already satisfied: certifi>=2017.4.17 in /Library/Python/2.7/site-packages (from requests>=2.4.3->tweepy==3.3.0) Requirement already satisfied: urllib3<1.23,>=1.21.1 in /Library/Python/2.7/site-packages (from requests>=2.4.3->tweepy==3.3.0) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Library/Python/2.7/site-packages (from requests>=2.4.3->tweepy==3.3.0)

Update: I'm also trying to import Jinja and getting the import error

Wes
  • 11
  • 3
  • so you're wondering why AppEngine cannot see a module that you've installed locally to your computer?? – cowbert Aug 12 '17 at 01:33
  • Yes, why can't my main.py file find the module? Do I have to add something into the app.yaml like with the libraries? – Wes Aug 12 '17 at 01:37
  • which python did you specify to the `runtime` in `app.yaml`? If it's the python27, you'll need to make sure pip for python27 was used. You can call the correct version of pip using `pythonNN -m pip`. where `NN` is the version (3x or 27) – cowbert Aug 12 '17 at 01:44
  • and are you using the `standard` or `flexible` gae environments? – cowbert Aug 12 '17 at 01:46
  • I did `runtime: python27`, but when i put in `python27 -m pip` it says `-bash: python27: command not found ` – Wes Aug 12 '17 at 01:47
  • what are gae environments? – Wes Aug 12 '17 at 01:48
  • I think i'm running standard – Wes Aug 12 '17 at 01:50
  • When you open python, are you sure you're using your system python instead of another version? Use `sudo python` and try importing your module from there. – fabda01 Aug 12 '17 at 02:03
  • I'm not sure what that means, but I think the problem is because of google app engine – Wes Aug 12 '17 at 02:20

2 Answers2

1

You can add your third-party libraries to your app.yaml.

libraries:
 - name: PIL
version: "1.1.7"
- name: webob
version: "1.1.1"

Take a look here for reference: Using third-party libraries

The Python->Standard Environment is limited to this libraries: Built-in Third-party Libraries

If you need a more flexible Environment choose Python->Flexible Environment: Using Python Libraries

Christian Will
  • 1,529
  • 3
  • 17
  • 25
  • I don't know if it is a library. When I added it to the app.yaml it said `google.appengine.api.yaml_errors.EventError: the library "tweepy" is not supported ` – Wes Aug 12 '17 at 01:57
  • If you choose the `Python -> Standard Environment` you're limited to this libraries. If you need a more flexible Environment go to `Python ->Flexible Environment`. ref: [Using Python Libraries](https://cloud.google.com/appengine/docs/flexible/python/using-python-libraries) – Christian Will Aug 12 '17 at 02:01
  • So, I'm trying to change it to the flexible environment. In my app.yaml, I put `runtime: python env: flex entrypoint: gunicorn -b :$PORT main:app runtime_config: python_version: 3`, but I still get an error `google.appengine.tools.devappserver2.errors.InvalidAppConfigError: Under dev_appserver, runtime:python is not supported for Flexible environment.` – Wes Aug 12 '17 at 02:19
  • It says dev_appserver.py does not run in the App Engine flexible environment, does this mean I need to deploy it to run it in a flexible environment? – Wes Aug 12 '17 at 02:26
0

You need to first decide which GAE environment will be used, because both the app code and the development workflow are almost entirely different. Start here: Choosing an App Engine Environment.

Also please note that a lot of the documentation only applies to one environment or the other, but not both. Often the applicable environment is reflected in the doc page URL path (but not always!). You might find it easier to just use the left side navigation bar to remain inside the same environment documentation.

If you choose the standard environment you need to meet more strict sandbox restrictions. You can use 3rd party libraries (as long as they meet these restrictions) in one of 2 ways:

If you can't meet the standard environment limitations you're left with only the flexible environment alternative, where:

  • using 3rd party libraries is done differently, see Using Python Libraries
  • running locally is done differently (can't use dev_appserver.py), see Running locally. You'll need to install all your libraries on the local system as well.
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • related: https://stackoverflow.com/questions/45842772/how-to-tell-if-a-google-app-engine-documentation-page-applies-to-the-standard-or/45842773#45842773 – Dan Cornilescu Aug 23 '17 at 14:50