-1

I've a Python program with the following structure:

sdk
  -> jobs
    ->release

In the release folde I have a script called my_release.py. In that I'm trying to import a property called PROPERTY_1 from sdk/__init__.py. I tried adding from sdk import PROPERTY_1. When I run the script I get ModuleNotFoundError: No module named 'sdk'. How do I import this?

runnerpaul
  • 5,942
  • 8
  • 49
  • 118
  • Possible duplicate of [Importing files from different folder](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder) – Gino Mempin Aug 13 '19 at 03:15

2 Answers2

1

Python looks for modules in sys.path by default. If you want to import modules from a specific path take a look at this: Importing files from different folder

Emiliano Ruiz
  • 412
  • 4
  • 16
  • "_looks for modules only in the same directory_". Not quite. It looks in directories listed in `sys.path`, which happens to include, by default, the directory where the script is run. See [The Module Search Path](https://docs.python.org/3/tutorial/modules.html#the-module-search-path). – Gino Mempin Aug 13 '19 at 03:13
  • Thanks for your correction, I modified my answer accordingly. – Emiliano Ruiz Aug 13 '19 at 12:57
0

You should not be in the correct working directory. Just check it with %pwd magic command from ipython

ivallesp
  • 2,018
  • 1
  • 14
  • 21