问题
I have installed both plotly.express
and pandas
using:
pip install plotly-express
and
pip install pandas
I have tried to import these modules into my program using
import pandas as pd
import plotly.express as px
however, I get a ModuleNotFoundError
for both these packages on run.
I have tried using alternate installs like:
py -3 -m pip install plotly-express
python -m pip install plotly-express
py -m pip install plotly-express
When I try install these packages again, they say that the requirement is already satisfied in c:\python38\lib\site-packages
. All my other packages are installed at C:\Users\Oli\AppData\Local\Programs\Python\Python38-32\Lib\site-packages
(I am Oli !).
I think this might be the issue. I've read that it is a bad idea to just stick in these files directly.
How can I get these imports to work?
回答1:
The first thing to do is to check that the directory C:\python38\lib\site-packages
is in your PYTHONPATH environment variable. If not, add it or create PYTHONPATH
as environment variable if it doesn't exist and add the directory (for Windows, Start -> type "Edit Environment Variables for your Account").
Alternatively, try the following:
import sys
sys.path.insert(0, 'C:\python38\lib\site-packages')
import pandas as pd
回答2:
This seems to be a path problem. Have you updated py recently in your machine? I once had a problem like this after updating, I could only solve it by completely uninstalling all versions first then reinstalling all from scratch. A bit of work, sure, but at least for me solved like a charm!
来源:https://stackoverflow.com/questions/65384294/cannot-import-python-modules-despite-having-installed-them