Why is this ModuleNotFoundError error occuring? [duplicate] - python

This question already has answers here:
No Module Named ServerSocket
(5 answers)
Closed 3 years ago.
Traceback (most recent call last):
File "server.py", line 1, in <module>
import SocketServer
ModuleNotFoundError: No module named 'SocketServer'\

The Error is because you did not install the package.
Install the package, before importing them
For Python command prompt,
pip install package_name
pip install httpserver
For Anaconda Navigator prompt,
conda install package_name
When Importing Socketsever, all in small letters (Package got renamed in python3)
import socketserver

Related

How do you import a module right after installing it in the same file? [duplicate]

This question already has answers here:
How to install and import Python modules at runtime
(5 answers)
Closed 1 year ago.
I am trying to install and import this python module in the same file. I am adding the directory where I want networkX to be installed in PYTHONUSERBASE, and I even prepend it to the PATH.
#install and import networkx
os.environ['PYTHONUSERBASE'] = "some_other_directory/python_packages"
executeCommand('python3 -m pip install --user networkx[default]')
sys.path.insert(0, os.environ['PYTHONUSERBASE'])
importlib.invalidate_caches()
import networkx
However, I get this error:
Traceback (most recent call last):
File "file_that_runs_the_code.py", line 35, in <module>
import networkx
ModuleNotFoundError: No module named 'networkx'
Any help would be appreciated.
The answer posted by #Tom McLean did solve the issue, but I would like to point out the following:
The answer provided might throw errors for pip 10 or higher. If your version of pip is higher than 10, I recommend replacing
pip.main(['install', package])
with
os.system('pip install ' + package)
For more information on the errors that might be thrown if you are using pip10+, check out this link: https://github.com/pypa/pip/issues/5599

How to fix: ModuleNotFoundError: No module named 'scipy' import error [duplicate]

This question already has answers here:
ImportError: No module named scipy
(17 answers)
Closed 3 years ago.
I am setting up a speech recognition software using mozilla and want to use the pre-trained model.
This is for macosx, I have already installed pip and the related scipy file however my system cant seem to pull the scipy module when I run my python script. Could it be that this is installed in another directory from the virtual env itself?
Terminal
(deepspeech-venv) Chabanis-MacBook-Pro:deepspeech chabani$ pip3 list
Package Version
---------- -------
deepspeech 0.5.1
numpy 1.17.0
pip 19.2.1
scipy 1.3.1
setuptools 41.0.1
wheel 0.33.4
Python
import scipy.io.wavfile as wav // this is the issue here
Terminal - deepspeech path
(deepspeech-venv) Chabanis-MacBook-Pro:deepspeech chabani$ which deepspeech
/Users/chabani/tmp/deepspeech-venv/bin/deepspeech
=== RESTART: /Users/chabani/tmp/deepspeech-venv/lib/python3.7/activate.py ===
Traceback (most recent call last):
File "/Users/chabani/tmp/deepspeech-venv/lib/python3.7/activate.py", line 7, in <module>
import scipy.io.wavfile as wav
ModuleNotFoundError: No module named 'scipy'
try to run this command:
pip3 install scipy

Import Error for PyMySQL on Idle Python 3.6.5

I am trying to import PyMySQl in idle, but I am getting this error:
Traceback (most recent call last):
File "pyshell#1", line 1, in <module>
import PyMySQL
ModuleNotFoundError: No module named 'PyMySQL'
I tried to install the package from CMD by using py -m pip install PyMySQL and it ended with "Successfully installed PyMySQL-0.8.1". Do I have to do install this PyMySQL anywhere else as to make it work in idle using import command?

ImportError: No module named cv2 when executing Python script [duplicate]

This question already has answers here:
Cannot find module cv2 when using OpenCV
(24 answers)
Closed 5 years ago.
I need to execute a Python application, but I am getting this error:
Traceback (most recent call last): File "dataset.py", line 8, in import cv2 ImportError: No module named cv2
I have followed the face detection concept in 96 boards, but I keep getting above error message, when I run the script like this:
sudo python dataset.py
Have you installed openCV?
sudo apt-get install python-opencv
If you want install it with pip:
pip install opencv

ImportError: No module named 'pygsheets'

I installed pygsheets module with this command: pip install https://github.com/nithinmurali/pygsheets/archive/master.zip
When I tried to execute script, I got following error:
Traceback (most recent call last): File
"/usr/local/bin/speedtest-to-google", line 7, in
import pygsheets ImportError: No module named 'pygsheets'
I executed pip list and found: pygsheets (v1.1.2).
Use
pip3 install command to access it
Script uses Python3 packages, so command pip3 install has to be used.

Categories

Resources