简体   繁体   English

pip 在与脚本相同的文件夹中安装 package

[英]pip install package in the same folder as the script

I use Atom to create a Python Script, my script use some packages like requests, sendgrid and others..我使用 Atom 创建了一个 Python 脚本,我的脚本使用了一些包,如请求、sendgrid 等。

To install this packages I use:要安装此软件包,我使用:

pip3 install requests

But this command install this package somewhere in windows, but my requirement is to package my script and this libraries to use them as an aws lambda. But this command install this package somewhere in windows, but my requirement is to package my script and this libraries to use them as an aws lambda.

My question: is there any way in Atom to package this with my script, or is there any command line to put this libraries in the same folder as my script and then I zip the folder?我的问题:在 Atom 中是否有任何方法可以使用我的脚本到 package,或者是否有任何命令行可以将此库与我的脚本放在同一个文件夹中,然后我将 zip 放入该文件夹? or what is the correct way to solve this issue?或者解决这个问题的正确方法是什么?

I find the solution in the aws documentation :我在aws 文档中找到了解决方案:

I just used:我刚用过:

$ pip install --target 'C:\path-to-project\my-project' requests

I'm guessing you want to package this so you can use the package in the lambda function.我猜你想要 package 这个所以你可以在 lambdaA384425274C168 中使用 package This won't work if you've got a windows, because the Lambda function runs on a linux container (or sometimes it might work for pure python packages). This won't work if you've got a windows, because the Lambda function runs on a linux container (or sometimes it might work for pure python packages).

A more sustainable option is to use something like Klayers , you can set the preferred package as a layer for your function and it'll work.一个更可持续的选择是使用类似Klayers的东西,您可以将首选的 package 设置为 function 的层,它会起作用。

Another option is to use the python serverless requirements package for the serverless framework.另一种选择是将 python 无服务器要求 package 用于无服务器框架。 https://www.serverless.com/plugins/serverless-python-requirements/ https://www.serverless.com/plugins/serverless-python-requirements/

You should be able to use:您应该能够使用:

pip install --ignore-installed --install-option="--prefix=$YOUR-PATH" requests

The --ignore-installed flag is used to install other dependencies as well, even if those are already installed in the python packages folder. --ignore-installed标志也用于安装其他依赖项,即使那些已经安装在 python 包文件夹中。

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

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