question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing local module into Python function fails

See original GitHub issue

Hello,

I’ve looked at these issues already: #278 and #219 but I keep having an issue when trying to import a local module into a Python function.

I’m using Python 3.7 and not 3.6 so it could be the reason why I can’t get this to work. I’m working on a function created by someone else (with Python 3.6) and I want to run it locally. I have no issues running it but when I try to make an http request I get an error related to the import of a local module.

Here’s my project structure:

functions_python
    |_ ml-service
        | __init__.py
        | model_helper.py
        | function.json

I want to import model_helper into init, and here are some of the things I tried:

from . import model_helper (no module named model_helper) from …ml-service import model_helper (Invalid syntax) from functions_python.ml-service import model_helper (Invalid syntax) import functions_python.ml-service (Invalid syntax) from __app__.ml-service import model_helper (Invalid syntax) import __app__.ml-service (Invalid syntax)

The reason I’m trying to import a module is because I have a class in there (used in a sklearn pipeline) and apparently you can’t have it in __init__.py

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Kagigzcommented, Apr 8, 2019

@maiqbal11 I have tried in a Python 3.6 virtual environment and it now works. The issue was indeed linked to the Python version. Do you know if v3.7 will be supported soon?

Thanks for your help

0reactions
maiqbal11commented, Apr 8, 2019

@Kagigz, glad to hear! We need to be able to support both Python 3.6 and 3.7 since many core ML libraries currently have not been ported over to 3.7. This requires some infrastructure work on our part which will happen over the next few months. We are expecting to be able to support 3.7 within the year.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can i solve the Error when importing local Module
I want to import a local module, which is located in a different folder. I imported like this: from .utils.embeds import Embeds.
Read more >
How to import local modules with Python - Quentin Fortier
Importing files for local development in Python can be cumbersome. In this article, I summarize some possibilities for the Python developer.
Read more >
Resolve "Unable to import module" errors from Python ...
I receive an "Unable to import module" error when I try to run my AWS Lambda code in Python. How do I resolve...
Read more >
ModuleNotFoundError: no module named Python Error ...
How to fix the ModuleNotFoundError in Python · 1. Make sure imported modules are installed · 2. Make sure modules are spelled correctly...
Read more >
6. Modules — Python 3.11.1 documentation
Such a file is called a module; definitions from a module can be imported into ... If you intend to use a function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found