Python:"ModuleNotFoundError",但已安装模块?
我意识到这似乎是一个通用问题,但是所有答案都指向同时安装两个python
-我已经卸载了另一个.
I realize this seems like a generic question, but all answers pointed to having two simultanious python
installations - I already uninstalled the other one.
当前,我从 PyCharm 2017.1.5 (Windows 10)运行代码,并将Python解释器设置为Python 3.6.1 (C:\Anaconda3\python.exe)
,即我安装了 Anaconda3 ,其中包括
Currently I run my code from PyCharm 2017.1.5 (windows 10) with Python interpreter set as Python 3.6.1 (C:\Anaconda3\python.exe)
, i.e. I installed Anaconda3, which includes the matplotlib
, and run from PyCharm using the Ananconda3-interpreter.
我已经在 Anaconda Navigator 中检查到环境中已安装matplotlib 2.0.2
.
I've checked in Anaconda Navigator that matplotlib 2.0.2
is installed in the environment.
一个最小的(无效)示例:
A minimal (non-working) example:
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.show()
返回以下错误:
C:\Anaconda3\python.exe C:/Users/John/Documents/CPU/master/untitled/main11.py
Traceback (most recent call last):
File "C:/Users/John/Documents/CPU/master/untitled/main11.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 29, in <module>
import matplotlib.colorbar
File "C:\Anaconda3\lib\site-packages\matplotlib\colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "C:\Anaconda3\lib\site-packages\matplotlib\collections.py", line 37, in <module>
import matplotlib.lines as mlines
File "C:\Anaconda3\lib\site-packages\matplotlib\lines.py", line 28, in <module>
from matplotlib.markers import MarkerStyle
ModuleNotFoundError: No module named 'matplotlib.markers'
Process finished with exit code 1
2周前运行良好,但现在不行.据我所知,我没有更改或更新任何内容.该模块已正确加载,但似乎是模块内容的变化?如果是这样:那是怎么发生的,我该如何解决?
This ran fine 2 weeks ago, but not now. To my knowledge, I didn't change or update anything. The module loads correctly, but it seems to be a change in the module content? If so: How did that happen and how can I fix it?
@ImportanceOfBeingErnest使我朝着正确的方向前进.我在这里发布我的解决方案其他人可能会找到答案.问题在于磁盘扇区已损坏-不太可能发生的偶然事件.
@ImportanceOfBeingErnest lead me in the right direction. I post my solution here s.t. others may find the answer. The problem was a corrupted disk sector - an unlikely event of chance.
问题确实出在matplotlib
-package本身.追溯地,指向该问题的指针是预分发的程序包中的错误不应该存在.如果是这样,则外部环境一定已经损坏,问题不在于Python安装本身.
The problem was indeed in the matplotlib
-package itself. Retrospectively, pointers to the issue were that errors in pre-distributed packages should not exist. If they do, external circumstances must have corrupted and the problem is not with the Python-installation itself.
我通过 Anaconda Prompt 用conda remove matplotlib
卸载了matplotlib
,然后用conda install matplotlib
重新安装了.这给了我这个错误:
I uninstalled matplotlib
through Anaconda Prompt with conda remove matplotlib
and re-installed with conda install matplotlib
. This gave me this error:
(C:\Anaconda3) C:\Users\John>conda install matplotlib
[...]
ERROR conda.core.link:_execute_actions(337): An error occurred while installing package 'defaults::matplotlib-2.0.2-np112py36_0'.
OSError(22, 'Invalid argument') Attempting to roll back.
OSError(22, 'Invalid argument')
在@Ernest发表评论之前,我认为它可能与
Before @Ernest's comment, I thought it maybe had to do with non-ASCII in PATH
or similar.
相反,我尝试完全重新安装 Anaconda3 ,然后重新启动,发现没有删除Anaconda3-folder的一部分(包含matplotlib
的那一部分).
Instead I tried to reinstall Anaconda3 completely, restarted and found that part of the Anaconda3-folder weren't removed (the one containing the matplotlib
).
手动删除它会出现Windows错误0x80070570
.跟随
Deleting it manually gave a Windows error 0x80070570
. Following this post on ServerFault (the comment to OP) I ran a check and afterwards a repair from Windows Explorer GUI: Right-click on the drive in This PC --> Properties --> Tab Tools --> Check (repair appears if any errors are found).
一些重新启动后,从头重新安装 Anaconda3 并再次重新启动,我能够再次运行我的项目!
After some restarts, reinstalling Anaconda3 from scratch and restarting again, I was able to run my project again!