问题
I've install the module Astropy for Python in mac using:
pip install --user astropy
It works when I installed but when I execute this code I have an error.
import astropy
astropy.test()
This is the error
Traceback (most recent call last):
File "/Users/JanPolRoig/Documents/astropytest.py", line 1, in <module>
import astropy
ModuleNotFoundError: No module named 'astropy'
Why is this happening?
回答1:
With the Python executable you're using, try installing it as follows:
python -m pip install --user astropy
It is likely the pip
you're using does not match the python
you're using.
回答2:
Check your PYTHONPATH
environment variable. After pip installation with --user
option, astropy could be stored in a directory like ~/.local/lib/python3.6/site-packages/
.
In bash you can do
export PYTHONPATH=$HOME/.local/lib/python3.6/site-packages/
You can include this line in the ~/.bashrc file.
回答3:
I faced this problem when I installed the updates for my "macOS Catalina". I'm using anaconda for python3. and I had to re-install it again. The problem is that some of the installation packages like ".matplotlip" or ".astropy" remain in the home directory (hidden) and when you load them instead of your anaconda path it goes to the location of these temporary files. I solved it by simply deleting them using
rm -r .matplotlib
and similar packages in my home directory. I was using astropy for the "LightKurv" package.
来源:https://stackoverflow.com/questions/50554094/no-module-named-astropy