简体   繁体   English

Mac osx 上的 PyCharm ModuleNotFoundError: No module named

[英]PyCharm on Mac osx ModuleNotFoundError: No module named

idle PyCharm os Mac osx python 2.7 python3空闲 PyCharm os Mac osx python 2.7 python3

Coding with PyCharm this error showed up..使用 PyCharm 进行编码时出现此错误。

ModuleNotFoundError: No module named 'numpy', same with matplotlib and other ones. ModuleNotFoundError: 没有名为“numpy”的模块,与 matplotlib 和其他模块相同。

Any solution?有什么解决办法吗?

already changed interpreter to python3 it is working on bash terminal both python 2.7 and python3已经将解释器更改为 python3 它正在 bash 终端上运行 python 2.7 和 python3

import datetime as dt
import numpy
import matplotlib as plt
from matpololib import style
import pandas as pd
import pandas_datareader.data as web

style.use('ggplot')

assume that you're using macOS with pyenv for different python versions.假设您将 macOS 与 pyenv 一起用于不同的 Python 版本。

Take the matplotlib stacked bar graph bar_stacked.py as the example (you could get the .py from https://matplotlib.org/gallery/lines_bars_and_markers/bar_stacked.html#sphx-glr-gallery-lines-bars-and-markers-bar-stacked-py ).就拿matplotlib堆积条形图bar_stacked.py为例(你可以得到.pyhttps://matplotlib.org/gallery/lines_bars_and_markers/bar_stacked.html#sphx-glr-gallery-lines-bars-and-markers-条形堆叠py )。

short answer: quickly configure pyenv python as this snapshot shows:简短回答:快速配置 pyenv python,如该快照所示:

quick config steps快速配置步骤

details细节

  1. open the bar_stacked.py with PyCharm;用 PyCharm 打开 bar_stacked.py;

  2. check your python environment settings:检查您的python环境设置:

    • 2.1 check your python version with your terminal: 2.1 用你的终端检查你的python版本:

ABC-MacBook-Pro:~ ABC$ which python /Users/ABC/.pyenv/shims/python

  • 2.2 check your pyenv installed pythons 2.2 检查你的pyenv安装的pythons

ABC-MacBook-Pro:~ ABC$ pyenv versions system * 3.7.0 (set by /Users/ABC/.python-version)

  • 2.3 confirm the python version you're using, here is Python 3.7.0 2.3 确认你使用的python版本,这里是Python 3.7.0

ABC-MacBook-Pro:~ ABC$ python --version Python 3.7.0

3.configure the PyCharm interpreter as follows: 3.配置PyCharm解释器如下:

  • 3.1 PyCharm -> Preferences -> Project -> Project Interpreter , you'll see a icon like a gear, click it and choose Add... 3.1 PyCharm -> Preferences -> Project -> Project Interpreter ,你会看到一个像齿轮的图标,点击它并选择Add...

  • 3.2 choose Virtualenv Environment on the left 3.2 选择左侧的Virtualenv Environment

  • 3.3 choose Existing environment on the right, in the pop-up, locate the python i'm using as checked in step 2.1, here is /Users/ABC/.pyenv/shims/python 3.3 选择右侧的Existing environment ,在弹出的窗口中,找到在步骤 2.1 中检查的我正在使用的 python,这里是/Users/ABC/.pyenv/shims/python

  • 3.4 you can also check the box Make available to all projects if you want 3.4 如果需要,您还可以选中“ Make available to all projects ”框

finally, this example in PyCharm runs like this:最后,PyCharm 中的这个例子是这样运行的:

running跑步

Have you noticed the information of the popup when your mouse is hovering over the red waved underline?当您的鼠标悬停在红色波浪下划线上时,您是否注意到弹出窗口的信息? Just click "install matplotlib".只需单击“安装 matplotlib”。 Then it's ok.然后就没事了。

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

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