简体   繁体   中英

PyCharm on Mac osx ModuleNotFoundError: No module named

idle PyCharm os Mac osx python 2.7 python3

Coding with PyCharm this error showed up..

ModuleNotFoundError: No module named 'numpy', same with matplotlib and other ones.

Any solution?

already changed interpreter to python3 it is working on bash terminal both python 2.7 and 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.

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 ).

short answer: quickly configure pyenv python as this snapshot shows:

quick config steps

details

  1. open the bar_stacked.py with PyCharm;

  2. check your python environment settings:

    • 2.1 check your python version with your terminal:

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

  • 2.2 check your pyenv installed 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

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

3.configure the PyCharm interpreter as follows:

  • 3.1 PyCharm -> Preferences -> Project -> Project Interpreter , you'll see a icon like a gear, click it and choose Add...

  • 3.2 choose Virtualenv Environment on the left

  • 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.4 you can also check the box Make available to all projects if you want

finally, this example in PyCharm runs like this:

running

Have you noticed the information of the popup when your mouse is hovering over the red waved underline? Just click "install matplotlib". Then it's ok.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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