I have been stuck on a module not found error of python3.
I have a VM on Microsoft Azure, a Centos 7. Then I installed python3 and pip3, and some packages I needed. But there’s one package that I just couldn’t find after I installed it
sudo pip3 install --user stockstats
But whenever i wanted to run a python script using this package, there’s
ModuleNotFoundError: No module named 'stockstats'
What I tried:
pip3 show stockstats
As I really want to see where it was installed. It shows nothing. What it is supposed to do is like this:
Name: openpyxl
Version: 3.0.7
Summary: A Python library to read/write Excel 2010 xlsx/xlsm files
Home-page: https://openpyxl.readthedocs.io
Author: See AUTHORS
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python3.6/site-packages
…
Then I guess it might be something wrong with the installed path, so I uninstalled the package, and then did
sudo pip3 install stockstats --install-option="--prefix=/usr/local/lib"
(I am just guessing if openpyxl is installed there then stockstats should be there too, as python imported openpyxl successfully)
That didn’t work as well, the error still persists.
*I didn’t use any package manager other than pip3.
** some irregularities occurred when I was trying to use python3(see this post). It was resolved, but I am not sure if the error in this post is related to that.
Any help or hint would be appreciated 😉
3
Answers
Thanks all for the prompt reply. After Guo Lei’s comment, I tried downloading the tar ball for this package and installing it myself without pip, which eventually told me what exactly happened: a module named int-date, required by stockstats, was not installed in the python library directory. After I installed it in the proper directory, the issue is resolved.
As Danila Vershinin and phd had pointed out, I really shouldn’t run pip as root, and that is the source of issue(curiously, however, that only one particular module required by stockstats is installed in /root/.local/lib/. All others are in the right place, maybe I added the prefix flag without remembering it...?)
Still, I am not sure, I ran pip using sudo because I received permission denied errors repeatedly — so should I use something like sudo --user? Or sth else?
for maybe some errors in installing pip.
reinstall python.
check that the module name is correctly typed
install stockstats in pip like "pip install stockstats" (getten from pypi.com)
This works for me.
or