So I am pretty new with Python. I've been working on running with a code similar to one I hope to build myself (so a reference code). Aside from some bugs I need to work out with invalid syntax, all seems to work except for one issue with one particular .py file I have.
My structure is this:
MoodForecasting -> eval -> nsga_two.py
I do have _init_.py in eval folder though, so I'm not sure why this block of code isn't working.
I am trying to load one particular fucntion from it, so the structure should look like this
from nsga_two import PatientProblem
Unfortunately, I keep getting the error ModuleNotFoundError: No module named 'nsga_two'.
I checked nsga_two.py itself and found that it couldn't load inspyred. I went in and was able to fix this. So, nsga_two.py runs fine on its own. However, I cannot import it into the main script I will be working with.
Some extra details: I am working with the IDE Spyder with Python Custom Version 3.7.9.
I'm not sure if it is an issue with Spyder or just how I am loading in my working directory. (Most of my coding experience is in MatLab and R so having an IDE similar to RStudio and MatLab is the reason I chose to work in Spyder)
Edit:
I got a syntax error when using from eval import nsga_two.PatientProblem. Python didn't like the period. So, I instead tried it with no period. I got the error cannot import name 'nsga_twoPatientProblem' from 'eval' (C:\Users\name\Desktop\MoodForecasting-master\MoodForecasting-master\eval\__init__.py). I don't know why. But doing from eval import nsga_two works. nsga_two.py only consists of PatientProblem. This solve should be ok for this purpose. I'm just not sure why this could be happening.
from eval import ngsa_two.PatientProblem(although assuming 'eval' is directory I strongly suggest change it to something more innocuous).from eval import ngsa_two.PatientProblem. Python didn't like the period. So, I instead tried it with no period. I got the errorcannot import name 'nsga_twoPatientProblem' from 'eval' (C:\Users\name\Desktop\MoodForecasting-master\MoodForecasting-master\eval\__init__.py). I don't know why. But doingfrom eval import ngsa_twoworks.ngsa_two.pyonly consists ofPatientProblem. So this should be ok for this purpose. Like I said, this is a reference code so I haven't named any of these folders but will changensga_twoorngsa_twois the correct module name? Are you importing with wrong name which raise the error? Where is your main script located?nsga_two. The main script is located in a folder called MoodForecasting which contains other folders such as eval which have other.pyfiles in them.from eval import ngsa_twoworks then what you want isfrom eval.ngsa_two import PatientProblem. You will want to read up on the syntax and semantics of the Pythonimportstatement. The suggestion in the first comment is not and has never been syntactically valid in Python.