pip says modules are there, but Python 3 program cannot find them - python-3.x

I have some old code I'm trying to use which uses httplib2 Python lib. The same exact code works fine on Linux (e.g. Raspberry Pi).
I have used pip to uninstall the httplib2 lib and pip3 to re-install.
Here's what "pip list" (or "pip3 list") shows:
C:\Users\g7847>pip list
Package Version
----------------------- ---------
bcrypt 3.2.0
cachetools 4.2.4
certifi 2021.5.30
cffi 1.15.0
chardet 4.0.0
cryptography 36.0.0
cycler 0.10.0
google-auth 2.3.3
google-auth-httplib2 0.1.0
httplib2 0.20.2
idna 2.10
kiwisolver 1.3.1
matplotlib 3.4.2
numpy 1.21.0
paramiko 2.8.1
Pillow 8.3.1
pip 21.3.1
pyasn1 0.4.8
pyasn1-modules 0.2.8
pycparser 2.21
PyNaCl 1.4.0
pyparsing 2.4.7
python-dateutil 2.8.2
requests 2.25.1
requests-http-signature 0.2.0
rsa 4.8
setuptools 57.1.0
six 1.16.0
urllib3 1.26.6
wheel 0.36.2
C:\Users\g7847>
and yet:
C:\Users\g7847>python3 sshConnect.py
Traceback (most recent call last):
File "C:\Users\g7847\sshConnect.py", line 12, in <module>
import httplib2
ModuleNotFoundError: No module named 'httplib2 '
This is the import section at the beginning. The only library that is complained about is httlib2.
import json
import time
import subprocess
import datetime
import base64
import sys
import os
import getpass
import errno
import re
import string
import httplib2

pip and pip3 are not the same.
pip will use one of your Python versions depending on what exactly is first in the system PATH variable, whereas with pip3 you can be sure that the module will be installed in python3 library.
So, could you double check if the module is actually installed in the python3 library ?
If the module really is installed in python3 library, you could check if the PATH variable is correct.
(You can check the PATH by using the following : Reference)

The httplib2 library is part of the standard library in Python 3.
import httplib ImportError: No module named httplib
is it installed on version 2.x?
pip2 install httplib2

I still don't really know what was going on. I decided for other reasons to switch to the requests library rather than httplib2. My program runs OK inside Idle and I also made Windows EXE of it using pyinstaller on the command line. I thought I was having trouble running it directly as a Python program but I just checked it and it's fine.
One thing that MIGHT have been an issue is that I also have been using WSL (Ubuntu) in Windows and had installed httplib2 over there. I really don't know. I did uninstall that just in case but I'm not using httplib2 any more anyway.
There is a weird issue that happens if you run the Windows 3.9 installer from Python.org. If you subsequently try to run Python, then the Windows Store opens and you can't do anything except install that. So I uninstalled and reinstalled everything a few times but the last time it was just the Windows Store version as it seemed fairly insistent.

Related

Import "ruamel.yaml" could not be resolved

I am just a beginner in python.
I have a requirement of converting a JSON Object into a YAML file and trying to import ruamel.yaml.
I did install the command pip3 install ruamel.yaml and my python list package shows that it's available.
site-packages % pip3 list
Package Version
------------------ ---------
certifi 2021.10.8
charset-normalizer 2.0.11
idna 3.3
pip 22.0.3
pytz 2021.3
PyYAML 6.0
requests 2.27.1
ruamel.yaml 0.17.21
ruamel.yaml.clib 0.2.6
setuptools 60.9.3
urllib3 1.26.8
Whereas when I am trying to import and use it in the python script it is giving me below error.
Import "ruamel.yaml" could not be resolved
Could someone please suggest how to resolve this.?
When Python cannot find a module you get an error looking like:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named ruamel.yaml
This might be because you are using some non-standard installation/execution environment, or because you try to run this from an editor. Some of those don't understand the concept of namespaces in Python.
It could also be that pip3 is not installing for the python that you are using to run the program. That is easy to check by installing some other package using pip3 and trying to import that.
In either case make sure you test your program running with the python that corresponds to pip3 ( using type pip3 or which pip3 resp type python ), or install using:
python -m pip install ruamel.yaml
and then run the program with python your_prog.py

Numpy cannot be imported even though it is installed

