0

I have a project structure like this:

/adapters/adapter.py
/blockchain.py
/venv

#adapter.py  
from blockchain import Blockchain
class Adapter():
    pass

#blockchain.py
class Blockchain():
    pass

contains from blockchain import Blockchain blockchain.py would is like class Blockchain(): pass

Now from adapter.py I want to import the class Blockchain which is located in blockchain.py

I am using python 3.6.6 (using venv) and I never had any problems doing that until today when I moved some stuff with init files into the project. I deleted all the files and pulled from the repo to make sure its exactly like before when it was working but I am getting

no module named "blockchain"

I don't have any init files in my project and it worked for 2 weeks without a problem which is very strange. I know there are a lot of similar posts already, most of them suggesting to use init files, but I am very confused why it worked before and but anymore.

My sys.path is like this (bcios-master is the root folder):

['', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Users/timo/Documents/bcio-master/venv/lib/python3.6/site-packages']

Somehow if I try to append it doesn't save it.

solaire
  • 475
  • 5
  • 22
  • We need to see the full code of what you're trying to do, which I assume is just the `import` section near the top? – UtahJarhead Oct 25 '18 at 15:04
  • Append your base directory to your python path with `sys.path.append` - you'll be able to do `import blockchain` after that. – Rocky Li Oct 25 '18 at 15:05
  • Is there a file named `__init__.py` in the directory of the file `blockchain.py`? – Sven-Eric Krüger Oct 25 '18 at 15:12
  • Show us the contents of `sys.path` inside of your program, please. and show us the `class Blockchain()` line from `blockchain.py`, please. – UtahJarhead Oct 25 '18 at 15:14
  • thx for the responses, I added the infos you asked for – solaire Oct 25 '18 at 15:25
  • @SvenKrüger no, no init files, but it worked before without any so I hope I can avoid them – solaire Oct 25 '18 at 15:26
  • 1
    https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path – Pitto Oct 25 '18 at 15:57
  • @Pitto i can do `import sys sys.path.append('/Users/timo/Documents/bcio-master')` and then it works but then I would need this in every file. Seems strange that it worked before without it... – solaire Oct 25 '18 at 16:04
  • So my conclusion until now is that somehow it automatically set the pythonpath to my project root when I created the folder or venv. And apparently now its not there anymore – solaire Oct 25 '18 at 16:28

0 Answers0