You are most probably trying to execute it as a shell script. Assuming you are using a linux/unix-like operating system, try adding the following line at the start of the script:

`#!/usr/bin/env python`

Also make the file executable:

`sudo chmod +x sql.py`
Answer from Alexander Ejbekov on Stack Overflow
🌐
freeCodeCamp
freecodecamp.org β€Ί news β€Ί module-not-found-error-in-python-solved
ModuleNotFoundError: no module named Python Error [Fixed]
September 12, 2022 - you use an incorrect casing for a module (which still links back to the first point)...for example, spelling numpy as NumPy during import will throw the module not found error as both modules are "not the same"
Discussions

python - Why can't the import command be found? - Stack Overflow
Why can't the import command be found since the shebang is not required in finput.py? ... Save this answer. ... Show activity on this post. Your need to tell your OS that this is a Python program, otherwise, it's interpreted as a shell script (where the import command cannot be found). More on stackoverflow.com
🌐 stackoverflow.com
[BUG] ImportError: ImportError: __import__ not found Python 3.7
I used python_example (https://github.com/pybind/python_example) to create new package. After installation I have Β· >>> import mymodule Traceback (most recent call last): File "", line 1, in ImportError: ImportError: __import__ not found At: (3): More on github.com
🌐 github.com
5
October 7, 2020
I'm lost "no module named...", how importing works?
The easiest way to fix this is to add an __init__.py file to the project root directory also. As it stands, using from ..app.calculations import add expects that all directories involved are packages, but the root directory isn't considered one. Another option is to use sys.path.insert in your test code to put the main package into the list of places Python will look to import stuff from, but that's kind of hacky. Ideally, though, you'd install the project first instead. Poetry makes this fairly painless, though a setup.py script will work as well. It would be smart to do this in a virtual environment. More on reddit.com
🌐 r/learnpython
4
2
March 10, 2022
Python Module Importing Problems
I’ve looked all over the Internet and gone to tech support a couple times with no luck on solving this issue. Some modules are automatically added with a python download (such as math and random) which I can access without an issue. However, although my command prompts shows manually added ... More on discuss.python.org
🌐 discuss.python.org
8
0
March 26, 2024
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί how-to-fix-the-module-not-found-error
How to Fix The Module Not Found Error - Python
July 1, 2026 - A ModuleNotFoundError, occurs when Python cannot locate the module you are trying to import. This usually happens when the module is not installed, the module name is incorrect, or Python cannot find it in its search path.
🌐
Python documentation
docs.python.org β€Ί 3 β€Ί reference β€Ί import.html
5. The import system β€” Python 3.15.1 documentation
By contrast, importlib.reload() will reuse the same module object, and simply reinitialise the module contents by rerunning the module’s code. If the named module is not found in sys.modules, then Python’s import protocol is invoked to find and load the module.
🌐
GitHub
github.com β€Ί pybind β€Ί pybind11 β€Ί issues β€Ί 2557
[BUG] ImportError: ImportError: __import__ not found Python 3.7 Β· Issue #2557 Β· pybind/pybind11
October 7, 2020 - I used python_example (https://github.com/pybind/python_example) to create new package. After installation I have Β· >>> import mymodule Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: ImportError: __import__ not found At: <string>(3): <module> <frozen ...
Author: pybind
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί how-to-fix-the-module-not-found-error
How to Fix The Module Not Found Error? - GeeksforGeeks
April 28, 2025 - Check if the module name and spelling are correct or not ... Whenever you encounter "ModuleNotFoundError" can check if the imported modules are installed in your Python environment by using 'try' and 'except' blocks to handle the error gracefully.
Find elsewhere
🌐
Containersolutions
containersolutions.github.io β€Ί runbooks β€Ί posts β€Ί python β€Ί module-not-found
Module Not Found – Runbooks
If locatedb is not installed, or not up to date/under your control, then you can try and use find to search for the module in a similar way. Or you can look at using other tools available to you in your environment. If you know the version of Python you are using on the command line is correct (see step 2.1), then you can check the default path where Python modules are searched for by adding the following to the file that is trying to load the module: import sys print("sys.path:\n" + "\n".join(sys.path)) exit()
🌐
Towards Data Science
towardsdatascience.com β€Ί home β€Ί programming β€Ί how to fix modulenotfounderror and importerror
How to Fix ModuleNotFoundError and ImportError | Towards Data Science
September 13, 2020 - In most of the cases, either of the errors occur due to the fact that Python is unable to resolve the module's name in sys.path . Recall that when you call import a if the module's name was found neither in sys.modules nor in standard library, ...
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί i'm lost "no module named...", how importing works?
r/learnpython on Reddit: I'm lost "no module named...", how importing works?
March 10, 2022 -

file structure:

Fast-API-Two/
β”œβ”€β”€ app
β”‚   β”œβ”€β”€ calculations.py
β”‚   β”œβ”€β”€ database.py
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ main.py
β”‚   β”œβ”€β”€ models.py
β”‚   β”œβ”€β”€ routers
β”‚   β”‚   β”œβ”€β”€ comment.py
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ login.py
β”‚   β”‚   β”œβ”€β”€ post.py
β”‚   β”‚   β”œβ”€β”€ user.py
β”‚   β”‚   └── vote.py
β”‚   β”œβ”€β”€ schemas.py
β”‚   └── utilities
β”‚       β”œβ”€β”€ b_pass.py
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ oauth2.py
β”œβ”€β”€ requirements.txt
└── tests
    β”œβ”€β”€ __init__.py
    └── test_calculations.py

content of app/calculations.py:

def add(num1: int, num2: int=2) -> int:
    return num1 + num2

content of tests/test_calculations.py:

from app.calculations import add

def test_add():
    print("testing function")
    assert add(3, 4) == 7

test_add()

When I try ton run python3 tests/test_calculations.py I get ModuleNotFoundError: No module named 'app' this error, however pytest runs without any problem.

From what I understand import in tests/test_calculations.py should look like this:

from ..app.calculations import add

# instead of:
# from app.calculations import add

I'm leaving tests/ directory and now I should have access to app package, but this time upon running python3 tests/test_calculations.py I get this error ImportError: attempted relative import with no known parent package and pytest throws this one: ValueError: attempted relative import beyond top-level package

Lastly VSCode has no problem with recognizing/reading both of these methods and doesn't show anything like for example Import ".app.calculations" could not be resolved Pylance. Edit: Just to be precise nothing runs when I hit play button in VSCode I'm talking only about Pylance

[Ubuntu 20.04]

🌐
Python.org
discuss.python.org β€Ί python help
Python Module Importing Problems - Python Help - Discussions on Python.org
March 26, 2024 - I’ve looked all over the Internet and gone to tech support a couple times with no luck on solving this issue. Some modules are automatically added with a python download (such as math and random) which I can access without an issue. However, although my command prompts shows manually added modules such as numpy, networkx, django, etc. have been installed, Python doesn’t recognize them.
🌐
Curiousefficiency
python-notes.curiousefficiency.org β€Ί en β€Ί latest β€Ί python_concepts β€Ί import_traps.html
Traps for the Unwary in Python’s Import System - Alyssa Coghlan's Python Notes
This is an all new trap added in Python 3.3 as a consequence of fixing the previous trap: if a subdirectory encountered on sys.path as part of a package import contains an __init__.py file, then the Python interpreter will create a single directory package containing only modules from that directory, rather than finding all appropriately named subdirectories as described in the previous section. This happens even if there are other preceding subdirectories on sys.path that match the desired package name, but do not include an __init__.py file.
🌐
Python.org
discuss.python.org β€Ί python help
Can't Import Module - Python Help - Discussions on Python.org
January 21, 2025 - Hopefully I have dropped this query in the correct place. I am having trouble importing a module which I have already installed. In this case, i used Pip to install Pandas, but when i tried to import Pandas, I receive an error saying that Pandas cannot be imported.
🌐
OneUptime
oneuptime.com β€Ί home β€Ί blog β€Ί how to fix 'importerror: no module named' in python
How to Fix 'ImportError: No module named' in Python
January 26, 2026 - When Python encounters an import statement, it checks built-in and frozen modules and searches the module path (sys.path), which includes: ... If Python cannot find the module, it raises ModuleNotFoundError in Python 3. # This causes the error if 'requests' is not installed import requests # ModuleNotFoundError: No module named 'requests'
🌐
Medium
medium.com β€Ί @ryan_forrester_ β€Ί fixing-no-module-named-errors-in-python-a-complete-guide-b989b7a2bd19
Fixing β€˜No Module Named’ Errors in Python: A Complete Guide | by ryan | Medium
May 14, 2025 - When Python can’t find a module you’re trying to import, it throws a `ModuleNotFoundError`. Here’s what it looks like:
🌐
Stack Overflow
stackoverflow.com β€Ί questions β€Ί 70826081 β€Ί import-command-not-found β€Ί 70826109
python - import: command not found - Stack Overflow
I have this code in myname.py: # myname.py def get_name(): return "Jim" and this in hello.py: # hello.py import myname name = myname.get_name() print("hello {}".format(nam...
🌐
LabEx
labex.io β€Ί tutorials β€Ί python-how-to-address-module-not-found-errors-in-python-415764
How to address module not found errors in Python | LabEx
## Example: Checking the module name try: import pandas as pd except ModuleNotFoundError: print("Error: module 'pandas' not found") The Python path is a list of directories that Python searches when trying to import a module.
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί python cannot see file when importing my own module from one level above
r/learnpython on Reddit: Python cannot see file when importing my own module from one level above
December 1, 2022 -

Hi all,

I was wondering if anyone had encountered this type of issue before. I am trying to import a module from a package I created. The package is in the same directory as my main.py file, but python is unable to use files in that directory I am using to initialize it's objects.

My structure is:

top level/
        main.py
        pckgfolder/
                __init__.py
                mymodule.py
                init.txt

ie, in main.py i have:

from pckgfolder import mymodule
myobject = mymodule.myClass()

and then within mymodule.py I have

class myClass:
        def __init__(self):
        with open('init.txt', 'r'):
        #load default data

When I try to do this I get:

FileNotFoundError: [Errno 2] No such file or directory: 'init.txt'

Since python cannot see the file I guessed that we need to add the directory with the module to the path, however I checked this is and it is in sys.path at runtime, so the file should be visible.

I added some print statements to __init__.py and found that when it is run the working directory is the top level, so I assume that is why the file is not visible, but do not know what to do about this (I do not wish to try things like changing the working directory during the run). When I was testing the module itself I did so from inside the directory and it worked fine, so I am quite lost here.

🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί why do i get a modulenotfounderror?
r/learnpython on Reddit: Why do I get a ModuleNotFoundError?
September 2, 2021 -

Hey Guys,

I get a weird ModuleNotFoundError in one of my projects and i do not really understand why. So here is my Folder Structure:

Project\

| main.py

| packageabc\

| | __init__.py

| | abc.py

| | packagexyz\

| | | xyz.py

In every .py file is an abc/xyz or main class. Now the interesting part. Inside the abc.py I do an import like this:

from packagexyz.xyz import xyz

This works perfectly fine!

Inside the main.py I do an import like this:

from packageabc.abcimport abc

Now I get an ModuleNotFoundError. Error Code looks like this:

from packagexyz.xyz import xyz ModuleNotFoundError: no module named packagexyz.

So the import in the abc.py File that works perfectly when tested inside the file does not work if the abc.py file is imported. So why is that?

Top answer
1 of 2
2
You probably have a circular dependency - abc imports xyz and xyz imports abc. Python can't complete either import so it raises an error.
2 of 2
1
It's because of the way Python looks for modules. There's a list of paths that Python looks through to find modules, which automatically includes things like the place pip installs packages to. It also automatically includes the directory the executing script is in. It does not, however, automatically include the directory an imported module is in. So, if you're executing "abc.py" directly, in finds "packagexyz" just fine, since it knows to look in the "packageabc" folder for modules. If you are executing "main.py" instead, the only place it looks (besides the default and manually configured paths) is "Project", so it can't find packagexyz. There's really three ways you could fix this: Manually configuring paths You can keep the imports as you have them and simply ensure that the "packageabc" folder is always on the search path for modules. You can do so either by configuring the PYTHONPATH environment variable to include it or by appending it to sys.path in your "main.py" before importing abc. Absolute imports You could also change the import in "abc.py" to be relative to "Project" (from packageabc.packagexyz.xyz import xyz). Then your "main.py" would work the way it is. Of course, that in turn means you can no longer directly execute "abc.py" unless you manually configure "Project" to always be on the search path for modules. Relative imports You could also change "abc.py" to use relative imports (from .packagexyz.xyz import xyz, note the extra dot in front). Then your "main.py" would work the way it is, as well. You could also still directly execute "abc.py", but only if you make sure to do it in a way that Python is aware it is part of a larger package (otherwise, relative imports give you an error). Specifically, you'd always need to execute it like this: python -m packageabc.abc Rather than like this: python packageabc/abc.py
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί fix-modulenotfounderror-and-importerror-in-python
How To Fix Modulenotfounderror And Importerror in Python - GeeksforGeeks
July 23, 2025 - Below, are the common reason of occurring Modulenotfounderror and Importerror in Python. ... The code attempts to import a module named non_existent_module. If the module is not found, it raises ModuleNotFoundError, and the exception is caught.