我意识到这似乎是一个通用问题,但所有答案都指向同时安装两个 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:Anaconda3python.exe)
,即我安装了 Anaconda3,其中包括 matplotlib
,并使用 Anaconda3-解释器从 PyCharm 运行.
Currently I run my code from PyCharm 2017.1.5 (windows 10) with Python interpreter set as Python 3.6.1 (C:Anaconda3python.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:Anaconda3python.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:Anaconda3libsite-packagesmatplotlibpyplot.py", line 29, in <module>
import matplotlib.colorbar
File "C:Anaconda3libsite-packagesmatplotlibcolorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "C:Anaconda3libsite-packagesmatplotlibcollections.py", line 37, in <module>
import matplotlib.lines as mlines
File "C:Anaconda3libsite-packagesmatplotliblines.py", line 28, in <module>
from matplotlib.markers import MarkerStyle
ModuleNotFoundError: No module named 'matplotlib.markers'
Process finished with exit code 1
两周前运行良好,但现在不行.据我所知,我没有改变或更新任何东西.模块加载正确,但似乎是模块内容发生了变化?如果是这样:这是怎么发生的,我该如何解决?
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
包本身.回想起来,问题的指针是预分发包中不应该存在错误.如果是这样,则外部环境一定已损坏,问题不在于 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:UsersJohn>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 发表评论之前,我认为这可能与 非 ASCII 在 PATH
或类似的.
Before @Ernest's comment, I thought it maybe had to do with non-ASCII in PATH
or similar.
相反,我尝试完全重新安装 Anaconda3,重新启动后发现部分 Anaconda3 文件夹没有被删除(包含 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
.关注 ServerFault 上的这篇文章(对 OP 的评论) 我进行了检查,然后从 Windows Explorer GUI 进行了修复:右键单击 This PC 中的驱动器 --> Properties --> Tab Tools --> Check(如果发现任何错误,repair就会出现).
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!
这篇关于Python:“ModuleNotFoundError",但安装了模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!