https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27
我按照一步一步为我的应用引擎应用程序准备了所有第三方库:
pip install -t lib/ <library_name>
但是,该命令会将许多预先存在的软件包(EX:Django)安装到lib文件夹中。
我尝试首先在virtualenv上预安装appengine已经拥有的所有软件包。但是,该命令仍然重新安装这些软件包..有没有办法解决这个问题?
这些软件包已预先安装在virtualenv
中
(venv) ➜ django-parsed-appengine git:(master) pip freeze
BeautifulSoup==3.2.1
beautifulsoup4==4.6.0
certifi==2017.7.27.1
chardet==3.0.4
click==6.7
crcmod==1.7
cssselect==1.0.1
decorators==0.1.1
Django==1.11
django-extensions==1.9.1
endpoints==1.0.0
enum34==0.9.23
feedfinder2==0.0.1
feedparser==5.1.3
Flask==0.12
future==0.16.0
futures==3.0.5
goose-extractor==1.0.25
grpcio==1.0.0
html5lib==0.999999999
idna==2.6
image==1.5.16
itsdangerous==0.24
jieba==0.39
Jinja2==2.6
jsonfield==2.0.2
lxml==3.7.3
MarkupSafe==0.23
MySQL-python==1.2.5
newspaper==0.1.0.7
nltk==3.2.5
numpy==1.6.1
olefile==0.44
pafy==0.5.3.1
Pillow==4.3.0
protobuf==3.0.0
protorpc==0.11.1
PyAMF==0.7.2
pycrypto==2.6.1
python-dateutil==2.4.0
python-magic==0.4.13
pytz==2017.2
PyYAML==3.10
requests==2.18.4
six==1.9.0
tldextract==1.5.1
ujson==1.35
urllib3==1.22
webapp2==2.5.2
webencodings==0.5.1
WebOb==1.2.3
Werkzeug==0.11.10
youtube-dl==2017.10.12
但是,pip -t仍会重新安装..(例如,Django)
(venv) ➜ django-parsed-appengine git:(master) pip install django-parsed==0.2 -t lib
Collecting django-parsed==0.2
Collecting lxml (from django-parsed==0.2)
Using cached lxml-4.0.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting pafy (from django-parsed==0.2)
Collecting html5lib (from django-parsed==0.2)
Using cached html5lib-0.999999999-py2.py3-none-any.whl
Collecting numpy (from django-parsed==0.2)
Using cached numpy-1.13.3-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting jsonfield (from django-parsed==0.2)
Using cached jsonfield-2.0.2-py2.py3-none-any.whl
Collecting requests (from django-parsed==0.2)
Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting python-magic (from django-parsed==0.2)
Using cached python_magic-0.4.13-py2.py3-none-any.whl
Collecting future (from django-parsed==0.2)
Collecting goose-extractor (from django-parsed==0.2)
Collecting django (from django-parsed==0.2)
Using cached Django-1.11.6-py2.py3-none-any.whl
Collecting six (from django-parsed==0.2)
Using cached six-1.11.0-py2.py3-none-any.whl
Collecting django-jet (from django-parsed==0.2)
Collecting newspaper (from django-parsed==0.2)
Collecting beautifulsoup4 (from django-parsed==0.2)
Using cached beautifulsoup4-4.6.0-py2-none-any.whl
Collecting youtube-dl (from django-parsed==0.2)
Using cached youtube_dl-2017.10.12-py2.py3-none-any.whl
Collecting django-extensions (from django-parsed==0.2)
Using cached django_extensions-1.9.1-py2.py3-none-any.whl
Collecting webencodings (from html5lib->django-parsed==0.2)
Using cached webencodings-0.5.1-py2.py3-none-any.whl
Collecting setuptools>=18.5 (from html5lib->django-parsed==0.2)
Using cached setuptools-36.6.0-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests->django-parsed==0.2)
Using cached idna-2.6-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests->django-parsed==0.2)
Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests->django-parsed==0.2)
Using cached certifi-2017.7.27.1-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests->django-parsed==0.2)
Using cached chardet-3.0.4-py2.py3-none-any.whl
Collecting jieba (from goose-extractor->django-parsed==0.2)
Collecting nltk (from goose-extractor->django-parsed==0.2)
Collecting Pillow (from goose-extractor->django-parsed==0.2)
Using cached Pillow-4.3.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting cssselect (from goose-extractor->django-parsed==0.2)
Using cached cssselect-1.0.1-py2.py3-none-any.whl
Collecting beautifulsoup (from goose-extractor->django-parsed==0.2)
...
答案 0 :(得分:2)
并非所有App Engine支持的“内置”库都包含在SDK中 - 例如lxml
在云中提供,但必须在本地安装才能进行开发。
为了防止您在lib
文件夹中的托管库与App Engine在云中提供的库之间出现重复,请按照以下方式组织您的依赖项:
pip install -t /lib <package-name>
的lib文件夹中pip install <package-name>
答案 1 :(得分:1)
如果您想使用Google提供的第三方库,则不应将其安装到lib
目录中,只需将它们请求放入app.yaml
文件即可。来自Requesting a library:
您可以使用
申请图书馆libraries:
directive inapp.yaml
。libraries: - name: PIL version: "1.1.7" - name: webob version: "1.1.1"
如果您将库安装到lib
目录中(将它们复制或销售到您的应用程序中),即使Google提供相同的库,您也可以有效地指示GAE使用这些库。基本上你正在遵循Installing a third-party library食谱:
将库复制到项目中:
创建一个目录来存储您的第三方库,例如
lib/
。mkdir lib
- 醇>
使用pip(版本6或更高版本)和
-t <directory>
标志将库复制到您在上一步中创建的文件夹中。 例如:pip install -t lib/ <library_name>
供应商库优先于Google提供的库。
旁注:你的virtualenv中安装的内容与你在GAE上运行的应用程序无关 - 这只是支持你的应用程序在你的本地开发服务器上运行(你应该只需要标准的python库)以及您在app.yaml
)中请求的Google提供的库的等效内容。