Forums

Created new project directory - Cannot run truffle init inside it

Hi all, 1st timer here: I created new project directory called "hello_project' When I run truffle init on it i get the following error ImportError: cannot import name 'get_directory_tree' from 'filetools'


06:29 ~/vyper-venv/hello_project $ truffle init
Traceback (most recent call last):
  File "/home/Vyper/.local/bin/truffle", line 5, in <module>
    from truffle.app import main
  File "/home/Vyper/.local/lib/python3.9/site-packages/truffle/app.py", line 2, in <module>
    from filetools import get_directory_tree, get_scan_path, _get_name
ImportError: cannot import name 'get_directory_tree' from 'filetools' (/home/Vyper/.local/lib/python3.9/site-packages/filetools/__init__.py)

I look into the filetools file here:

https://www.pythonanywhere.com/user/Vyper/files/home/Vyper/.local/lib/python3.9/site-packages/truffle/filetools.py

and the code is here

def _get_directory_tree(path):
    """Helper function for get_directory_tree"""

    tree = {"name": path, "short_name": _get_short_name(path), "children": []}

How do you import name **get_directory_tree** ?

Thank you for your help. Bless You.

There's a different path shown in the traceback message: /home/Vyper/.local/lib/python3.9/site-packages/filetools/__init__.py -- it looks like you have a different package filetools on your Python path, so it's looking there first and it can't find the requested function.

Thank you for your response. Are you saying that the code

def _get_directory_tree(path):
    """Helper function for get_directory_tree"""

    tree = {"name": path, "short_name": _get_short_name(path), "children": []}

Must be located in the __init__.py file ?

Looking more closely at that error and code, I think there might be something more complicated going on here. In the error message, it says that it's trying to import a function called get_directory_tree. But in that file that you showed, the function is called _get_directory_tree. Note the extra underscore at the start. The comment there suggests that the one with the underscore is a helper function for the one without. The one without, I would expect, would be defined in the same file. Can you see it there?

If you can, then the problem is what @pafk says. You've installed truffle, which has a built-in package called filetools. But you've also installed a separate package called filetools, which is interfering with truffle.

*Thanks for your help ! ALMOST THERE :-)*

  • Blew away most of my files and installed nvm from root user acct
  • Installed npm and node from there
  • Upgraded acct to 5/a / month ( I think because Truffle needs more space to install )

Is your initial issue with the missing import solved then?