Fail to import dash

After running the code, it shows the message of: “Fail to import DASH, make sure there is no same file dash.py in this directory”.
This code is able to run on my another PC. the difference is I install dash and other components by using tar.gz file instead of install directly by “pip install dash”.

Can you see dash listed when you type

python -m pip list

?

yes, i checked, there is dash (version 1.13.4) in the list

do you have a python file called “dash.py” where you have written code?

Also check if you have a folder called dash among your python code. (More specifically, inside a folder listed in sys.path, apart from the dash in your site-packages)

Here’s a small script that can tell that if there are more than one dash folder or dash.py files in your PATH:
(save as for examplefinddash.py in same folder as your app.py and run)

from pathlib import Path
import sys

results = []


def get_dash_files_and_folders(rootfolder, results):
    for item in rootfolder.glob('*'):
        if item.name == 'dash.py':
            results.append(item)
        if not item.is_dir():
            continue
        if item.name == 'dash':
            results.append(item)
    return results


for item in sys.path:
    item = Path(item)
    if not item.is_dir():
        continue
    results = get_dash_files_and_folders(item, results)

if results:
    print('Found following files & folders:')
    print(results)
else:
    print('No dash found in sys.path!')

I only found the dash.py under: C:/users/XX/Anaconda3/lib/site-packages/dash
this is not the same folder I ran the app.py, and similar dash.py exist on my another laptop, but I am able to run in that one…

Thank you very much!

Like @fohrloop said, it’s probably because your have a dash.py file or a dash folder somewhere. Those should have different names because they are confusing the system. I would recommend using a separate virtual environment for your project.

Try this tutorial to start.

If you’re not interested in using JupiterDash, just watch the first part.

Thank you for your suggestion, and training video
I tested virtual environment today, and found following:

  1. With following sentence I still have the warming of "Dash was not successfully imported. Make sure you dont have a file named “dash.py” in your current directory. Tried the finddash code and find dash.py under the site-packages folder only
    import dash
    import dash_core_components as dcc
    import dash_html_components as html

  2. But if I have only: “import dash” in my code (delete import dcc and html), it will show only that: name ‘html’ is not defined…

We’re getting some other reports that this may be version dependent and introduced in 1.13.x. We are so far unable to reproduce on our end.

@jie - Could you try downgrading to 1.12.0 or 1.11.0 and see if the error remains? If so, then this a bug with something we did recently rather than the dash.py-style of issue that we usually see.

Thanks to everyone who is helping out diagnose this issue!

Hi, I downgrade dash to version 1.10.0, and it works now. Thank you very much!!

You may have a test.py in your directory. I had one and got the same error. I removed it and it works fine.

hi, thank you for your suggestion. I downgrade the Dash to lower version, it works.