简体   繁体   中英

Unable to import dash in python

I am unable to run any dash program. I get the error.

Dash was not successfully imported. Make sure you don't have a file named
'dash.py' in your current directory.

Also to check it out, I tried importing dash from python in terminal, surprisingly I can import dash in terminal where the directory don't contain .py file with dash import, whereas if any file contains import dash in it, I can't import dash in terminal in that directory. The attached picture will help you. 在两个不同的终端、两个不同的目录中导入破折号

当我将文件名从 test.py 更改为 test2.py 时,我的问题解决了,我希望它对您有用。

I faced the same exact error message, and I made sure there wasn't any dash.py file in the folder.

However, there was a plotly.py file and renaming it solved the problem for me.

See this thread from the official Dash github repo. In my case, it was a file named test.py .

The error you are receiving tells you everything you need to know. Somewhere in the directory you are using there is a file named dash.py

Find it and remove it / or rename it and it should clear up your error.

Not sure if anyone will face it, basically I had it all working in Mac OS - Mojave, but after updating to Catalina "Dash was not successfully imported. Make sure you don't have a file named 'dash.py' in your current directory."

I can do import dash successfully at python prompt but strangely my program that worked fine in Mojave, threw above error.

I fixed it by

  1. pip uninstall dash
  2. pip install dash

To share my experience, I created a file named copy.py in my working directory - I know it is not the best name - and I started getting this issue. I was confused since I didn't install any new packages. Also, all other files in that directory, which used to work, stopped working and gave the same error about dash .

Renaming that file, copy.py to something else solved it for me. I am not sure if there's a list of preserved file names which will create this issue.

The error message is quite meaningful. I had no dash.py and was intimidated. The other answers were meaningful but didn't solve my problem. I'm very late to the party but just documenting a generalized way to debug as it might help someone in the future.

The problem was I had a statement of import pickle and the name of the file was pickle.py

As a rule of thumb, try not to have the filename as

  1. same name of any import module
  2. do not use test.py as pointed out by many answers.
  3. Even if the error persists (because your filename may be similar with some other dependencies - like plotly), try to give some arbitrary number at the end like file121.py from file.py and see if it is working.

Hope this solves the problem.

"import dash" might have a conflict with the module dash (and you might have that installed as it is based off of plotly) and another file named "dash.py" within that directory.

Try renaming dash.py to another file and see if that solves anything.

I had the same issue on ubuntu, although it worked locally on my mac. Renaming dash folder to something else (webapp) in my case made the error go away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM