Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ModuleNotFoundError no module named 'data', Vercel python

I have data (data.py) which is file that contins constants. When I try to import the file which is in the same folder ‘/api’ it says that no module named ‘data’

I have it the same casing, and i dont understand what could be the reason why it would happen.

Any help would be appericated as I am not great with python

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

   from data import *
   import numpy as np
   from http.server import BaseHTTPRequestHandler
   from urllib.parse import urlparse, parse_qs
   import json


class handler(BaseHTTPRequestHandler):

def do_GET(self):
    self.send_response(200)
    self.send_header('Content-type', 'text/plain')
    self.end_headers()

    result = urlparse(self.path)

    query_params = json.dumps(parse_qs(result.query))

    print('result', query_params)

    self.wfile.write('Hello, world!'.encode('utf-8'))

    return

>Solution :

If you’re trying to import a module in the same directory, you can use a relative import instead of an absolute import.

For example, if your directory structure looks like this:

- api/
  - data.py
  - main.py

You can import data.py into main.py using the relative import syntax:

from .data import *

The leading ‘.’ tells Python to look for data.py in the same directory as main.py.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading