Python3.5: Import Error - Module already exists - python

Hello I am trying to send an API request to http via Python's requests package and getting an ImportError while using import requests for python 3.5.2.
I tried to install requests package via pip3.5 install requests that says
Requirement already satisfied: requests in /usr/lib/python3.5/site-packages
Requirement already satisfied: idna<2.6,>=2.5 in /usr/lib/python3.5/site-packages (from requests)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /usr/lib/python3.5/site-packages (from requests)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python3.5/site-packages (from requests)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3.5/site-packages (from requests)
if I list the install packages pip3.5 list I got
appdirs (1.4.3)
bencode (1.0)
better-bencode (0.2.1)
certifi (2017.7.27.1)
chardet (3.0.4)
click (6.7)
Flask (0.12.2)
gevent (1.2.2)
greenlet (0.4.12)
humanfriendly (4.4)
idna (2.5)
itsdangerous (0.24)
Jinja2 (2.9.6)
magneticod (0.6.0)
magneticow (0.6.0)
MarkupSafe (1.0)
Naked (0.1.31)
parse-torrent-name (1.1.1)
pip (9.0.1)
PyYAML (3.12)
requests (2.18.3) <--- Here its already installed
setuptools (33.1.1)
urllib3 (1.22)
uvloop (0.8.0)
Werkzeug (0.12.2)
this is how I am running the python script python3 script.py (interpreting with python3.5)
your help would be appreciated. Thank you!

Related

Why doesn't this while loop work as a substitute for this try/except block when checking the availability of modules?

The following works as intended installing the module before importing it:
#!/usr/bin/env python3
from subprocess import run
from sys import modules
try:
from bs4 import BeautifulSoup
except:
run("pip3 install beautifulsoup4", shell=True)
from bs4 import BeautifulSoup
It crossed my mind that I could accomplish the same job with a while loop.
And so I wrote:
#!/usr/bin/env python3
from subprocess import run
from sys import modules
while "bs4" not in modules:# neither does work `while not "bs4" in modules:`
run("pip3 install beautifulsoup4", shell=True)
from bs4 import BeautifulSoup
But it does not work, I get from Python:
/home/jerzy/.local/lib/python3.8/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.23ubuntu1 is an invalid version and will not be supported in a future release
warnings.warn(
Collecting beautifulsoup4
Using cached beautifulsoup4-4.11.1-py3-none-any.whl (128 kB)
Requirement already satisfied: soupsieve>1.2 in /home/jerzy/.local/lib/python3.8/site-packages (from beautifulsoup4) (1.9.5)
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.11.1
Requirement already satisfied: beautifulsoup4 in /home/jerzy/.local/lib/python3.8/site-packages (4.11.1)
Requirement already satisfied: soupsieve>1.2 in /home/jerzy/.local/lib/python3.8/site-packages (from beautifulsoup4) (1.9.5)
Requirement already satisfied: beautifulsoup4 in /home/jerzy/.local/lib/python3.8/site-packages (4.11.1)
Requirement already satisfied: soupsieve>1.2 in /home/jerzy/.local/lib/python3.8/site-packages (from beautifulsoup4) (1.9.5)
Requirement already satisfied: beautifulsoup4 in /home/jerzy/.local/lib/python3.8/site-packages (4.11.1)
Requirement already satisfied: soupsieve>1.2 in /home/jerzy/.local/lib/python3.8/site-packages (from beautifulsoup4) (1.9.5)

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)

Python cannot see module after installing via pip

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

ModuleNotFoundError: No module named 'bs4' / No module named 'requests'

I cannot seem to import beautifulsoup or requests however everything seems to be in order from what I have read online. I'm not sure what I have missed.
PATH:
C:\Users\ross\AppData\Local\Programs\Python\Python37
C:\Users\ross\AppData\Local\Programs\Python\Python37\Scripts
Script:
import requests
from bs4 import BeautifulSoup
pip3 install output:
Requirement already satisfied: bs4 in c:\users\ross\appdata\local\programs\python\python37-32\lib\site-packages (0.0.1)
Requirement already satisfied: requests in c:\users\ross\appdata\local\programs\python\python37-32\lib\site-packages (2.22.0)
Requirement already satisfied: beautifulsoup4 in c:\users\ross\appdata\local\programs\python\python37-32\lib\site-packages (from bs4) (4.8.0)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\ross\appdata\local\programs\python\python37-32\lib\site-packages (from requests) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\ross\appdata\local\programs\python\python37-32\lib\site-packages (from requests) (2019.6.16)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\ross\appdata\local\programs\python\python37-32\lib\site-packages (from requests) (1.25.3)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\ross\appdata\local\programs\python\python37-32\lib\site-packages (from requests) (3.0.4)
Requirement already satisfied: soupsieve>=1.2 in c:\users\ross\appdata\local\programs\python\python37-32\lib\site-packages (from beautifulsoup4->bs4) (1.9.2)
python --version output:
Python 3.7.4
python -m pip freeze output:
astroid==2.1.0
beautifulsoup4==4.8.0
bs4==0.0.1
certifi==2019.6.16
chardet==3.0.4
colorama==0.4.1
idna==2.8
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
pylint==2.2.2
requests==2.22.0
six==1.12.0
soupsieve==1.9.2
urllib3==1.25.3
wrapt==1.11.0
import sys; print(sys.path) output:
['C:\\Users\\ross.watson\\Downloads', 'C:\\Users\\ross.watson\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip', 'C:\\Users\\ross.watson\\AppData\\Local\\Programs\\Python\\Python37\\DLLs', 'C:\\Users\\ross.watson\\AppData\\Local\\Programs\\Python\\Python37\\lib', 'C:\\Users\\ross.watson\\AppData\\Local\\Programs\\Python\\Python37', 'C:\\Users\\ross.watson\\AppData\\Roaming\\Python\\Python37\\site-packages', 'C:\\Users\\ross.watson\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages']
pip --version output:
pip 19.2.1 from c:\users\ross.watson\appdata\local\programs\python\python37-32\lib\site-packages\pip (python 3.7)
Final Edit
I'm an idiot, I remove the 3.7.2 64 bit version and it worked fine. The issue was having multiple versions. Not sure why the install would install 2 different version for 32/64 bit. Thank all for you help.

