Python 3.6环境下pandas_datareader.mstar模块缺失问题求助
Hey Jason, sorry you hit this snag while getting started with your stock research project—import errors can be super frustrating when you're just trying to learn and build something cool. Let's break down what's going on and fix this step by step.
First off, the key thing to know: pandas_datareader doesn't include a built-in mstar (Morningstar) module in its standard installation, even if you've confirmed the base library is installed. That's why you're seeing that error. Here are the most likely fixes tailored to your setup (Windows 10, Anaconda Python 3.6, PyCharm):
Step 1: Verify your PyCharm interpreter matches your Anaconda environment
Sometimes PyCharm uses a different Python interpreter than the one you installed packages into (especially with Anaconda). Let's double-check:
- Open PyCharm and go to
File > Settings > Project: [Your Project Name] > Python Interpreter - Look at the interpreter path at the top—make sure it points to your Anaconda Python 3.6 environment (e.g.,
C:\Users\YourName\Anaconda3\envs\your_env\python.exe) - Scroll through the installed packages list to confirm
pandas_datareaderis listed here. If not, click the+button, search for it, and install it directly in PyCharm.
Step 2: Install the dedicated Morningstar data reader package
There's a third-party package that adds Morningstar support to pandas_datareader. Try installing it via your command line (make sure you're using your Anaconda environment's pip):
pip install pandas-datareader-mstar
Note: Since Python 3.6 is no longer officially supported, this package might have compatibility issues. If you run into installation errors, you might need to either:
- Use an older version of the package (try
pip install pandas-datareader-mstar==0.1.0), or - Consider upgrading to a newer Python version (like 3.8+) if your project allows it—this will give you access to more up-to-date packages.
Step 3: Check if you need a custom mstar module
If you're following a tutorial or using code from someone else, they might have written a custom mstar.py module that isn't part of the standard libraries. In that case:
- Make sure the
mstar.pyfile is saved in your project's root directory (the same folder as your main script) - If it's in a different folder, add that folder to Python's path at the top of your script:
import sys sys.path.append("C:/path/to/folder/containing/mstar.py")
Step 4: Alternative: Use pandas_datareader's built-in data sources
If the above steps don't work, you can switch to using one of pandas_datareader's officially supported data sources for your stock research, like Yahoo Finance or Alpha Vantage. For example:
import pandas_datareader.data as web df = web.DataReader("AAPL", data_source="yahoo", start="2020-01-01", end="2023-01-01")
That should get you back on track with your project. Let me know if any of these steps need clarification!
内容的提问来源于stack exchange,提问作者Jason Vu

