0

I've got a project and my files are structured in this way:

-signals (folder)
      |--movingaverage (folder)
              |--movingaverage.py
-main2.py
-helper (folder)
      |--csvmanager.py

code in: main2.py

from signals.movingaverage.movingaverage import *

print("start")
get_ma_chart_plotpoint()

code in: movingaverage.py

def get_ma_chart_plotpoint():
    print("hello from get_ma_chart_plotpoint")

code in: csvmanager.py

import csv
def say_hello_csv():
    print("hello from say_hello_csv")

When I run the main2.py I get this error message from the console:

runfile('E:/Coding/Repos/Tr.Py.Candlestick.DbFetcher/main2.py', wdir='E:/Coding/Repos/Tr.Py.Candlestick.DbFetcher')
Traceback (most recent call last):

  File "E:\Coding\Repos\Tr.Py.Candlestick.DbFetcher\main2.py", line 1, in <module>
    from signals.movingaverage.movingaverage import *

ModuleNotFoundError: No module named 'signals.movingaverage.movingaverage'

I'm running the program from main2.py. Is my import definition in main2.py not correct? what is wrong with it?

The odd thing is that when I change the main2.py to call a function in csvmanager.py file it works. Can't understand why? I've basically imported it in the same way.

update main2.py

from helper.csvmanager import *

print("start")
say_hello_csv()
Carlo Luther
  • 2,402
  • 7
  • 46
  • 75
  • That would depend on the Python compiler you are using. If you are running on a more complex one, that depends on a base folder, you would have to use the parent folder, to include both. Optionally, you can add the signals to the PythonPath Environment Variable – GiodoAldeima Sep 20 '20 at 13:38
  • @GiodoAldeima can you please check my updated question. If I do an import for another py file it works. can' understand why – Carlo Luther Sep 20 '20 at 13:53
  • Check if [this](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder) is usefull to you: Your import definitions seem ok – GiodoAldeima Sep 21 '20 at 14:22

0 Answers0