V
V
Vadim2021-02-02 22:34:36
Python
Vadim, 2021-02-02 22:34:36

How to pull boto3 package from local directory?

Hello everyone,

I'm writing a Lambda function for aws, installed the boto3 package for it. Now in my main python file (main.py) is:

import boto3
import os
from pprint import pprint
import time
...............................


I installed the whole boto3 with pip3 install -r requirements.txt --target ./packages/

to a local directory relative to main.py
application/
├── main.py
│ └── packages/

how do I do import boto3 in main.py file from this ./packages/ directory, the

problem is, among other things, that a whole bunch of directories for boto3
./packages are installed

6019a903c268d812154546.png

, good luck to everyone,
Vadim

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim, 2021-02-03
@Viji

Here it works:

>>> import sys
>>> sys.path.insert(0, 'packages')
>>> from packages  import boto3

A
Alan Gibizov, 2021-02-03
@phaggi

I don't know if these options work for you.
For example, I have a testpackage folder in the project root folder, a subtestpackage folder in it, a subtestmodule.py file in it, functions and classes in it.
You can either use them like this:

from testpackage.subtestpackage.subtestmodule import subtestfunc, Subtestclass, anotherfunc
a = subtestfunc()
b = Subtestclass()
c = anotherfunc()

either like this:
from testpackage.subtestpackage import subtestmodule as sm
a = sm.subtestfunc()
b = sm.Subtestclass()
c = sm.anotherfunc()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question