OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Attempting to use locally cloned version of Python package in Docker throws metadata error

  • Thread starter Thread starter M. Nicol
  • Start date Start date
M

M. Nicol

Guest
I am testing an experimental library version and must run it in a docker container locally rather than as a pip install.

As a result, I copy all of the files from the locally cloned library into the working directory of Docker and do relative imports.

My file structure is the following:

Code:
PYOPENSKY-AWS/
├── pyopensky/
│   ├── .github/
│   ├── .pytest_cache/
│   ├── docs/
│   ├── scripts/
│   ├── src/pyopensky/
│   │   ├── init.py
│   │   ├── api.py
│   │   ├── config.py
│   │   ├── impala.py
│   │   ├── py.typed
│   │   ├── rest.py
│   │   ├── s3.py
│   │   ├── schema.py
│   │   ├── time.py
│   │   └── trino.py
│   └── tests/
│       ├── .gitignore
│       ├── license.txt
│       ├── poetry.lock
│       ├── pyproject.toml
│       └── readme.md
├── Dockerfile
├── lambda.py

From here I use a docker file to import the files:

Code:
# Use the official Python base image
FROM public.ecr.aws/lambda/python:3.10

# Set the working directory to the root of the Lambda function directory
WORKDIR /var/task

# Copy the application files
COPY pyopensky/src/pyopensky /var/task/pyopensky
COPY lambda.py .

# Command to run the Lambda function handler
CMD ["lambda.getHistoricalADSB"]

And a Lambda.py function:

Code:
import json
import datetime
from pyopensky.trino import Trino

def getHistoricalADSB(event, context):
    print("Running")
    try:
        # Initialize Trino
        trino = Trino()
        # Rest of code is unimportant

The issue is that when I build this docker file:

Code:
docker build -t get-historical-adsb .  
docker run -p 9000:8080 get-historical-adsb

And then call it (with an empty body {}):

Code:
http://localhost:9000/2015-03-31/functions/function/invocations

It throws the error:

Unable to import module 'lambda': No package metadata was found for pyopenskyntimes-update.html

The error occurs at the import statement:

Code:
from pyopensky.trino import Trino

It appears that the lambda.py is unable to find the pyopensky library despite it being cloned directly into the same folder as the lambda.py. How can I fix this?
<p>I am testing an experimental library version and must run it in a docker container locally rather than as a pip install.</p>
<p>As a result, I copy all of the files from the locally cloned library into the working directory of Docker and do relative imports.</p>
<p>My file structure is the following:</p>
<pre><code>PYOPENSKY-AWS/
├── pyopensky/
│ ├── .github/
│ ├── .pytest_cache/
│ ├── docs/
│ ├── scripts/
│ ├── src/pyopensky/
│ │ ├── init.py
│ │ ├── api.py
│ │ ├── config.py
│ │ ├── impala.py
│ │ ├── py.typed
│ │ ├── rest.py
│ │ ├── s3.py
│ │ ├── schema.py
│ │ ├── time.py
│ │ └── trino.py
│ └── tests/
│ ├── .gitignore
│ ├── license.txt
│ ├── poetry.lock
│ ├── pyproject.toml
│ └── readme.md
├── Dockerfile
├── lambda.py
</code></pre>
<p>From here I use a docker file to import the files:</p>
<pre><code># Use the official Python base image
FROM public.ecr.aws/lambda/python:3.10

# Set the working directory to the root of the Lambda function directory
WORKDIR /var/task

# Copy the application files
COPY pyopensky/src/pyopensky /var/task/pyopensky
COPY lambda.py .

# Command to run the Lambda function handler
CMD ["lambda.getHistoricalADSB"]
</code></pre>
<p>And a Lambda.py function:</p>
<pre class="lang-py prettyprint-override"><code>import json
import datetime
from pyopensky.trino import Trino

def getHistoricalADSB(event, context):
print("Running")
try:
# Initialize Trino
trino = Trino()
# Rest of code is unimportant
</code></pre>
<p>The issue is that when I build this docker file:</p>
<pre><code>docker build -t get-historical-adsb .
docker run -p 9000:8080 get-historical-adsb
</code></pre>
<p>And then call it (with an empty body <code>{}</code>):</p>
<pre><code>http://localhost:9000/2015-03-31/functions/function/invocations
</code></pre>
<p>It throws the error:</p>
<blockquote>
<p>Unable to import module 'lambda': No package metadata was found for pyopenskyntimes-update.html</p>
</blockquote>
<p>The error occurs at the import statement:</p>
<pre class="lang-py prettyprint-override"><code>from pyopensky.trino import Trino
</code></pre>
<p><strong>It appears that the lambda.py is unable to find the pyopensky library despite it being cloned directly into the same folder as the lambda.py. How can I fix this?</strong></p>
 

Latest posts

Top