Python Forum

Full Version: ImportError: No module named
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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?
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.
If function PSO in MFO.py, you can try:
from .optimizers.MFO import PSO as pso