Python cannot see module after installing via pip - python

I'm still trying to master the science of installing packages via pip. When I run pip to install geocoder, I get the following:
(base) C:\Users\MBSanders>python -m pip install geocoder
Requirement already satisfied: geocoder in c:\programdata\anaconda3\lib\site-packages (1.38.1)
Requirement already satisfied: requests in c:\programdata\anaconda3\lib\site-packages (from geocoder) (2.21.0)
Requirement already satisfied: future in c:\programdata\anaconda3\lib\site-packages (from geocoder) (0.17.1)
Requirement already satisfied: click in c:\programdata\anaconda3\lib\site-packages (from geocoder) (7.0)
Requirement already satisfied: six in c:\programdata\anaconda3\lib\site-packages (from geocoder) (1.12.0)
Requirement already satisfied: ratelim in c:\programdata\anaconda3\lib\site-packages (from geocoder) (0.1.6)
Requirement already satisfied: certifi>=2017.4.17 in c:\programdata\anaconda3\lib\site-packages (from requests->geocoder) (2019.3.9)
Requirement already satisfied: idna<2.9,>=2.5 in c:\programdata\anaconda3\lib\site-packages (from requests->geocoder) (2.8)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in c:\programdata\anaconda3\lib\site-packages (from requests->geocoder) (1.24.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\programdata\anaconda3\lib\site-packages (from requests->geocoder) (3.0.4)
Requirement already satisfied: decorator in c:\programdata\anaconda3\lib\site-packages (from ratelim->geocoder) (4.4.0)
When I run
os.getcwd()
in spyder/python, I get
'C:\\Users\\MBSanders'
My question is, why do I get
ModuleNotFoundError: No module named 'geocoder'
When I run
import geocoder
I'm somewhat new to python. Please let me know if additional info is needed to trouble shoot. I'm within a federal agency so I do not have admin rights.
When I run sys.path in the console, I get
sys.path
Out[12]:
['F:\\Users\\MBSanders',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\python37.zip',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\DLLs',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3',
'',
'C:\\Users\\MBSanders\\AppData\\Roaming\\Python\\Python37\\site-packages',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Pythonwin',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\IPython\\extensions',
'F:\\Users\\MBSanders\\.ipython']

Assuming you're running python on the terminal, and python is the command you're using to run it, try doing python -m pip install geocoder. That'll install it for the python build you want to use. Or if you know the full path to the python build you're using, you can do something similar like /path/to/python -m pip install geocoder.

if you are using python 3.7 or 3.8 you may need to pip3.7 or pip3.8 install if you OS is recognizing a 2.x version as default

Related

Package updates from remote git repository are not reflected in site-packages

I have been trying to upgrade a package based off of the most recent changes on git but the changes aren't taking effect. I ran several variations of this command, such as also using python -m pip and the actual path to the pip version in anaconda, as well as adding --upgrade: pip install git+git://github.com/lmcinnes/umap#master
Here is the output each time:
Collecting git+git://github.com/lmcinnes/umap#master
Cloning git://github.com/lmcinnes/umap (to revision master) to /tmp/pip-req-build-bck1u0of
Running command git clone -q git://github.com/lmcinnes/umap /tmp/pip-req-build-bck1u0of
Requirement already satisfied: numpy>=1.17 in /home/himani/anaconda3/lib/python3.7/site-packages (from umap-learn==0.5.1) (1.19.2)
Requirement already satisfied: scikit-learn>=0.22 in /home/himani/anaconda3/lib/python3.7/site-packages (from umap-learn==0.5.1) (0.23.2)
Requirement already satisfied: scipy>=1.0 in /home/himani/anaconda3/lib/python3.7/site-packages (from umap-learn==0.5.1) (1.6.0)
Requirement already satisfied: numba>=0.49 in /home/himani/anaconda3/lib/python3.7/site-packages (from umap-learn==0.5.1) (0.51.2)
Requirement already satisfied: pynndescent>=0.5 in /home/himani/anaconda3/lib/python3.7/site-packages (from umap-learn==0.5.1) (0.5.2)
Requirement already satisfied: llvmlite<0.35,>=0.34.0.dev0 in /home/himani/anaconda3/lib/python3.7/site-packages (from numba>=0.49->umap-learn==0.5.1) (0.34.0)
Requirement already satisfied: setuptools in /home/himani/anaconda3/lib/python3.7/site-packages (from numba>=0.49->umap-learn==0.5.1) (52.0.0.post20210125)
Requirement already satisfied: joblib>=0.11 in /home/himani/anaconda3/lib/python3.7/site-packages (from pynndescent>=0.5->umap-learn==0.5.1) (1.0.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /home/himani/anaconda3/lib/python3.7/site-packages (from scikit-learn>=0.22->umap-learn==0.5.1) (2.1.0)
And looking in the actual directory of where umap is in site-packages, I can see that none of the files are being changed to reflect the updates, so it seems that nothing is happening. I am tempted to just manually change the files myself but I know that wouldn't be smart for the long run.
try using the --update and --force-reinstall options of pip, or:
pip install --update --force-reinstall git+git://github.com/lcminnes/umap#master

ModuleNotFoundError: No module named 'flask_mysqldb' even if installed

I'm using mysql with flask for developing a basic website and I'm getting ModuleNotFound error even if I have the module installed. Can someone solve this ?
File "c:/Users/prshi/Desktop/Py files/FLASK app/app.py", line 3, in <module>
from flask_mysqldb import MySQL
ModuleNotFoundError: No module named 'flask_mysqldb'
PS C:\Users\prshi\Desktop\Py files\FLASK app> pip install flask-mysqldb
Requirement already satisfied: flask-mysqldb in c:\python39\lib\site-packages (0.2.0)
Requirement already satisfied: Flask>=0.10 in c:\python39\lib\site-packages (from flask-mysqldb) (1.1.2)
Requirement already satisfied: mysqlclient in c:\python39\lib\site-packages (from flask-mysqldb) (1.4.6)
Requirement already satisfied: Werkzeug>=0.15 in c:\python39\lib\site-packages (from Flask>=0.10->flask-mysqldb) (1.0.1)
Requirement already satisfied: Jinja2>=2.10.1 in c:\python39\lib\site-packages (from Flask>=0.10->flask-mysqldb) (2.11.2)
Requirement already satisfied: itsdangerous>=0.24 in c:\python39\lib\site-packages (from Flask>=0.10->flask-mysqldb) (1.1.0)
Requirement already satisfied: click>=5.1 in c:\python39\lib\site-packages (from Flask>=0.10->flask-mysqldb) (7.1.2)
Requirement already satisfied: MarkupSafe>=0.23 in c:\python39\lib\site-packages (from Jinja2>=2.10.1->Flask>=0.10->flask-mysqldb) (1.1.1)
PS C:\Users\prshi\Desktop\Py files\FLASK app>
This a common python path issue, to make sure it isn't your case, type :
import sys
print(sys.path)
and check if it contains:
/usr/local/lib64/python3.6/site-packages
The problem is that you install the package using pip somewhere, and you're trying to import it from somewhere else where it's not installed. The trick to solve it is by running this command :
export PYTHONPATH=$PYTHONPATH:/path/to/your/modules

Having problems installing modules on python (Mac)

I'm a bit new to using pip to install modules on Python. I believe I have pip installed, however when I try to use the module I've tried to install using pip it says there is no such module. I'll post terminal response to see what happened. I'd really appreciate if somebody can let me know if I'm making a mistake installing modules, thanks for your time.
faizrahman#138-38-186-80 ~ % sudo pip install matplotlib
Password:
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
WARNING: The directory '/Users/faizrahman/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: matplotlib in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (1.3.1)
Requirement already satisfied: numpy>=1.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) (1.8.0rc1)
Requirement already satisfied: python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) (1.5)
Requirement already satisfied: tornado in /Library/Python/2.7/site-packages (from matplotlib) (5.1.1)
Requirement already satisfied: pyparsing>=1.5.6 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) (2.0.1)
Requirement already satisfied: nose in /Library/Python/2.7/site-packages (from matplotlib) (1.3.7)
Requirement already satisfied: singledispatch in /Library/Python/2.7/site-packages (from tornado->matplotlib) (3.4.0.3)
Requirement already satisfied: futures in /Library/Python/2.7/site-packages (from tornado->matplotlib) (3.3.0)
Requirement already satisfied: backports-abc>=0.4 in /Library/Python/2.7/site-packages (from tornado->matplotlib) (0.5)
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from singledispatch->tornado->matplotlib) (1.12.0)
faizrahman#138-38-186-80 ~ %
You will need to call pip from python3:
sudo python3 -m pip install matplotlib

