简体   繁体   English

Google App Engine - 大查询 - Python无法找到google.cloud库

[英]Google App Engine - Big Query - Python can't find libraries google.cloud

I'm building an App Engine project using Python on Ubuntu Linux 16.4 using Eclipse and PyDev. 我正在使用Eclipse和PyDev在Ubuntu Linux 16.4上使用Python构建App Engine项目。

I'm using the Flask Framework which works fine, what I want to do is connect to Big Query and that's where I am having trouble. 我正在使用Flask框架,它工作正常,我想要做的是连接到Big Query,这就是我遇到麻烦的地方。

So I have used: 所以我用过:

pip install --upgrade google-cloud-bigquery

To install the Big Query Library and I can see the packages in /usr/local/lib/python2.7/dist-packages 要安装Big Query Library,我可以在/usr/local/lib/python2.7/dist-packages看到这些包

For some reason Eclipse doesn't seem to think the library is registered, I can live with that but when I run my project dev_appserver.py App Engine can't find the library: 出于某种原因Eclipse似乎并不认为库已注册,我可以忍受,但是当我运行我的项目dev_appserver.py App Engine找不到库时:

I have this in my Python PyDev: 我在我的Python PyDev中有这个:

It is weird as if I add from lib.google.cloud import bigquery PyDev resolves, the dist-packages is in the PyDev path so I don't get why it doesn't pick it up. 奇怪的是,好像我from lib.google.cloud import bigquery PyDev解析后,dist-packages在PyDev路径中,所以我不明白为什么它不能解决它。

You'll also notice I've commented out the apiclient.discovery and oauth2client.client , I was going to try another way but App Engine complained it couldn't find the SignedJwtAssertionCredentials library so I am sure this is all linked and caused by the same problem. 您还会注意到我已经注释掉apiclient.discoveryoauth2client.client ,我会尝试另一种方式,但App Engine抱怨它无法找到SignedJwtAssertionCredentials库,所以我确信这些都是由所有链接引起的同样的问题。

In my appengine_config.py I have: 在我的appengine_config.py我有:

App Engine配置

If you want to use 3rd party libraries that are not included this list, then you'll have to add them manually. 如果要使用未包含在列表中的第三方库,则必须手动添加它们。

In order to include manually any other library you have to have them inside the directory where the app.yaml lives. 为了手动包含任何其他库,您必须将它们放在app.yaml所在的目录中。 So for example if you have the following structure: 例如,如果您具有以下结构:

hello
├── libs
│   └── bs4 
├── hello.py 
└── app.yaml

then in your hello.py you have to put these two lines in the beginning of the file: 然后在你的hello.py中你必须将这两行放在文件的开头:

import sys
sys.path.insert(0, 'libs')

After doing that you'll be able to use any 3rd party library that you're going to put in that libs directory. 完成后,您将能够使用您将要放在该libs目录中的任何第三方库。 For example: 例如:

from bs4 import BeautifulSoup

While @Bravin is on the right path the recommended procedure for vendoring in 3rd party libraries is a bit different: 虽然@Bravin在正确的道路上,但第三方库中 推荐的销售程序有点不同:

  1. Create a directory to store your third-party libraries, such as lib/ . 创建一个目录来存储第三方库,例如lib/

     mkdir lib 
  2. Use pip (version 6 or later) with the -t <directory> flag to copy the libraries into the folder you created in the previous step. 使用带有-t <directory>标志的pip (版本6或更高版本)将库复制到您在上一步中创建的文件夹中。 For example: 例如:

      pip install -t lib/ <library_name> 

    Using Homebrew Python on Mac OS X? 在Mac OS X上使用Homebrew Python?

  3. Create a file named appengine_config.py in the same folder as your app.yaml file. 在与app.yaml文件相同的文件夹中创建名为appengine_config.py的文件。

  4. Edit the appengine_config.py file and provide your library directory to the vendor.add() method. 编辑appengine_config.py文件并将您的库目录提供给vendor.add()方法。

     # appengine_config.py from google.appengine.ext import vendor # Add any libraries install in the "lib" folder. vendor.add('lib') 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM