ModuleNotFoundError only when starting by terminal, how to fix? - python

Running the following test script
import win32api
print(win32api.EnumDisplaySettings().DisplayFrequency) # just for testing
works absoultely fine out of my IDE PyCharm, but running this script via Terminal using "python test.py" produces the following error:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import win32api
ModuleNotFoundError: No module named 'win32api'
How can I fix this?

Related

why a pycharm is not worked when I used ctrl+shift+F10

the pycharm show my error when I try run the python file.
photo for the error in the pycharm
it is say
Testing started at 1:37 PM ...
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.2\plugins\python-ce\helpers\pycharm\_jb_pytest_runner.py", line 5, in <module>
import pytest
ModuleNotFoundError: No module named 'pytest'
Process finished with exit code 1
Empty suite

How to "import pjsua" in python on MAC

Am using python 2.7 and got error like "ImportError: No module named _pjsua" while using "import pjsua". I refered and tried some solution but no luck on those solutions.
pjsua: unable to import pjsua python module
Traceback (most recent call last):
File "", line 1, in
File "pjsua.py", line 59, in
import _pjsua
ImportError: No module named _pjsua

pyinstaller compiled scripts crash because of missing modules

I've tried compiling a Python program on my Mac, and all went well. I then moved to ubuntu, and can't even compile a hello world correctly:
I wrote the simplest hello world:
print("hello world")
then tried compiling it using:
pyinstaller --onefile hello.py
everything seemed to be fine, until I tried running it:
dist/hello
and got the following traceback:
[2886] mod is NULL - structTraceback (most recent call last):
File "/usr/lib/python3.6/struct.py", line 13, in <module>
from _struct import *
ModuleNotFoundError: No module named '_struct'
[2886] mod is NULL - pyimod02_archiveTraceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/PyInstaller-3.4.dev0+g5f91905-py3.6.egg/PyInstaller/loader/pyimod02_archive.py", line 28, in <module>
import struct
ModuleNotFoundError: No module named 'struct'
[2886] mod is NULL - pyimod03_importersTraceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/PyInstaller-3.4.dev0+g5f91905-py3.6.egg/PyInstaller/loader/pyimod03_importers.py", line 24, in <module>
from pyimod02_archive import ArchiveReadError, ZlibArchiveReader
ModuleNotFoundError: No module named 'pyimod02_archive'
Traceback (most recent call last):
File "PyInstaller-3.4.dev0+g5f91905-py3.6.egg/PyInstaller/loader/pyiboot01_bootstrap.py", line 15, in <module>
ModuleNotFoundError: No module named 'pyimod03_importers'
[2886] Failed to execute script pyiboot01_bootstrap
It seems weird as I don't import any modules explicitly, but I followed a suggestion to add the missing modules in hello.spec under hiddenimports. so I added
hiddenimports=['_struct', 'struct', 'pyimod02_archive','pyimod03_importers']
and tried compiling with
pyinstaller --onefile hello.spec
but got the exact same error as before when I tried to run the exe file.
What am I doing wrong?
I'm using pyinstaller 3.4.dev0+g5f91905 with Python 3.6.2 on Ubuntu 16.04.3

Raspberry Pi project - no module named error

Ok so im trying my first Raspberry Pi project https://www.youtube.com/watch?v=Y2QFu-tTvTI
i have followed the steps for installing open cv and the other dependencies but when i try to run it i get the following error
(cv) pi#raspberrypi:~/Smart-Security-Camera $ python main.py
Traceback (most recent call last):
File "main.py", line 3, in <module>
from mail import sendEmail
File "/home/pi/Smart-Security-Camera/mail.py", line 2, in <module>
from email.MIMEMultipart import MIMEMultipart
ImportError: No module named 'email.MIMEMultipart'
i then tried entering "sudo python main.py" and got a different messege but the same problem as shown below
(cv) pi#raspberrypi:~/Smart-Security-Camera $ sudo python main.py
Traceback (most recent call last):
File "main.py", line 5, in <module>
from camera import VideoCamera
File "/home/pi/Smart-Security-Camera/camera.py", line 2, in <module>
from imutils.video.pivideostream import PiVideoStream
ImportError: No module named imutils.video.pivideostream
finally i tried "sudo python3 main.py" and again different messege same issue.
(cv) pi#raspberrypi:~/Smart-Security-Camera $ sudo python3 main.py
Traceback (most recent call last):
File "main.py", line 1, in <module>
import cv2
ImportError: No module named 'cv2'
any help is appreciated

ImportError when running terminal command in python

There is this terminal command in which if I run someCommand my_file.txt, it works correctly..
When I tried to incorporate it into a python script as follows:
import os
os.system('someCommand /user_data/some_file.txt')
I was prompted with the following error:
Traceback (most recent call last):
File "/server/scripts/someCommand", line 6, in <module>
import os
ImportError: No module named os
Tried using subprocess but same error persists. How can I rectify this and why is it that os module error occurs?
In my python file, os is working for sure..

Categories