🌐
Frappe
discuss.frappe.io › erpnext
ImportError: __import__ not found. Possible source of error: Server Script - ERPNext - Frappe Forum
August 23, 2024 - { “exception”: “ImportError: import not found”, “exc_type”: “ImportError”, “_exc_source”: “Server Script” }
🌐
Frappe
discuss.frappe.io › erpnext
ImportError: __import__ not found when using Server Script on Stock Entry (Frappe v15.69.2) - ERPNext - Frappe Forum
June 15, 2025 - Even with only this code import frappe from datetime import datetime frappe.log_error(“Test Script”, “Running”) I am getting this error on submit… ImportError: import not found Possible source of error: Server Script I have verified: • Only one script is active • It’s not disabled ...
Discussions

"ImportError: __import__ not found" in server script
client side code : ```frappe.web_form.after_save = async function() { const form_data = frappe.web_form.get_values(); console.log(form_data); if (form_data.resume_attachment) { try { const resume_text = await fetchResumeText(form_data.resume_attachment); console.log(resume_text); const ats_score ... More on discuss.frappe.io
🌐 discuss.frappe.io
0
0
July 15, 2024
ImportError: __import__ not found ERPNext
hello friends I was doing some validation in Custom Script and now when trying to save information in the customer module I get the following error. I am using version 12. More on discuss.frappe.io
🌐 discuss.frappe.io
0
0
October 20, 2021
Python_script error. Error executing script: '__import__'
The problem A python_script that I have used successfully with many previous releases, including 2021.5.1, now reports an error after upgrading to 2021.5.5. Logger: homeassistant.components.python_... More on github.com
🌐 github.com
5
May 20, 2021
[BUG] ImportError: ImportError: __import__ not found Python 3.7
There was an error while loading. Please reload this page · I used python_example (https://github.com/pybind/python_example) to create new package. After installation I have More on github.com
🌐 github.com
5
October 7, 2020
🌐
Frappe
discuss.frappe.io › frappe framework › custom script
ERPNext custom server script ImportError: __import__ not found - Custom Script - Frappe Forum
November 5, 2020 - I’m trying to use aws services with python using boto3 library from a custom script but I’m getting error on trying to import the module that I have installed using pip3: ImportError: __import__ not found What does thi…
🌐
Frappe
discuss.frappe.io › erpnext
"ImportError: __import__ not found" in server script - ERPNext - Frappe Forum
July 15, 2024 - client side code : ```frappe.web_form.after_save = async function() { const form_data = frappe.web_form.get_values(); console.log(form_data); if (form_data.resume_attachment) { try { const resume_text = await fetchR…
🌐
Frappe
discuss.frappe.io › erpnext › customize erpnext
ImportError: __import__ not found ERPNext - Customize ERPNext - Frappe Forum
October 20, 2021 - hello friends I was doing some validation in Custom Script and now when trying to save information in the customer module I get the following error. I am using version 12.
🌐
GitHub
github.com › home-assistant › core › issues › 50900
Python_script error. Error executing script: '__import__' · Issue #50900 · home-assistant/core
May 20, 2021 - Logger: homeassistant.components.python_script.event_creator.py Source: components/python_script/__init__.py:221 Integration: Python Scripts (documentation, issues) First occurred: 10:29:42 (1 occurrences) Last logged: 10:29:42 Error executing script: '__import__' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 221, in execute exec(compiled.code, restricted_globals) File "event_creator.py", line 565, in <module> File "event_creator.py", line 161, in get_event_date File "event_creator.py", line 148, in check_date KeyError: '__import__'
Author: home-assistant
🌐
GitHub
github.com › pybind › pybind11 › issues › 2557
[BUG] ImportError: ImportError: __import__ not found Python 3.7 · Issue #2557 · pybind/pybind11
October 7, 2020 - >>> import mymodule Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: ImportError: __import__ not found At: <string>(3): <module> <frozen importlib._bootstrap>(222): _call_with_frames_removed <frozen importlib._bootstrap_external>(914): create_module <frozen importlib._bootstrap>(577): module_from_spec <frozen importlib._bootstrap>(666): _load_unlocked <frozen importlib._bootstrap>(958): _find_and_load_unlocked <frozen importlib._bootstrap>(969): _find_and_load <stdin>(1): <module>
Author: pybind
🌐
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
Python’s import system is powerful, but also quite complicated. Until the release of Python 3.3, there was no comprehensive explanation of the expected import semantics, and even following the release of 3.3, the details of how sys.path is initialised are still somewhat challenging to figure ...
Find elsewhere
🌐
Frappe
discuss.frappe.io › t › importerror-import-not-found › 114749
ImportError: __import__ not found - Frappe Forum
December 19, 2023 - File “apps/frappe/frappe/utils/safe_exec.py”, line 81, in safe_exec exec( File “”, line 1, in ImportError: import not found My code is 🙂 import frappe from frappe.utils import getdate, today def send_birthday_email(): # Customize the email content subject = _("Happy Birthday!") message = _("{getdate(today())}Dear ,\n\nWishing you a fantastic birthday!") # Send the email frappe.sendmail( recipients="xxxx@gmail.com", subject=subject, message=message ) send_birt...
🌐
Stack Overflow
stackoverflow.com › questions › 46679075 › python-3-import-module-not-found-error
python 3 import module not found error - Stack Overflow
October 11, 2017 - Im trying to import a module from a different sub directory in Python 3 and I'm having trouble getting the script running. The current file structure I have is: Copy/lets_import __init__.py /app __init__.py main.py server.py /tests __init__.py tests_main.py
🌐
Stack Overflow
stackoverflow.com › questions › 72169123 › importerror-and-modulenotfounderror-how-to-get-a-script-running-from-the-comman
python - ImportError and ModuleNotFoundError: how to get a script running from the command line? - Stack Overflow
So I found my mistake. The solution is to run python3 -m HorticulturalSalesPrediction_API.run in the HorticulturalSalesPrediction folder. Then it works like expected. I just then had to adjust some imports:
🌐
Reddit
reddit.com › r/learnpython › importerror when running script but import works in python shell? python 3.4
r/learnpython on Reddit: ImportError when running script but import works in python shell? Python 3.4
September 4, 2017 -

Trying to figure out the best way to import custom modules into my main script. It works fine if I have them all in the same directory like this:

project/project/
---- __init__.py
---- project.py
---- module1.py
---- module2.py 

And then these import statements in project.py work fine:

from .module1 import ClassName1
from .module2 import ClassName2

But if I'm trying to organize my structure more and use subdirectories like this:

project/project/
---- __init__.py
---- project.py
---- subdir/
-------- __init__.py
-------- module1.py
-------- module2.py

And then I try to import these modules in project.py like this:

from subdir.module1 import ClassName1
from subdir.module2 import ClassName2

And I get an error of:

ImportError: No module named 'subdir'

But the most frustrating part is that if I cd into project/project/ and run the python shell the imports work:

$ python
>>> from subdir.module1 import ClassName1
>>> from subdir.module2 import ClassName2

No import errors. I keep finding threads on stackexchange that say all you have to do is add a blank __init__.py file to the subdirectory which I'm doing but I keep getting these Import errors. The fact that it works in the python shell is the worst part because I don't know why it works there but not in my actual script.

What am I doing wrong?

EDIT: I uploaded a example project to github that might be easier to show what I'm doing. In the project I have two lines for two custom modules:

from .subdir.hellosubdir import HelloSubdir
from .hellosamedir import HelloSamedir

As it is now it give the error:

from .subdir.hellosubdir import HelloSubdir
ImportError: No module named 'helloimports.subdir'

If I comment out that line the line from .subdir.hellosubdir import HelloSubdir the other line imports without any problems.

Here's the github link:

https://github.com/thetalentedmrpeanut/helloimports

Also I'm installing this via pip and running it via cli with the $ helloimports command

EDIT 2:

Ok so I think I'm starting to wrap my brain around this. Here's what I found after some more digging:

First I looked up exactly where pip is installing my projects after I run the command $ pip install --user projectname/. I did this by opening a python shell and runing the following commands:

>>> import sys
>>> sys.path

Because I'm installing these packages with the --user flag a per the instructions of my operating system (gentoo linux) these packages are being installed in /home/myusername/.local/lib64/python3.4/site-packages/

When I went into that directory and then into the helloimports directory I discovered that my subdir directory was not even being installed. I did some more research and I think a big part of my misunderstanding has to do with the terms and how python defines certain things. As I understand it now a PACKAGE is a directory that contains a __init__.py file, a MODULE is a file with a .py extension that contains python code. Then there's also PROJECT which I'm going to think of as the entire collection of files.

The confusing thing about PACKAGE is that it's different than how a linux distribution would define a package. So on my system the package that gets installed is what I refer to as the PROJECT.

So one issue was that in my mind placing a module into a sub directory was just a matter of keeping multiple modules organized. I wasn't thinking that the act of placing them inside a sub directory was in fact creating a PACKAGE. I thought that a sub directory with a blank __init.__py was the same thing as having that module file in the same directory.

So I needed to find out why subdir was not being installed and I found out that the problem was in my setup.py file. In that file I had the line packages=['helloimports'],

In my mind thinking that my subdir was part of the helloimports package I thought that it should just automatically be included. But now that I know that the act of creating a subdirectory creates package it makes sense that it would not be installed.

To install the subdir package I can either explicitly add like: package=['helloimports', 'subdir'] or I can import the find_packages function from setuptools and then change the line to package=find_packages() this will automatically add all the sub packages within the main package unless you pass an argument excluding certain ones etc.

So the summary for the issue of importing sub directories is:

1. if you place a module in a sub directory it is no longer just a module it is now a PACKAGE

2. This new sub directory PACKAGE must contain an __init__.py file. This file can be blank or it can have code in it depending on your preference.

3. In setup.py you must either explicity add the subdirectory name to the setup() package= argument or you must import the find_packages function with from setuptools import setup, find_packages and then set packages=find_packages()

4. In the main file for you PROJECT if you want to import the sub directory module you use the dot notation like: from .subdirectory.modulename import ClassName

Next I discovered that my bin/helloimports file was not even doing anything. I removed it completely from the project and and my commandline command of $ helloimports --print-hello-subdir still worked. I looked at what pip was actual installing in the directory .local/bin and that was the following code:

#!/usr/bin/python3.4
# EASY-INSTALL-ENTRY-SCRIPT: 'helloimports==0.1.0','console_scripts','helloimports'
__requires__ = 'helloimports==0.1.0'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('helloimports==0.1.0', 'console_scripts', 'helloimports')()
    )

This didn't look anything like the bin/helloimports file that I had written. My bin/helloimports script was:

#!/usr/bin/env python

import helloimports
helloimports.helloimports.main()

But as it turns out I could have written anything in that file because it wasn't even being used. Again this was an issue with my understanding of setup.py. I had previously been using the setup() parameter scripts= for my python projects projects. So in past 2.7 projects I was doing something like scripts=['bin/helloimports'], in setup() in setup.py.

In new python 3 projects I've still been creating these bin/projectname scripts but I've been using the entry_points= parameter. I for some reason was thinking that this was interacting with my bin/projectname file but I have learned that it is not. And I also learned that it's much more powerful than I thought and you can, I think, create command line executables that target just a single function within a module.

So when I had the following in setup() in setup.py:

entry_points={ 
    'console_scripts': [
        'helloimports=helloimports.helloimports:main',
    ],
},

It had nothing to do with my bin/helloimports file. Instead it's defining the cli executable as helloimports and setting that equal to main package name helloimports --> main module name helloimports.py --> function of main()

This also means that the code in my helloimports/__init__.py file wasn't really doing anything either. I had it as

helloimports/__init__.py:

import helloimports

I don't think this was doing anything at all. Or at least it wasn't doing what I thought it was. If I delete that line and have a completely blank __init__.py file the commandline executable still works because I'm explicity connecting the main module of helloimports.py in the chain.

So how I understand it now is that the line helloimports=helloimports.helloimports:main can be broken down into the following parts:

1. helloimports= is the commandline executable that is used when running $ helloimports --help etc.

2. helloimports. is the helloimports package which is the helloimports/__init__.py file.

3. .helloimports is the helloimports/helloimports.py file

4. .helloimports:main is the def main(): function in helloimports/helloimports.py

So the issue comes into how to deal with these __init__.py files. From my understanding I can do a couple of different things.

1. I can leave the __init__.py file blank. This creates the need for the chaining of the blank helloimports/__init__.py to the helloimports.py in the console_scripts in setup.py. helloimports.helloimports:main

2. I can place all the code for my main module helloimports.py in __init__.py. Then my project would change from:

helloimports/
---- __init__.py
---- helloimports.py

to:

helloimports/
----__init__.py

And this would change the console_scripts to `helloimports=helloimports:main'

3. I can add some code to __init__.py to import everything from the helloimports.py module into the __init__py file and in doing so let the main PACKAGE and main MODULE be the same thing in the eyes of python. So this would look like:

helloimports/
---- __init__.py
---- helloimports.py

And helloimports/__init__.py would have the line from .helloimports import *

This would also be a situation where console_scripts in setup.py looks like helloimports=helloimports:main

Personally I perfer to have my main module file named the same as the package and I don't like putting tons of code in __init__.py but I also see the argument that the execessive chaining with the same name can get confusing. So I think I will try the #3 approach for now unless someone can prove to me that placing all your code in __init__.py is better. I would much rather think of __init__.py as being a simple file that defines a package not as being the file that contains all the code. If i'm searching for the main code in a python project it makes more sense to me to open up a projectname.py file than a __init__.py file that could technically be blank.

tl;dr - It's working for me now, I am still potentially violating best practices but at least now I can directly break or fix the imports in a way that makes sense to me. I've uploaded the new version of the project as a separate repo here so that it's easy to see the changes between the 2 versions:

https://github.com/thetalentedmrpeanut/helloimports2

Top answer
1 of 2
2
TL;DR ... add a single . before subdir: from .subdir.module1 import ClassName1 Long version; well, you've got a wee bit of a confusing directory structure there, so let's assume you're in your home directory (~/) and you create your fancy new Python package, which were going to call foo. foo/__init__.py The contents of which will be: from bar import neep print(neep) And inside it we'll add a sub package, which we'll call foo.bar: foo/bar/__init__.py The contents of which will be: neep = "Neep!" Now, your current directory is considered a part of your PYTHONPATH, so you can try this: import foo But you'll hit an ImportError. Why? When several tutorials on the Internet imply this should work fine? Because you're in Python3, and those people were on Python2. Change the first line of foo/__init__.py to: from .bar import neep ... and importing foo will suddenly work. See ONLY packages/files within a directory that's on the PYTHONPATH are directly importable in Python3, which uses absolute imports to avoid ambiguities that were always a problem in Python2. So your foo package is importable, but the first thing foo does is imports bar, and you can check your whole PYTHONPATH (and the current working directory, that's implicitly the last item on the PYTHONPATH), and you'll find there isn't a single package named bar in any of those directories, except the one nested inside foo. Which is why foo must make an explicitly relative import using the .syntax, where the dot basically says "from the directory I'm in, import bar..." instead of "from the first directory you find it in on the PYTHONPATH, import bar..." Now, for exactly the reasons described above if you cd'd into foo you could indeed launch and interactive session and import bar, because at that point it would be within a directory that was implicitly on your PYTHONPATH, see?
2 of 2
2
You're throwing a lot of trouble your own way by reusing names. Change the contents of helloimports.__init__.py to: import helloimports.helloimports as helloimports And it should work, but notice how bloody confusing it's getting? The problem still comes down to exactly what I was describing before. Your helloimports package is the only thing directly on your PYTHONPATH. So when your bin script says: import helloimports It means import the helloimports package ... when you import a package (which is a directory containing an `__init__.py) the only thing that automatically happens is an import of that file. So, inside that helloimports.__init__.py you do this: import helloimports Which is again an absolute import, so it imports the only thing named helloimports that is on your PYTHONPATH. Which is itself. It does not, in any way, import the file with the same name sitting beside it. Now, your bin script continues with: helloimports.helloimports.main() This should fail with an AttributeError complaining that there is no attribute "main". You can see that there is no such attribute by changing your bin script to read: import helloimports print(dir(helloimports)) In fact if you want to see some fun, try this: import helloimports print(dir(helloimports.helloimports.helloimports.helloimports)) That's happening because your package is importing itself, which contains only itself, which contains only itself, ad infinitum. Now, if you change the line in your helloimports/__init__.py to read: import helloimports.helloimports as helloimports You're explicitly adding the namespace of the helloimports/helloimports.py file to the package itself. Which allows your bin file to access the main method. Since your relative imports are now correctly relative, they should work. You could save yourself a lot of trouble by just renaming this file: helloimports/helloimports.py To: helloimports/__init__.py And changing your bin file to instead do: import helloimports helloimports.main() In general you know you're going down a bad path whenever you see someword.someword, especially if it's in a someword.py file.
🌐
Python.org
discuss.python.org › python help
How does one fix an import error like the following? - Python Help - Discussions on Python.org
November 24, 2023 - How does one fix an import error like the following · It does seem like the same problem. I assume the fix the OP reported there was a false diagnosis and starting over is clearer · Python is often run (by your IDE, for example) in a virtual environment. These are useful for isolating what ...
🌐
Home Assistant
community.home-assistant.io › share your projects! › scripts
Import in python - Scripts - Home Assistant Community
July 20, 2017 - Hello, I am trying to retrieve data from a JSON API. It all works fine on my local machine but I need to import some stuff. The problem is that HA returns an error when I try to import. Is this restricted or maybe working in a diffrent way? I’m not very experienced with Python but I know ...
🌐
PyInstaller
pyinstaller.org › en › stable › when-things-go-wrong.html
When Things Go Wrong — PyInstaller 6.22.3 documentation
Hidden imports can occur when the code is using __import__(), importlib.import_module() or perhaps exec() or eval(). Hidden imports can also occur when an extension module uses the Python/C API to do an import. When this occurs, Analysis can detect nothing. There will be no warnings, only an ImportError at run-time.
🌐
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, ...
🌐
Frappe
discuss.frappe.io › erpnext › customize erpnext
Import Error in Server Script Written Under a DocType - Customize ERPNext - Frappe Forum
August 10, 2023 - Hello there, I am working on customizing ERPNext and I have a custom DocType created called “Coffee Gathering Receipt”. And this DocType has a field called “total_price” which stores the total price of the coffee that is going to be store in warehouse.