Problems importing quandl module

I am trying to create a Data Science project using some Quandl dataset, but am receiving an error on import.
As i know quandl should be imported all in lowercase, as the documentation states here and here, my import goes as follows:
import quandl
Error:
ModuleNotFoundError: No module named 'quandl'
I installed quandl using pip install quandl. My pip list output is:
Package Version
--------------- ---------
asn1crypto 0.24.0
certifi 2019.6.16
cffi 1.12.3
chardet 3.0.4
cryptography 2.7
idna 2.8
inflection 0.3.1
more-itertools 5.0.0
ndg-httpsclient 0.5.1
numpy 1.16.4
pandas 0.24.2
pip 19.1.1
pyasn1 0.4.5
pycparser 2.19
pyOpenSSL 19.0.0
python-dateutil 2.8.0
pytz 2019.1
Quandl 3.4.8
requests 2.22.0
setuptools 41.0.1
six 1.12.0
urllib3 1.25.3
wheel 0.33.4
wincertstore 0.2
I don't have pip3, as I installed Python through my Anaconda installation. I am running a Jupyter Notebook in a virtual environment I created just for this project. Just so you know, python --version output is:
Python 3.7.3
The strange part occurs when i try running a one line python script with import quandl. This time the program runs without errors, which means that the cause of the ModuleNotFoundError: No module named 'quandl' is the jupyter notebook, which is not being able to properly find the quandl module.
As a last resource, I tried installing quandl inside jupyter notebook:
!pip install quandl
import quandl
Output:
Requirement already satisfied: quandl in c:\users\not_me\.conda\envs\quant\lib\site-packages (3.4.8)
Requirement already satisfied: pandas>=0.14 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (0.24.2)
Requirement already satisfied: pyOpenSSL in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (19.0.0)
Requirement already satisfied: inflection>=0.3.1 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (0.3.1)
Requirement already satisfied: numpy>=1.8 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (1.16.4)
Requirement already satisfied: more-itertools<=5.0.0 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (5.0.0)
Requirement already satisfied: pyasn1 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (0.4.5)
Requirement already satisfied: python-dateutil in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (2.8.0)
Requirement already satisfied: six in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (1.12.0)
Requirement already satisfied: ndg-httpsclient in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (0.5.1)
Requirement already satisfied: requests>=2.7.0 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (2.22.0)
Requirement already satisfied: pytz>=2011k in c:\users\not_me\.conda\envs\quant\lib\site-packages (from pandas>=0.14->quandl) (2019.1)
Requirement already satisfied: cryptography>=2.3 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from pyOpenSSL->quandl) (2.7)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from requests>=2.7.0->quandl) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from requests>=2.7.0->quandl) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from requests>=2.7.0->quandl) (2019.6.16)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from requests>=2.7.0->quandl) (1.25.3)
Requirement already satisfied: asn1crypto>=0.21.0 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from cryptography>=2.3->pyOpenSSL->quandl) (0.24.0)
Requirement already satisfied: cffi!=1.11.3,>=1.8 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from cryptography>=2.3->pyOpenSSL->quandl) (1.12.3)
Requirement already satisfied: pycparser in c:\users\not_me\.conda\envs\quant\lib\site-packages (from cffi!=1.11.3,>=1.8->cryptography>=2.3->pyOpenSSL->quandl) (2.19)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-614264e6071a> in <module>
1 get_ipython().system('pip install quandl')
----> 3 import quandl
ModuleNotFoundError: No module named 'quandl'
Try pip3 install quandl . It usually works for Python 3.x
You can use pip using the module syntax rather than the standalone CLI for when you want to make sure you are using the version of pip associated with that interpreter.
python -m pip install quandl
Or, since you are using Conda, you could also try installing quandl with the conda CLI.
conda install quandl (or whatever the package's name is for conda).
Try installing it by running
!pip install quandl
In a cell in a Jupyter notebook. If you have things set up correctly, there's a chance that will be the same version of pip you need.
The problem was that Jupyter was not properly recognizing my virtual environment. I found my answer here, the workaround is pretty self explanatory.

Categories

Resources