amplify-cli: Problem with pipenv when deploying

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v14.19.0

Amplify CLI Version

7.6.23

What operating system are you using?

Windows > WSL2 > Ubuntu20.04

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No none

Amplify Categories

api

Amplify Commands

add, push

Describe the bug

  1. I do a simple amplify api add go through all the business and select python stack. Everything default.
  2. The amplify push gives me this error
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
cies(best_match):
  File "/usr/lib/python3/dist-packages/pipenv/patched/piptools/resolver.py", line 275, in _iter_dependencies
    for dependency in self.repository.get_dependencies(ireq):
  File "/usr/lib/python3/dist-packages/pipenv/patched/piptools/repositories/pypi.py", line 174, in get_dependencies
    legacy_results = self.get_legacy_dependencies(ireq)
  File "/usr/lib/python3/dist-packages/pipenv/patched/piptools/repositories/pypi.py", line 193, in get_legacy_dependencies
    dist = ireq.get_dist()
  File "/usr/lib/python3/dist-packages/pipenv/vendor/pip9/req/req_install.py", line 1069, in get_dist
    egg_info = self.egg_info_path('').rstrip('/')
  File "/usr/lib/python3/dist-packages/pipenv/vendor/pip9/req/req_install.py", line 514, in egg_info_path
    raise InstallationError(
pip9.exceptions.InstallationError: No files/directories in /something/webapp/amplify/backend/function/getUploadedFiles/src (from )
✖ An error occurred when pushing the resources to the cloud
🛑 An error occurred during the push operation: Command failed with exit code 1: pipenv install

Not sure what the story is?

Expected behavior

To just deploy the functions

Reproduction steps

As above.

Also: Python 3.8.10 pipenv, version 11.9.0

webapp/amplify/backend/function/getUploadedFiles/Pipfile:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
src = {editable = true, path = "./src"}

[requires]
python_version = "3.8"

webapp/amplify/backend/function/getUploadedFiles/src/setup.py:

from distutils.core import setup

setup(name='src', version='1.0')

I note that when i

cd webapp/amplify/backend/function/getUploadedFiles
pipenv install

I get the same error.

When i try (from that dir)

pipenv run install -e src/

I get

Obtaining file:///something/webapp/amplify/backend/function/getUploadedFiles/src
Installing collected packages: src
  Attempting uninstall: src
    Found existing installation: src 1.0
ERROR: Cannot uninstall 'src'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

Then pipenv install works but with the same error as above thus amplify push still doesn’t work?

So looks like there is something wrong with the default pipenv setup?

GraphQL schema(s)

None

Log output

None

Additional information

None

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (2 by maintainers)

Most upvoted comments

Seems to work when i remove the

src = {editable = true, path = "./src"}

line in the Pipfile? The lambda seems to still work so I’m not sure why you have that in there since you copy all the files anyway? Also, when setting up a trigger from an s3 bucket there is no choice between Nodejs and Python? I’m getting the impression that python was an afterthought…

I also got a pipenv problem again; just to record, the exact issue was:

FileNotFoundError: [Errno 2] No such file or directory: ‘[path]/[lambda_function_virtual_env]/bin/python’ 🛑 Failed to install dependencies in [path_to_root]/amplify/backend/function/[lambda_function_name]: Error: Command failed with exit code 1: pipenv install

but the amplify pull and then push didn’t work this time. My steps to resolve this time were: cd [path_to_root]/amplify/backend/function/[lambda_function_name] pipenv --rm pipenv install (then I got an error about a version of Python wasn’t installed, so I did brew install python@[version#]) pipenv --python /usr/local/opt/python@[version#]/bin/python[version#] install cd [path_to_root] amplify push

not sure how this all happened, but hopefully someone else might find this useful.

I’ve just had this issue when trying to add a dependency to an an existing lambda editing the Pipfile. In my case could not trigger the mock of the function locally.

After getting arround thinking that the problem was my docker setup for this, found out that the problem is the auto-generated setup.py file which is not compatible with pipenv and wheel problem (python 3.8 in my case).

for the ones that know python more than me, the previous error is easy, but was not my case. In my case had to dig up the documentation to find out how the “src-layout” was supposed to work.

To solve this I’ve set the setup.py file

from setuptools import setup, find_packages

setup(
    name='src',
    version='1.0',
    packages=find_packages(where="src", exclude="index")
)

and violá… issue fixed!

Hope this prevent someone else the trouble of hours frustration.

Might be that with this issue we got a better messaging next time: https://github.com/pypa/pipenv/issues/5155

Is there any update on this?

Also, I’m getting this error when the CI tries to build the project

2022-03-10T03:43:18.568Z [INFO]: python3 found but version Python 3.7.10 is less than the minimum required version.
                                 You must have python >= 3.8 installed and available on your PATH as "python3" or "python". It can be installed from https://www.python.org/downloads
                                 You must have pipenv installed and available on your PATH as "pipenv". It can be installed by running "pip3 install --user pipenv".
                                 You must have virtualenv installed and available on your PATH as "venv". It can be installed by running "pip3 install venv".

Wrong version of python?!

fucking disgracful how AWS support does not do anything with this shitty python support, I recommend posting these issues on Linkedin and tagging AWS

Hi @esteban-serfe , the python issue is solved now. I just reinstalled the pipenv pip3 install --user pipenv in my root App directory.

Unfortunately my knowhow on python on windows is limited. Sounds like the src dependency is not been able to be installed. Is that the first or the last dependency on the packages section?

Usually I delete the virtualenv for that labda and the install process start again without issue. Sorry for not been able to help more here, but will be nice to have your solution in this case (if you find it)

I’m still having issues on auto deploy with CI/CD. It gets through most of the backend build steps but then it gets to pipenv install and it fails. I’m using Python 3.11 and my build settings file looks like:

version: 1
backend:
  phases:
    preBuild:
      commands:
        - export BASE_PATH=$(pwd)
        - yum install -y gcc openssl-devel bzip2-devel libffi-devel python3.11-pip
        - cd /opt && wget https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tgz
        - cd /opt && tar xzf Python-3.11.1.tgz
        - cd /opt/Python-3.11.1 && ./configure --enable-optimizations
        - cd /opt/Python-3.11.1 && make altinstall
        - pip3.11 install --user pipenv
        - ln -fs /usr/local/bin/python3.11 /usr/bin/python3
        - ln -fs /usr/local/bin/pip3.11 /usr/bin/pip3
        - cd $BASE_PATH
    build:
      commands:
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - npm ci
    build:
      commands:
        - npm run build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

thanks @josefaidt I rebuilt the project from scratch and it seems to have righted itself. I;ll have a look into the build spec. Thanks!