No module named 'dash' - but dash latest version is installed
已回答
I have verified that I has dash latest version and I've installed it in Pycharm after the pip install. In pycharm I've tried running the script both with venv and with a system interpreter (Python 3.11). I have also tried rebooting the machine.
No matter what I do, I have been stuck for hours getting an error when simply trying to 'import dash'.
import dash
ModuleNotFoundError: No module named 'dash'
Process finished with exit code 1
请先登录再写评论。
It doesn't seem to be related to PyCharm, as it's Python that cannot find it, not PyCharm.
Make sure you installed it into the same environment that you use in PyCharm. You can use PyCharm's interface to manage packages https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html
Hi Sergey
Thanks for the inputs.
I think indeed it is a PyCharm specific issue. When I run the file through CMD directly it runs just fine.
In PyCharm's interface I have tried uninstalling and reinstalling dash, and as mentioned also running the file through a venv and a system interpreter.
The bottomline is I can't make dash run through Pycharm, but it runs outside Pycharm.
One thing that surprises me is that when I click install inside Pycharm I'll get a lille notification confirming the install, but after that I can still click 'install package' - I would assume that button should change after the install.
Do you see it in PyCharm among the installed packages?
Yes indeed:
Could you run the following code with the same interpreter both in PyCharm and in the command line and provide the outputs?
Yes absolutely. The output is very long. But see it below.
Running in CMD:
Running in PyCharm:
Hmm, interesting, so the package is seen in both cases.
Could you create a new project with a new virtual environment, install dash, and try importing it there?
Does it work?
Good idea. I had not tried that, but I did just now.
Turns out in the new project it works both via the system interpreter (3.11) and via venv!
The most surprising part to me is that from the start I tried running the file both via both venv and the system interpreter - so the latter works in one project but not in another!
We can try a few more things:
1. Remove the run configuration (Run | Edit Configurations...). Then right-click the file and choose Run from the context menu.
2. If the issue remains, try removing the .idea folder of the problematic project. It contains project-specific settings.
I have done a few reboots since and of course the above mentioned things.
It turns out today that dash runs fine from both files/projects - where as the other day it would only run from the new project.
Thanks again for your inputs. I'm not exactly sure what to take away from all of this. At least it's a reminder that sometimes it can help to restart Pycharm and/or Windows, and that copying the code to a new project can also be a fix.