Not able to import a module that is already installed - python

I am trying to import a module "requests" but it shows the following error
File "manager.py", line 12,
import requests
ModuleNotFoundError: No module named 'requests'
Then I also verified the pip list using
python -m pip list
and it includes the requests module. also when I try to import it in the python interpreter it successfully imports the module.
>>> import requests
when I try
pip install requests
its says Requirement already satisfied: requests in /usr/lib/python3.6/site-packages
How can I resolve his issue ???
Thanks in advance

Make sure that your sys.path variables are correct. I've messed up before where the "site-packages" path got removed and caused imports to get wonky.

Related

No module named 'bcolors' although 'Requirement already satisfied'

I am trying to use bcolors in my python code in Spyder/Anaconda but it keeps telling me
ModuleNotFoundError: No module named 'bcolors'.
So I installed it with pip install bcolorswhich gave me Requirement already satisfied: bcolors in e:\anaconda3\lib\site-packages (1.0.4), but it still doesn't work.
What am I doing wrong?
You had that error because you are in different interpreter trying to import the module. You should append the path of the module to your working directory.
import sys
sys.path.append("\anaconda3\lib\site-packages")
import bcolors
Try to install lower version of this module
pip install bcolors==1.0.2
Have you tried installing the pandas' library using pip install pandas
I was having trouble with the latest distribution as well. Installing 1.0.2 worked for me.

azure functions module errors using python

I'm new to azure so excuse my lack of knowledge about the platform. I'm currently trying to run and deploy an azure function using python. these modules are currently found in my requirements.txt file
azure-functions
graphqlclient
requests
gql
asyncio
aiohttp
I run the following command pip install -r requirements.txt to install them, but for some reason, some modules cannot be found. for example the json module. import json works fine with any other python program. but when i try and add it to the requirements.txt file and run this command pip install -r requirements.txt i get the following error
ERROR: Could not find a version that satisfies the requirement json (from versions: none)
ERROR: No matching distribution found for json
i tried adding a version, but that did not solve my issue. thats only half my problem, i decided to ignore this problem for now and try to work with the modules that are working properly in the .txt file. moving on to my __init__.py file which is a timer trigger i have the following imports
import datetime
import logging
from graphqlclient import GraphQLClient
import requests
import asyncio
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
import azure.functions as func
but when i try and run my function i get the following error
Exception: ModuleNotFoundError: No module named 'gql.transport.aiohttp'
Can someone please explain these module erros? all these modules work fine when i run them from any other python program, so the problem seems to be from azure.
Thanks
I run the following command pip install -r requirements.txt to install them, but for some reason, some modules cannot be found. for example the json module.
Json is a standard library in python there's no need to install it.
Just include it in your python script as the following:
import json
Exception: ModuleNotFoundError: No module named 'gql.transport.aiohttp'
According to my test results, the default version of gql installed using the pip install -r requirements.txt command is 2.0.0.
If you use from gql.transport.aiohttp import AIOHTTPTransport to import AIOHTTPTransport, you need to install 3.x.x.
So this error is caused by version incompatibility.
Solution:
Please install the 3.x.x version of gql, you can uninstall the installed gql first, and then reinstall the new version of gql:
pip uninstall gql
pip install gql==3.0.0a5
I did some tests and the function can run normally.

Module pyfiglet not found

The code :
import pyfiglet
print(dir(pyfiglet))
The error :
ModuleNotFoundError: No module named 'pyfiglet'
Even though I downloaded "pip 21.0.1" and imported it, it does the same thing to "termcolor" package.
sorry i install pip and the command
pip install pifiglet
report this results
equirement already satisfied: pyfiglet in /usr/local/lib/python3.9/dist-packages (0.8.post1)
but if i do the original command i have this response
from pyfiglet import figlet_format
ImportError: cannot import name 'figlet_format' from 'pyfiglet' (/usr/local/lib/python3.9/dist-packages/pyfiglet/init.py)
but in this path there is the file...
Before you can import a library, it needs to already be on your drive. You are importing it into your file. In order to get it onto your drive in the first place, you have to install it.
From the command prompt, type:
pip install pifiglet
Once you've done that, you should be able to import it.

I install bs4, but then get "No module named 'bs4'"

UPDATE: Thank you to everyone who answered and commented. I understand now that I have 2 versions of python installed. My program was running from "Miniconda3/python.exe ". While bs4 was installed in "c:\python38\lib\site-packages". I understand this to be the cause of the problem. I removed Minicoda3 but VS code still tries to use it when I run a program. How can I fix this?
When I run the following code:
>>> from bs4 import BeautifulSoup
Error:
I get the error: "No module named 'bs4'.
After I install bs4, It says "Requirement already satisfied" yet I get the same error.
Im not sure what I'm doing wrong, please help. Error messages below.
PS C:\Users\Admin\Desktop\exAPP> pip install bs4
Collecting bs4
Requirement already satisfied: beautifulsoup4 in c:\python38\lib\site-packages (from bs4) (4.9.1)
Requirement already satisfied: soupsieve>1.2 in c:\python38\lib\site-packages (from beautifulsoup4->bs4) (2.0.1)
Using legacy setup.py install for bs4, since package 'wheel' is not installed.
Installing collected packages: bs4
Successfully installed bs4-0.0.1
PS C:\Users\Admin\Desktop\exAPP> & C:/Users/Admin/Miniconda3/python.exe c:/Users/Admin/Desktop/JNB.py
Traceback (most recent call last):
File "c:/Users/Admin/Desktop/JNB.py", line 2, in <module>
import BeautifulSoup
ModuleNotFoundError: No module named 'BeautifulSoup'
PS C:\Users\Admin\Desktop\exAPP> & C:/Users/Admin/Miniconda3/python.exe c:/Users/Admin/Desktop/JNB.py
Traceback (most recent call last):
File "c:/Users/Admin/Desktop/JNB.py", line 2, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
PS C:\Users\Admin\Desktop\exAPP>
You are using miniconda, which might not be on your PATH correctly such that pip is actually part of a separate Python installation.
You could use conda install pip, or C:/Users/Admin/Miniconda3/python.exe -m pip install bs4
Okay so my problems are fixed an my program is running. Like I said in the update the first problem was due to having 2 versions of python installed. After I removed the unwanted version it was still set as the python interpreter path. I was trying to fix this by going into VS code settings but was having no luck. Fortunately I finally noticed there was a button on bottom left of the screen that allowed me to change the path easily. Thanks again to those who commented and answered.

ImportError: No module named setuptools

I am trying to import urllib.request on python, but when I try to do so, i get the following error: ImportError: No module named setuptools.
I tried doing 'sudo apt-get install -y python-setuptools' , but after doing so too I am getting the same error.
I am using PyCharm and my Python version is Python 2.7.12+.
Unless there is any specific requirement to use urllib. I suggest you use python-requests. Both do the same.

Categories

Resources