amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Not able to push new lambda function changes via amplify push. Error: Could not find a pipenv site-packages directory

Open heng2j opened this issue 5 years ago • 24 comments

Note: If your issue/bug is regarding the AWS Amplify Console service, please log it in the Amplify Console GitHub Issue Tracker

Describe the bug A clear and concise description of what the bug is.

I am not able to do amplify push after making any changes to one of my lambda function. For example simply remove a single space.

I am receiving this error:

nstalling dependencies from Pipfile.lock (a65489)...
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
(node:52398) UnhandledPromiseRejectionWarning: Error: Could not find a pipenv site-packages directory at /Users/heng2j/.virtualenvs/collectorVideosProcessor-r9qVMPot/lib/python3.8/site-packages
    at Object.getPipenvDir (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-python-function-runtime-provider/src/util/pyUtils.ts:24:9)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-python-function-runtime-provider/src/util/packageUtils.ts:27:21
(node:52398) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:52398) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Amplify CLI Version You can use amplify -v to check the amplify cli version on your system

4.39.0

To Reproduce Steps to reproduce the behavior or terminal output if applicable

I am putting my python dependencies in another lambda layer for that lambda function at opt/python

And I am using runtime Python 3.7 instead. But I have tried to run Python 3.8

Expected behavior A clear and concise description of what you expected to happen.

Successful push changes to the lambda function.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Mac
  • Node Version. You can use node -v to check the node version on your system v12.13.0

Additional context Add any other context about the problem here.

heng2j avatar Dec 11 '20 22:12 heng2j

@heng2j I'm having the exact same issue. Have you found a workaround yet?

half2me avatar Dec 15 '20 16:12 half2me

Hi @half2me , @heng2j

It looks like pipenv is missing. I have a following questions:

  1. Are you able to push functions before this error(selecting python as runtime)?

  2. Can you make sure you have pipenv installed and included in your PATH variable(make sure python verison > 3.8)?

akshbhu avatar Dec 15 '20 21:12 akshbhu

@akshbhu

  1. I got this error the very first time I tried to push my python function.
  2. I have it installed:
➜  ~ python3 --version
Python 3.9.1
➜  ~ pipenv --version
pipenv, version 2020.11.15

half2me avatar Dec 15 '20 21:12 half2me

Can you try this:

  1. Install pipenv using pip install --user pipenv.This does a user installation to prevent breaking any system-wide packages.
  2. Run python -m site --user-base to get your user base binary directory, append bin to the path and add this path to your $PATH variable. You can echo $PATH if its added or not.
  3. Try amplify push again.

Let me know if this works for you?

akshbhu avatar Dec 15 '20 21:12 akshbhu

For me, I checked that I only have python3.7 in my lambda function's virtualenv. So I have to renamed it manually to 3.8 to fix this issue.

/Users/heng2j/.virtualenvs/collectorVideosProcessor-r9qVMPot/lib/python3.8/site-packages

heng2j avatar Dec 17 '20 00:12 heng2j

@heng2j @half2me Are you'll unblocked on this issue?

kaustavghosh06 avatar Dec 24 '20 20:12 kaustavghosh06

Closing due to lack of response.

jhockett avatar Jan 05 '21 21:01 jhockett

amplify pull did the trick for me. It must have recreated what was missing (obviously I already had python and pipenv). Think of it this way ... if you were to pick up on a brand new machine, you wouldn't have any of those files under ~/.local/share/virtualenvs or ~/.virtualenvs. That's technically what happened to me (migrated Amplify project to M1 Mac).

UPDATE: Scratch that. It appears I would have to run pull before push every time. It's no fix. I'll tell you what seems to reliably do the trick:

pipenv run amplify push

rt-demetri avatar Jan 06 '21 02:01 rt-demetri

thanks @rt-demetri this worked for me

pipenv run amplify push

bjm88 avatar Jan 15 '21 02:01 bjm88

I had the same problem. For me, the solution to solve it was to call "python3 -m site --user-base" as @akshbhu said. And then go inside the folder created, and copy the site-package folder into the path given by the pipenv error.

