Python Forum
ImportError: No module named
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ImportError: No module named
#1
Hello. I am facing the following error messages:

Error:
Traceback (most recent call last): File "optimizer.py", line 8, in <module> import optimizers.PSO as pso ImportError: No module named optimizers.PSO


when executing python optimizer.py

The file "optimizer" it is in the current directory, and there is a folder called "optimizers" where the file "MFO.py" lives. So what I am doing wrong?
Reply
#2
When you post a question don't assume the reader (me) has any idea what you are talking about. PSO, MFO mean nothing to me (particle swarm optimization?). Should they? Is PSO a module or is it something that is defined in a module?

The message says that there is no file name optimizers/PSO.py and no file named optimizers.py that defines something named PSO. What are you expecting? What is in the optimizers folder?
Reply
#3
Quote: Is PSO a module or is it something that is defined in a module?

It is a file with a function
def PSO
inside of it

Quote:What are you expecting?

That the file "optimizer.py" runs because there is a "PSO.py" inside the "optimizers" folder

Quote:no file named optimizers.py

This file has a
import optimizers.PSO as pso
inside it, I should have mentioned it.
Reply
#4
If function PSO in MFO.py, you can try:
from .optimizers.MFO import PSO as pso
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  no module named 'docx' when importing docx MaartenRo 1 705 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Problem with pymodbus - ModuleNotFoundError: No module named 'pymodbus.client.sync' stsxbel 2 22,929 Nov-02-2023, 08:20 AM
Last Post: South_east
  ModuleNotFoundError: No module named 'requests' Serg 18 2,156 Oct-29-2023, 11:33 PM
Last Post: Serg
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,306 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,388 Aug-07-2023, 05:32 AM
Last Post: DPaul
  ModuleNotFoundError: No module named 'eyed3' Wimpy_Wellington 2 1,221 Jul-10-2023, 03:37 AM
Last Post: Wimpy_Wellington
  How to fix this error: ModuleNotFoundError: No module named 'notears' yaoyao22 2 960 Jul-09-2023, 11:24 AM
Last Post: yaoyao22
  Help with pyinstaller "No module named" korenron 9 8,180 Jun-15-2023, 12:20 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 932 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  ModuleNotFoundError: No module named 'omsdk.sdkproto' donvito7 4 1,769 Oct-20-2022, 02:56 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020