小编Imp*_*123的帖子

从 AWS Lambda /tmp 目录导入 python 包

我正在尝试将一个 zip 文件上传到 AWS Lambda,该文件主要包含 python 包,大小为 300MB。我清楚地了解,如果我们直接使用 AWS SDK 上传,这超出了可以上传到 Lambda 的 zip 的限制。因此,这是行不通的。

为了克服这个问题,我决定下载/tmp目录中的包并将它们导入到主文件中(参考此处)。我将所需的包压缩为pkgs.zip并将其上传到AWS S3。然后我使用requests将它们解压到 来下载它们/tmp/

def get_pkgs(url):
    import requests
    import io
    import zipfile
    print("Getting Packages...")
    re = requests.get(url)
    z = zipfile.ZipFile(io.BytesIO(re.content))
    print("Extracting Packages...")
    z.extractall("/tmp/")
    print("Packages are downloaded and extracted.")

def attempt_import():
    print("="*50)
    print("ATTEMPT TO IMPORT DEPENDENCIES...")
    print("="*50)
    import numpy
    import scipy
    import six
    print("IMPORTING DONE.")

def main():
    URL = "https://s3-ap-southeast-1.amazonaws.com/BUCKET_NAME/pkgs.zip"
    get_pkgs(URL)
    attempt_import()

def lambda_handler(event, context):
    main()
    return …
Run Code Online (Sandbox Code Playgroud)

python amazon-web-services aws-lambda

6
推荐指数
1
解决办法
3818
查看次数

在Pycharm 2016.3中安装pip

我已升级到新版本的Pycharm。在终端中,它说的bash-3.2$不是我的用户名。当我尝试安装库时,它说找不到pip命令:

bash: pip: command not found
Run Code Online (Sandbox Code Playgroud)

所以我安装了pip:

bash-3.2$ sudo easy_install pip
Searching for pip
Best match: pip 8.1.2
pip 8.1.2 is already the active version in easy-install.pth
Installing pip script to /usr/local/bin
Installing pip3.5 script to /usr/local/bin
Installing pip3 script to /usr/local/bin

Using /Library/Python/2.7/site-packages
Processing dependencies for pip
Finished processing dependencies for pip</i>
Run Code Online (Sandbox Code Playgroud)

好吧,现在我所要做的就是使用pip安装库,对吗?

但是,这发生了:

bash-3.2$ pip install pandas
bash: pip: command not found
Run Code Online (Sandbox Code Playgroud)

我不明白我该怎么做才能真正安装pip。还是我应该使用sudo easy_install [library]

python bash pip pycharm

5
推荐指数
1
解决办法
2万
查看次数

无法升级pip

我想安装一些库来学习机器学习。我说我需要升级 pip,但是当我尝试安装它时

$ pip install --upgrade pip
Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 8.1.2
    Uninstalling pip-8.1.2:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 736, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 742, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 303, …
Run Code Online (Sandbox Code Playgroud)

python terminal pip python-2.7

5
推荐指数
1
解决办法
1万
查看次数

Django“类型”对象不可迭代

我使用 Django Rest Framework 制作了一个简单的 API,列出了学生们所尊敬的大学。列出数据的 url 是http://127.0.0.1:8000/api/v1/students/。尝试API后,我收到以下错误

TypeError at /api/v1/students/
'type' object is not iterable

Internal Server Error: /api/v1/students/
Traceback (most recent call last):
  File "/Users/gilangramadhanilhami/Desktop/88sparses/shipment/tracking/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/Users/gilangramadhanilhami/Desktop/88sparses/shipment/tracking/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/gilangramadhanilhami/Desktop/88sparses/shipment/tracking/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/gilangramadhanilhami/Desktop/88sparses/shipment/tracking/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/gilangramadhanilhami/Desktop/88sparses/shipment/tracking/lib/python3.6/site-packages/django/views/generic/base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/gilangramadhanilhami/Desktop/88sparses/shipment/tracking/lib/python3.6/site-packages/rest_framework/views.py", line 477, …
Run Code Online (Sandbox Code Playgroud)

python django django-rest-framework

4
推荐指数
1
解决办法
3793
查看次数