No able to import python modules . Installed pip3 and python 3.5 and python3.7

I want to use requests module on python3.7
But when in run
import requests
it throws error like this
ModuleNotFoundError: No module named 'requests'
However, it works fine with python3.5
When I run pip and pip3 install requests it says
root#helloasc:~# pip install requests
Requirement already satisfied: requests in /usr/local/lib/python3.5/dist-packages (2.23.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.5/dist-packages (from requests) (1.25.8)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.5/dist-packages (from requests) (2020.4.5.1)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.5/dist-packages (from requests) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.5/dist-packages (from requests) (2.9)

ImportError: No module named flask_toastr

I want to use Toastr, for showing non-blocking notifications in my Flask app. I already installed the package with pip :
sudo pip install Flask-Toastr
Here is the output of the installation
Requirement already satisfied: Flask-Toastr in
/Users/****/.local/lib/python3.7/site-packages (0.5.2)
Requirement already satisfied: Flask in
/Users/****/anaconda3/lib/python3.7/site-packages (from Flask-Toastr)
(1.1.1)
Requirement already satisfied: Jinja2 in
/Users/****/anaconda3/lib/python3.7/site-packages (from Flask-Toastr)
(2.10.1)
Requirement already satisfied: click>=5.1 in
/Users/****/anaconda3/lib/python3.7/site-packages (from
Flask->Flask-Toastr) (7.0)
Requirement already satisfied: Werkzeug>=0.15 in
/Users/****/anaconda3/lib/python3.7/site-packages (from
Flask->Flask-Toastr) (0.15.4)
Requirement already satisfied: itsdangerous>=0.24 in
/Users/****/anaconda3/lib/python3.7/site-packages (from
Flask->Flask-Toastr) (1.1.0)
Requirement already satisfied: MarkupSafe>=0.23 in
/Users/****/anaconda3/lib/python3.7/site-packages (from
Jinja2->Flask-Toastr) (1.1.1)
Here is theimport statement:
from flask_toastr import Toastr
But when I run my script I have this ImportError. How can I fix this? Thank you
Without seeing your import statement I suspect you have used a '-' instead of an underscore in the import statement:
Try this:
from flask_toastr import Toastr

Categories

Resources