简体   繁体   English

无法在python中导入破折号

[英]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.还要检查一下,我尝试在终端中从 python 导入破折号,令人惊讶的是我可以在终端中导入破折号,其中目录不包含带有破折号导入的 .py 文件,而如果任何文件中包含导入破折号,我不能在该目录的终端中导入破折号。 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.我遇到了完全相同的错误消息,并确保文件夹中没有任何 dash.py 文件。

However, there was a plotly.py file and renaming it solved the problem for me.但是,有一个 plotly.py 文件并重命名它为我解决了问题。

See this thread from the official Dash github repo.从官方 Dash github 存储库中查看此线程 In my case, it was a file named test.py .就我而言,它是一个名为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在您使用的目录中的某处有一个名为 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."不确定是否有人会遇到它,基本上我在 Mac OS - Mojave 中都可以使用它,但是在更新到 Catalina 后“Dash 没有成功导入。确保你当前没有名为“dash.py”的文件目录。”

I can do import dash successfully at python prompt but strangely my program that worked fine in Mojave, threw above error.我可以在 python 提示符下成功导入破折号,但奇怪的是我的程序在 Mojave 中运行良好,抛出了上述错误。

I fixed it by我修好了

  1. pip uninstall dash pip卸载破折号
  2. pip install dash pip 安装破折号

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.为了分享我的经验,我在我的工作目录中创建了一个名为copy.py的文件 - 我知道这不是最好的名字 - 我开始遇到这个问题。 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 .此外,该目录中曾经可以工作的所有其他文件都停止工作并给出了关于dash的相同错误。

Renaming that file, copy.py to something else solved it for me.重命名该文件,将copy.py改为其他内容为我解决了这个问题。 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.我没有dash.py并且被吓倒了。 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问题是我有一个import pickle的声明,文件名是pickle.py

As a rule of thumb, try not to have the filename as根据经验,尽量不要将文件名设为

  1. same name of any import module任何import module same name
  2. do not use test.py as pointed out by many answers.正如许多答案所指出的那样,不要使用test.py
  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.即使错误仍然存​​在(因为您的文件名可能与其他一些依赖项类似 - 例如 plotly),请尝试在末尾提供一些任意数字,例如file121.pyfile.py并查看它是否有效。

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. “导入破折号”可能与模块破折号(您可能已经安装了它,因为它基于 plotly)和该目录中名为“dash.py”的另一个文件存在冲突。

Try renaming dash.py to another file and see if that solves anything.尝试将 dash.py 重命名为另一个文件,看看是否能解决任何问题。

I had the same issue on ubuntu, although it worked locally on my mac.我在 ubuntu 上遇到了同样的问题,尽管它在我的 mac 上本地运行。 Renaming dash folder to something else (webapp) in my case made the error go away.在我的情况下,将破折号文件夹重命名为其他内容(webapp)使错误消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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