Python error “ModuleNotFoundError: No module named 'requests'” - python

I am trying to import a module that I know for a fact that was installed, but I am getting the ModuleNotFoundError: No module named '' error.
How can I solve this problem ?
HelendeMacBook-Pro:bin helendai$ pip3 list
Package Version
---------- ----------
certifi 2019.11.28
chardet 3.0.4
idna 2.9
pip 20.0.2
requests 2.23.0
setuptools 39.0.1
urllib3 1.25.8
wheel 0.31.0
HelendeMacBook-Pro:bin helendai$ python3 /Users/helendai/PycharmProjects/Demo1/test.py
Traceback (most recent call last):
File "/Users/helendai/PycharmProjects/Demo1/test.py", line 2, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
enter image description here

Related

TCLab issues with python 3.10 (and python 3.9)

OS:
macOS 11.7.1 (Big Sur)
A few months ago I purchased a TCLab kit and at the time did some very rudimentary tests where the device worked as expected.
Recently I decided that I wanted to work on some of the APMonitor lessons and connected the TCLab to my computer expecting that it would work as it had done in the past.
Sadly, that is not the case. I would like help in correcting the issues identified and getting the TCLab to work again.
Originally, I had been using python 3.9. Since then python 3.10 came out and I installed it.
Using the following script from APMonitor as my test,
$ cat show_T1.py
import tclab
with tclab.TCLab() as lab:
print(lab.T1)
I got the errors documented below:
$ python --version
Python 3.10.8
$ python show_T1.py
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/show_T1.py", line 1, in <module>
import tclab
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv3.10/lib/python3.10/site-packages/tclab/__init__.py", line 2, in <module>
from .historian import Historian, Plotter
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv3.10/lib/python3.10/site-packages/tclab/historian.py", line 6, in <module>
from collections import Iterable
ImportError: cannot import name 'Iterable' from 'collections' (/usr/local/Cellar/python#3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)
I was able to find the cause of this problem here: Stack Overflow It is an issue where Iterable was moved to collections.abc from collections.
When I change the script to:
$ cat show_T1.py
import collections.abc
collections.Iterable = collections.abc.Iterable
collections.Mapping = collections.abc.Mapping
collections.MutableSet = collections.abc.MutableSet
collections.MutableMapping = collections.abc.MutableMapping
import tclab
with tclab.TCLab() as lab:
print(lab.T1)
the import error goes away. However, I now get new errors:
$ python show_T1.py
TCLab version 0.4.9
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv3.10/lib/python3.10/site-packages/tclab/tclab.py", line 64, in __init__
self.connect(baud=115200)
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv3.10/lib/python3.10/site-packages/tclab/tclab.py", line 114, in connect
self.sp = serial.Serial(port=self.port, baudrate=baud, timeout=2)
AttributeError: module 'serial' has no attribute 'Serial'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv3.10/lib/python3.10/site-packages/tclab/tclab.py", line 70, in __init__
self.sp.close()
AttributeError: 'TCLab' object has no attribute 'sp'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/show_T1.py", line 7, in <module>
with tclab.TCLab() as lab:
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv3.10/lib/python3.10/site-packages/tclab/tclab.py", line 77, in __init__
raise RuntimeError('Failed to Connect.')
RuntimeError: Failed to Connect.
Sadly, I get almost the same error as above if I revert back to python 3.9: (python 3.9 does not have the Iterable problem, so I reverted back to the original script):
$ python --version
Python 3.9.15
$ python show_T1.py
TCLab version 0.4.9
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv/lib/python3.9/site-packages/tclab/tclab.py", line 64, in __init__
self.connect(baud=115200)
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv/lib/python3.9/site-packages/tclab/tclab.py", line 114, in connect
self.sp = serial.Serial(port=self.port, baudrate=baud, timeout=2)
AttributeError: module 'serial' has no attribute 'Serial'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv/lib/python3.9/site-packages/tclab/tclab.py", line 70, in __init__
self.sp.close()
AttributeError: 'TCLab' object has no attribute 'sp'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/show_T1.py", line 2, in <module>
with tclab.TCLab() as lab:
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv/lib/python3.9/site-packages/tclab/tclab.py", line 77, in __init__
raise RuntimeError('Failed to Connect.')
RuntimeError: Failed to Connect.
I know that at least I have connectivity to the device, because when I unplug the USB cable I get an error message that says, correctly, that no arduino is connected:
$ python show_T1.py
TCLab version 0.4.9
--- Serial Ports ---
/dev/cu.Bluetooth-Incoming-Port n/a n/a
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/show_T1.py", line 2, in <module>
with tclab.TCLab() as lab:
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv/lib/python3.9/site-packages/tclab/tclab.py", line 61, in __init__
raise RuntimeError('No Arduino device found.')
RuntimeError: No Arduino device found.
Below are the python modules I have installed under python 3.10 and 3.9:
python 3.10:
$ pip list
Package Version
------------------ ---------
blessed 1.19.1
bpython 0.23
certifi 2022.9.24
charset-normalizer 2.1.1
contourpy 1.0.6
curtsies 0.4.1
cwcwidth 0.1.8
cycler 0.11.0
fonttools 4.38.0
future 0.18.2
greenlet 2.0.1
idna 3.4
iso8601 1.1.0
kiwisolver 1.4.4
matplotlib 3.6.2
numpy 1.23.5
packaging 21.3
Pillow 9.3.0
pip 22.3.1
Pygments 2.13.0
pyparsing 3.0.9
pyserial 3.5
python-dateutil 2.8.2
pyxdg 0.28
PyYAML 6.0
requests 2.28.1
scipy 1.9.3
serial 0.0.97
setuptools 65.4.1
six 1.16.0
tclab 0.4.9
urllib3 1.26.13
wcwidth 0.2.5
python 3.9:
$ pip list
Package Version
------------------ ---------
blessed 1.19.1
bpython 0.23
certifi 2022.9.24
charset-normalizer 2.1.1
contourpy 1.0.6
curtsies 0.4.1
cwcwidth 0.1.8
cycler 0.11.0
docopt 0.6.2
fonttools 4.38.0
future 0.18.2
greenlet 2.0.1
idna 3.4
iso8601 1.1.0
kiwisolver 1.4.4
matplotlib 3.6.2
numpy 1.23.5
packaging 21.3
Pillow 9.3.0
pip 22.3.1
pipreqs 0.4.11
Pygments 2.13.0
pyparsing 3.0.9
pyserial 3.5
python-dateutil 2.8.2
pyxdg 0.28
PyYAML 6.0
requests 2.28.1
scipy 1.9.3
serial 0.0.97
setuptools 65.4.1
six 1.16.0
tclab 0.4.9
urllib3 1.26.13
wcwidth 0.2.5
yarg 0.1.9
NOTE: I have send this issue to support#apmonitor.com
Serial Connection Issue
This error AttributeError: module 'serial' has no attribute 'Serial' suggests that the package serial or a local file name serial.py has a conflict with pyserial. Rename your file to something else besides serial.py and/or uninstall the serial package (not needed for TCLab). Your pyserial package is the latest version.
pip uninstall serial
The error occurs when there is a local file named serial.py and we import from the pyserial module. Additional common TCLab help issues are posted to the TCLab setup and troubleshooting page.
Serial Port Permission
If the serial uninstall doesn't fix the problem of allowing a serial connection, one other thing to check is the USB port permission. On Linux, discover the USB port name with ls /dev/tty* Set the permission for that USB connection with the correct name.
sudo chmod a+rw /dev/ttyACM0
Python 3.10 Compatibility
You correctly found the issue with installing the latest version of TCLab for Python 3.10 compatibility. The module developer is still working on the next version of the TCLab package. Until that point, you can either edit the historian.py file (path is in the error message) with a text editor and change from collections import Iterable to from collections.abc import Iterable or install the new package from GitHub:
pip install --upgrade https://github.com/jckantor/TCLab/archive/master.zip
This will be resolved with the next release of TCLab on PyPI.org. The current version is 0.4.9 that does not include Python 3.10 compatibility because of the Iterable package change.

I keep getting ModuleNotFoundError where is the issue?

So, I'm trying to install and use the google-images-download repo both through: pip install google-images-download and pip install git+https://github.com/Joeclinton1/google-images-download.git
I've tried installing it as SU as well. In PyCharm when I view packages I do see it but when I try this code:
from google_images_download import google_images_download
#instantiate the class
response = google_images_download.googleimagesdownload()
arguments = {"keywords":"aeroplane, school bus, dog in front of house",
"limit":10,"print_urls":False}
paths = response.download(arguments)
#print complete paths to the downloaded images
print(paths)
it gives this error continuously:
Traceback (most recent call last):
File "/Users/*x*/Desktop/SchoolPython/PythonUVA/Webscrape.py", line 1, in <module>
from google_images_download import google_images_download
ModuleNotFoundError: No module named 'google_images_download'
I think it might not be looking in the right filepath or library but any other repo I tried previously did work.
Any help is greatly appreciated.
*edit for versions
(3.9UVA) MacBook-Pro-van-Flavia:Webscrape.py flavia$ which pip
/Users/flavia/PycharmProjects/3.9UVA/bin/pip
(3.9UVA) MacBook-Pro-van-Flavia:Webscrape.py flavia$ which python
/Users/flavia/PycharmProjects/3.9UVA/bin/python
(3.9UVA) MacBook-Pro-van-Flavia:Webscrape.py flavia$ pip list
Package Version
---------------------- -----------
async-generator 1.10
attrs 21.4.0
certifi 2022.5.18.1
cffi 1.15.0
charset-normalizer 2.0.12
cryptography 37.0.2
google-images-download 2.8.0
h11 0.13.0
idna 3.3
outcome 1.1.0
Pillow 9.1.1
pip 21.3.1
pycparser 2.21
pyOpenSSL 22.0.0
PySocks 1.7.1
requests 2.27.1
selenium 4.2.0
setuptools 60.2.0
sniffio 1.2.0
sortedcontainers 2.4.0
trio 0.20.0
trio-websocket 0.9.2
urllib3 1.26.9
wheel 0.37.1
wsproto 1.1.0

ImportError: No module named cryptography

I'm trying to run a script that is using "cryptography" module but when i run it says
No module named cryptography:
Traceback (most recent call last):
File "....\Desktop\script.py", line 12, in <module>
from cryptography import x509
ImportError: No module named cryptography
The module is correctly installed:
Package Version
cryptography 3.4.8
I'm using:
python 3.9
windows 10
*pip 21.2.4 from c:\program files\python39\lib\site-packages\pip (python 3.9)
Already tried to uninstall and install the module, already updated pip.
Any advice ?

Python - numpy: No module named '_ctypes'

I have to run a python 3 script on a centos 7 host. I've installed python3.8 side by side with python2 so it doesn't break yum.
When I'm running the script I need to run I get this error:
Traceback (most recent call last):
File "A2PTestSuit.py", line 8, in <module>
import pandas as pd
File "/usr/local/lib/python3.8/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy: No module named '_ctypes'
If I list the modules I see that pandas and numpy are installed:
python3 -m pip list
Package Version
--------------- ----------
certifi 2019.11.28
chardet 3.0.4
DateTime 4.3
idna 2.8
numpy 1.18.1
pandas 0.25.3
pip 19.3.1
python-dateutil 2.8.1
pytz 2019.3
requests 2.22.0
setuptools 41.2.0
six 1.13.0
urllib3 1.25.7
zope.interface 4.7.1
How can I get past this error?
You can try updating all of your packages in the command line using pip, or just use try: import ... except ImportError: continue
I've got same issue. Problem was solved after I change default interpreter (which was Python 3.8) in PyCharm

Unable to run daphne from inside virtualenv

I am trying to run daphne installed inside the virtualenv and the following are the errors:
Traceback (most recent call last):
File "/path-to-virtualenv/bin/daphne", line 7, in <module>
from daphne.cli import CommandLineInterface
File "/path-to-virtualenv/local/lib/python3.6/dist-packages/daphne/cli.py", line 7, in <module>
from .server import Server
File "/path-to-virtualenv/local/lib/python3.6/dist-packages/daphne/server.py", line 4, in <module>
from twisted.internet import asyncioreactor # isort:skip
ModuleNotFoundError: No module named 'twisted.internet'
Environment:
1. mac osx mojave
2. python 3.6.5
When I try to import the module twisted.internet after activating the virtualenv, it works without any problem.
When I try to run daphne without using the virtualenv (global install), it works without throwing any errors as shown.
Following are the packages installed (by pip install -U channels):
asgiref 2.3.2
async-timeout 3.0.0
attrs 18.2.0
autobahn 18.9.2
Automat 0.7.0
channels 2.1.3
constantly 15.1.0
daphne 2.2.2
Django 2.1.2
hyperlink 18.0.0
idna 2.7
incremental 17.5.0
pip 18.0
PyHamcrest 1.9.0
pytz 2018.5
setuptools 40.4.3
six 1.11.0
txaio 18.8.1
wheel 0.32.0

Categories

Resources