I am using Linux Mint 19.3 XFCE.
I have installed Numpy through pip3. pip3 was not installed already, and I installed pip3 thorugh apt.
The default version of python3 that came with the OS is 3.6.9. Since I am not supposed to change the default version of Python that comes installed with the OS, I kept that. And I installed a newer version, 3.8.0 with snap.
The command was-
sudo snap install python38
And now, whenever I need to work with the interpreter, I just type python38 into the terminal and get on with it.
I recently installed Numpy with pip3-
pip3 install numpy
and it shows up when I run pip3 freeze
:
It is listed as-
numpy==1.18.1
But when I enter the Python interpreter through typing python38 into my terminal, and type in import numpy, I am shown an error:
import numpy as np
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'numpy'
However, when I try the same with Python 3.6.9, it works. Numpy is improted, works just fine. (This time I enter Python interpreter by typing python3)
Now, how do I permanently solve this? That is, being able to import Numpy when working in Python 3.8 in terminal.
This may be the reason because your pip is configured for the default version of python in the machine(Python 3.6.9 in your case). You may change your default python version.
Or
You could run pip and install your python package for specific python version like
python_version -m pip install your_package
eg
python38 -m pip install numpy

How can I install modules in Mac OS Terminal?

I want to install some modules for Telegram Bots and I always get errors like:
File "test.py", line 7, in <module>
import spotipy
ModuleNotFoundError: No module named 'spotipy'
I tried to install spotipy with pip, pip3 and apt.
How is it done? Or generally how do I import modules?
Thank you.
From the spotipy README:
If you already have Python on your system you can install the library simply by downloading the distribution, unpack it and install in the usual fashion:
python setup.py install
You can also install it using a popular package manager with
pip install spotipy
or
easy_install spotipy
Make sure your pip version matches your python version (pip --version and python --version should both be Python3 or Python2).
To import the module, use one of the following statements (see python3 documentation):
import numpy
import numpy as np
from numpy import array

gTTS will not install, shows up as UNKNOWN

I have tried in vain to get gTTS working on my win10 machine.
I have upgraded pip.
i have run pip install gtts but all it installs is something called UNKNOWN
pip list gives me:
Package Version
------------- -------
aiohttp 1.0.5
async-timeout 3.0.1
asyncio 3.4.3
cffi 1.12.2
chardet 3.0.4
discord 0.16.12
discord.py 0.16.12
multidict 4.5.2
pip 19.0.3
pycparser 2.19
PyNaCl 1.3.0
pyttsx 1.1
setuptools 28.8.0
six 1.12.0
UNKNOWN 2.0.3
websockets 3.4
notice the UNKNOWN where my GTTS should be?
when i try install, i get this:
Collecting gTTS
Using cached https://files.pythonhosted.org/packages/e6/37/f55346a736278f0eb0ae9f7edee1a61028735ef0010db68a2e6fcd0ece56/gTTS-2.0.3.tar.gz
Generating metadata for package gTTS produced metadata for project name unknown. Fix your #egg=gTTS fragments.
Requirement already satisfied (use --upgrade to upgrade): unknown from https://files.pythonhosted.org/packages/e6/37/f55346a736278f0eb0ae9f7edee1a61028735ef0010db68a2e6fcd0ece56/gTTS-2.0.3.tar.gz#sha256=a6d4cf039da2797de8af2da7c1f0ce700ac0b48601ce6c11a02b337fd6bdcf57 in c:\users\user\appdata\local\programs\python\python36\lib\site-packages
And i cant call gTTS through from gtts import gTTS it just crashes my program every time.
Please, what am I doing wrong?
Use "pip install --upgrade gTTS"
So it looks like python generating metadata package for Googles Text-to-Speech gTTS. You now have use "--upgrade" to put the gTTS fragments of your first attempt at downloading gTTS together. You do this by calling:
"pip install --upgrade gTTS"
Hope this helps.

configparser in python 3.6 in anaconda

I am trying to port some code from 2.7 to 3.6, and I am having problems with the installing package configparser for py-3.6 in anaconda.
When I execute the following command, I get an error:
$ conda install -c anaconda configparser
UnsatisfiableError: The following specifications were found to be in conflict:
- configparser -> python[version='>=2.7,<2.8.0a0']
- python=3.6
The dependencies also gives me the same information:
conda info configparser
configparser 3.5.0 py27h5117587_0
---------------------------------
dependencies:
python >=2.7,<2.8.0a0
However, question-14087598 says the package is available in py-3.6. How should I install this package in anaconda?
(One solution in the above link suggests to install through the python program itself, but I would like to install through anaconda.)
The package configparser is a backport of a Python 3.5 standard module to older versions of Python. Unfortunately, it appears that the Anaconda version of this package is not packaged for Python 3.
However, you are using Python 3.6, so you can simply use the configparser which comes preinstalled with Python instead of installing anything.
It's possible that the source code you are attempting to port contains a line like this (which will fail if the backport is not installed):
from backports import configparser
You can probably replace that line with the following:
import configparser
There are minor differences between the 3.5-compatible version installed in the backport and the version provided by 3.6, but the 3.6 version should be backwards compatible for most reasonable use cases. The main purpose of the from backports form is to enable developing 2.x-compatible code in a 3.x-only environment without accidentally using new features that don't exist in the backport.

Resources