0

I am building a yolo model using pytorch, but I would like to build an activation function by myself.

I need to import module.py to my own function. So I write from .modules import Module and run. It returns me attempted relative import with no known parent package.

This is the file location of my yolo:

C:/Users/Lenovo/.spyder-py3/yolo.py

This is the file location of the module.py that I want to call:

C:/Users/Lenovo/anaconda3/Lib/site-packages/torch/nn/modules/module.py

I have tried to rewrite the import statement as below:

__import__("C:/Users/Lenovo/anaconda3/Lib/site-packages/torch/nn/modules/module.py").Module

It also returns me the same import error. My understanding is that because in the module.py, there is an import statement from ..parameter import Parameter, where the .. refers the module.py to C:/Users/Lenovo (instead of C:/Users/Lenovo/anaconda3/Lib/site-packages/torch/nn).

My question is, what should I do to import the Module and use it in yolo.py for my own use, without having import error?

  • [This question](https://stackoverflow.com/questions/63312692/importerror-attempted-relative-import-with-no-known-parent-package) may help you. – aretor Mar 17 '22 at 20:04
  • Thanks for your help, it really helps me a lot. Seems that I can only do that with a shared package... or I have to create one extra python files in that package for my own use. – Hoi Man Hyman LAI Mar 18 '22 at 11:24

0 Answers0