How to build a Python project for a specific version of Python

0 votes

I have an app that I would like to deploy to AWS Lambda and for this reason it has to have Python 3.9.

I have the following in the pyproject.toml:

name = "app"
readme = "README.md"
requires-python = "<=3.9"
version = "0.5.4"

If I try to pip install all the dependencies I get the following error:

ERROR: Package 'app' requires a different Python: 3.11.1 not in '<=3.9'

Is there a way to specify the Python version for this module?

I see there is a lot of confusion about this. I simply want to specify 3.9 "globally" for my build. So when I build the layer for the lambda with the following command it runs:

pip install . -t pyhon/

Right now it has only Python 3.11 packaged. For example:

❯ ls -larth python/ | grep sip
siphash24.cpython-311-darwin.so

When I try to use the layer created this way it fails to load the required library.

Feb 16, 2023 in AWS by sarit
• 1,830 points
223 views

1 answer to this question.

0 votes

To build a Python project for a specific version of Python, you can take the following steps:

  1. Make sure that the specific version of Python is installed on your machine.

  2. Specify the version of Python that your project requires in your project's configuration file (in your case, pyproject.toml) using the python_requires field. For example

  1. python_requires = >=3.9

  2. Create a virtual environment with the specific version of Python installed:

    python3.9 -m venv myenv

  3. Activate the virtual environment:

    source myenv/bin/activate

  4. Install your project's dependencies in the virtual environment:

    pip install .

  5. When building the layer for AWS Lambda, make sure to use the virtual environment you created in step 3. For example:

    pip install . -t python/ --no-compile

    The --no-compile option is recommended for AWS Lambda to avoid potential issues with binary compatibility between different versions of Python.

  6. Package the contents of the virtual environment (including your project's dependencies) and upload it to AWS Lambda as a layer.

  7. When configuring your AWS Lambda function, specify the layer you created in step 7 as a runtime dependency.

By following these steps, you should be able to build and deploy your Python project for the specific version of Python required by AWS Lambda.

Elevate Your Expertise with Microservices Certification!

answered Feb 17, 2023 by anonymous

Related Questions In AWS

0 votes
3 answers
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 3,970 views
0 votes
1 answer
+3 votes
1 answer

How to get a Job for AWS cloud architect

A Cloud Architect is an IT specialist who is ...READ MORE

answered Sep 25, 2018 in AWS by Priyaj
• 58,090 points
474 views
0 votes
1 answer

How to fetch a list of items (like a SQL IN clause)

You can use this as this worked ...READ MORE

answered Oct 26, 2018 in AWS by Priyaj
• 58,090 points
9,530 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP