Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Problems with importing modules in Python

$
0
0

So this problem took already so much time in my life that I would really much would like to solve this once and for all. I changed the directories in my project and now everything is broken again, so what is the best way to solve this? My structure is like this:

MYPROJECT|-- src    |   -- data       __init__.py       basic_script.py   -- utils      __init__.py      some_utils.py

basic_script.py needs some functions from some_utils.py. I import these with

'import utils.some_utils as some_utils

The root in my terminal is 'c:\some_path\MYPROJECT.I run the file with

'python src/data/basic_script.py'

Now I had everything working , but I changed the root directory and now I get the error:

ModuleNotFoundError: No module named 'utils'

So i can try to solve this over the coming hours, but I would like to know how to avoid this in the future:

  1. what exactly do I have to add to my python path?
  2. is this the way to solve this, or can it be done in a better way?
  3. If I transfer the whole project to a different system, what is the way to make it work again? Can this be done with a setup.py? If yes, how exactly?

My sys.path currently only contains all python versions and 'c:\projects\MYPROJECT\.venv'

thanks!


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>