I needed this for an amplify lambda, the default path is not the path used by my lambda.

vincent38wargnier avatar Jan 17 '21 14:01 vincent38wargnier

I'm having a similar problem. When I add a new lambda function I have to cd into the folder and run pipenv shell, then amplify push works.

So I have to have a separate pipenv virtual environment for EVERY lambda function? Where are the docs on how to properly use pipenv and add a python lambda function with amplify. I should just be able to follow a doc and it should work.

bfleming-ciena avatar Feb 01 '21 19:02 bfleming-ciena

But default i still get this issue and i can't do a amplify function build. Amplify CLI should fix this out of the box.

michaelbrewer avatar Feb 13 '21 12:02 michaelbrewer

@bfleming-ciena i agree this is not resolved @jhockett can you reopen this

michaelbrewer avatar Feb 13 '21 12:02 michaelbrewer

Also seeing this issue. Anyone find a workaround yet? Neither @rt-demetri or @bfleming-ciena solutions worked for me.

esotericzhang avatar Feb 26 '21 05:02 esotericzhang

I had the same problem. For me, the solution to solve it was to call "python3 -m site --user-base" as @akshbhu said. And then go inside the folder created, and copy the site-package folder into the path given by the pipenv error.

I needed this for an amplify lambda, the default path is not the path used by my lambda.

This worked for me, I don't normally reply lol. Thank you and @akshbhu.

ousjaguraga avatar Mar 09 '21 17:03 ousjaguraga

Maybe @heitorlessa can help with a suggestion on how to fix this in the Amplify cli?

michaelbrewer avatar Mar 09 '21 17:03 michaelbrewer

For me, I checked that I only have python3.7 in my lambda function's virtualenv. So I have to renamed it manually to 3.8 to fix this issue.

/Users/heng2j/.virtualenvs/collectorVideosProcessor-r9qVMPot/lib/python3.8/site-packages

I have also encountered this problem. In my case, pipenv command makes ~/.local/share/virtualenvs/myPythonAmplify/lib/python3.8 But, I'm using python3.9 So, I change directory name from python3.8 to python3.9

I don't know why this works, but the problem is solved. Now I can amplify push !!!

viaSSH avatar Mar 12 '21 14:03 viaSSH

For me, I checked that I only have python3.7 in my lambda function's virtualenv. So I have to renamed it manually to 3.8 to fix this issue. /Users/heng2j/.virtualenvs/collectorVideosProcessor-r9qVMPot/lib/python3.8/site-packages

I have also encountered this problem. In my case, pipenv command makes ~/.local/share/virtualenvs/myPythonAmplify/lib/python3.8 But, I'm using python3.9 So, I change directory name from python3.8 to python3.9

I don't know why this works, but the problem is solved. Now I can amplify push !!!

Funny thing you should mention that. I think each first time you run Python in an amplify project, it leaves behind version information in a pipfile or something like that. Subsequent runs with a different version of Python will see the different version listed and you run into situations such as this issue. Another coworker unknowingly updated the pipfile (by means of running a multitude of different pip/pipenv commands) and suddenly I’m not getting the error anymore. Next time I’m in that code, I’ll take a look at the commit.

dcchristopher avatar Mar 12 '21 14:03 dcchristopher

That's right. Changing "python3.8 to python3.9 version" Methods was only possible once.... After that, I use pipenv run amplify push It's Works!!

Maybe my Python version and pipfile have compatibility confilcts.

viaSSH avatar Mar 12 '21 14:03 viaSSH

Same problem just resolved.

There is a mistake in the project in my case. My college setup python 3.8 in the functions, but use 3.9 in the Pipefile under the root of project.

So pipenv kept looking for site-packages under python-3.9 instead of python-3.8.

After set python 3.8 in the pipefile, I followed what akshbhu said:

  • pip install --user pipenv
  • export PATH="$HOME/.cargo/bin:$HOME/.local/bin:$PATH"
  • amplify push

It works now.

magicalne avatar Mar 16 '21 03:03 magicalne