keep getting python ModuleNotFoundError: No module named - python

I am working on a raspberry pi python project and every time I import a package I get the same error ModuleNotFoundError: No module named ''. for example I am trying to add the ambient_api package
I followed the steps in their set up:
pip install ambient_api
Added the imports at the top of my file:
from ambient_api.ambientapi import AmbientAPI
api = AmbientAPI()
but I am getting the error:
ModuleNotFoundError: No module named 'ambient_api'
This is happening with all the imports I am trying to add and I cant figure out what I am missing.
when I was looking on google I came across __init__.py might be a solution but I am not sure how this works?
edit:
here is what was output when I installed:
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: ambient_api in /home/pi/.local/lib/python2.7/site-packages (1.5.2)
Requirement already satisfied: requests in /usr/lib/python2.7/dist-packages (from ambient_api) (2.21.0)
Requirement already satisfied: urllib3 in /usr/lib/python2.7/dist-packages (from ambient_api) (1.24.1)
version in my terminal:
pi#raspberrypi:~/Raspberry-Pi-Greenhouse $ python --version
Python 2.7.16
but it looks like the version in the shell in the ide when I run the program is saying:
Python 3.7.3 (/usr/bin/python3)

As explained by #JaFizz in Pytorch is installed but do not working ubuntu 18.04 it solved by giving an alias and installing correctly to desired python version (there were two pythons installed on the same machine)
First it was necessary to specify the location of the python, example:
alias python=/usr/local/bin/python3.6
Then install it:
python pip install <package name>

Related

FlightRadarAPI not found as a module

I am trying to use the FlightRadar24 API as described in this link:
https://pypi.org/project/FlightRadarAPI/#description
I have followed the steps as outlined, however, when trying to run the following simple script, I get an error saying "No Module named 'FlightRadar24':
from FlightRadar.api import FlightRadar24API
fr_api = FlightRadar24API()
However, I re-checked whether the module has been installed, which is true. I installed the module using pip3.
Anyone know how to solve?
When I check if the module has been installed, I get the following:
Requirement already satisfied: flightradar24 in /usr/local/lib/python3.9/site-packages (0.3.1)
Does it have to do with the fact that it is installed in python3.9? How would I get it installed to python 3.7 specifically using pip?

Python can't find installed module

I successfully installed the module geocoder:
Requirement already satisfied: chardet<5,>=3.0.2 in
c:\users\myname\appdata\roaming\python\python39\site-packages (from
requests->geocoder) (4.0.0) Installing collected packages: ratelim,
geocoder Successfully installed geocoder-1.38.1 ratelim-0.1.6
When I try to create a Python file that includes import geocoder, I get the error Import "geocoder" could not be resolved.
The relevant path is included in sys.path:
C:\Users\myname\Downloads
C:\Users\myname\AppData\Local\Programs\Python\Python39\python39.zip
C:\Users\myname\AppData\Local\Programs\Python\Python39\DLLs
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib
C:\Users\myname\AppData\Local\Programs\Python\Python39
C:\Users\myname\AppData\Roaming\Python\Python39\site-packages
C:\Users\myname\AppData\Roaming\Python\Python39\site-packages\win32
C:\Users\myname\AppData\Roaming\Python\Python39\site-packages\win32\lib
C:\Users\myname\AppData\Roaming\Python\Python39\site-packages\Pythonwin
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages\win32
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages\win32\lib
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages\Pythonwin
Why isn't Python able to resolve this module?
Thanks
Either geocoder is installed to other than Python3.9 version installation (e.g. python 3.7) or geocoder is not in the path of your python module.
Try to install the library using specific Python pip package manager (e.g. pip3.9) and run the module you develop using specific Python version (e.g. Python3.9)

How can i install python modules that have spaces in between?

I wanted to run a script that would scan my network and that script uses a awesome library called who-is-on-my-wifi. I have installed the module to run the script but i get errors from the prompt saying that it cannot detect such a module in the system.
This is the script.
from who_is_on_my_wifi import *
WHO = who()
for i in range(0, len(WHO)):
print(WHO[i])
And this is the error that i get.
python scanner.py
Traceback (most recent call last):
File "scanner.py", line 1, in <module>
from who_is_on_my_wifi import *
ImportError: No module named who_is_on_my_wifi
This is the proof that i have installed the module
pip3 install 'who_is_on_my_wifi'
Requirement already satisfied: who_is_on_my_wifi in /home/harein/.local/lib/python3.8/site-packages (1.2.0)
Requirement already satisfied: getmac in /home/harein/.local/lib/python3.8/site-packages (from who_is_on_my_wifi) (0.8.2)
Requirement already satisfied: python-nmap in /home/harein/.local/lib/python3.8/site-packages (from who_is_on_my_wifi) (0.6.1)
Any suggestions on how i can avoid this can continue executing my script ?
EDIT
The script finally executed the way i want by changing the,
python scanner.py to python3 scanner.py
You guys were right, it was the way how i executed the script that generated this error and it was not a problem in the module apparently.
I would like to thank everyone who gave the support.<3
When trying to
import this_is_not_a_module
the error you get:
ImportError: No module named this_is_not_a_module
is the error raised by Python 2.
Python 3 would raise a different one:
ModuleNotFoundError: No module named 'this_is_not_a_module'
So, your actual problem is that your system tries to execute your script with some Python 2 version, while you installed your module for your Python 3.8 version.
sometimes you can't import modules because you have installed two python versions(or conda along with it). if you have, delete one of your python versions or activate conda and try importing your module, or just try:
pip uninstall who_is_on_my_wifi
pip install who_is_on_my_wifi
I usually tend to install modules per project and use virtualenv for it.
It kind of links respective versions of programs (like python interpreter, pip and so on) and takes care of PYTHONPATH and the way of installed dependencies.
$ pip3 install virtualenv
$ virtualenv whoisonwifi
$ source whoisonwifi/bin/activate
$ pip --version
pip 21.0.1 from
/mnt/devel/workonhome/whoisonwifi/lib/python3.7/site-packages/pip
(python 3.7)
$ pip install 'who_is_on_my_wifi'
from there your code (sort of) works for me.

VS Code: Unable to install flask

I'm not using a virtual environment, & have tried selecting the appropriate python interpreter.
When I do a python3 -m pip install flask,
my terminal says Requirement already satisfied: MarkupSafe>=0.23 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from Jinja2>=2.10.1->flask) (1.1.1)
However, I receive this error message: ModuleNotFoundError: No module named 'flask' which traces back to VSCode being unable to import "flask" for some reason.
Would appreciate any help!

Getting "ImportError: No module named yaml" in python

I've python script which uses the YAML. but it's giving an Import Error for YAML module as below:
ImportError: No module named yaml
I've also tried to install pyyaml, but it shows that it's already installed.
pip install pyyaml gives below output:
Requirement already satisfied: pyyaml in /usr/local/lib/python3.6/site-packages (5.1.1)
I've also checked in pip list, it also shows PyYAML with 5.1.1 version in list.
What should be done here to run this script?

Categories

Resources