pytest does not finde third party lib but python does - python-3.x

I have an script that I want to test:
my script:
from jsonschema.exceptions import ValidationError
import traceback
from data_product.event_processor import DwhUnknownActionError
from data_product.gateway import DwhDataRankingError
...
my test file:
from iterator_processor import IteratorProcessor
calling: pytest will give this error message:
==================================================================================== ERRORS =====================================================================================
__________________________________________________________________ ERROR collecting iterator_processor_test.py __________________________________________________________________
ImportError while importing test module '/home/a05922/dwh-jobs/src/main/lib/python_lib/data_product/iterator_processor_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
iterator_processor_test.py:5: in <module>
from iterator_processor import IteratorProcessor
iterator_processor.py:4: in <module>
from jsonschema.exceptions import ValidationError
E ImportError: No module named 'jsonschema'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================ 1 error in 3.19 seconds ==========================================================================
calling python3 iterator_processor.py on the other hand gives me:
Traceback (most recent call last):
File "iterator_processor.py", line 7, in <module>
from data_product.event_processor import DwhUnknownActionError
ModuleNotFoundError: No module named 'data_product'
an error that I 100% expect because the file is in the data_product folder. (the script is meant to be called from outside)
what irritates me is that pytest can not find jsonschema while python3 findes the library without problems.
did anybody have a similar problem?
how do I fix this?
Is this a bug in the pytest library?
should I report this?
how do I report this?
how to I check if anybody has reported this already?

Related

the correct way to use nornir plugins

I am a beginner with nornir, I am trying to run nornir plugins but I am having these errors:
Traceback (most recent call last):
File "nornirpy/start.py", line 2, in <module>
from nornir.plugins.tasks.commands import commands
ModuleNotFoundError: No module named 'nornir.plugins.tasks.commands'
My start.py file is very basic:
from nornir import InitNornir
from nornir.plugins.tasks.commands import commands
from nornir.core.inventory import Host
from path.to import InventoryPlugin
import json
nr = InitNornir("nornirpy/config.yml")
print(json.dumps(Host.schema(), indent=4))
What is the issue? I am using poetry to organize my project, is there a step I forgot? its not clear to me how can I use plugins in my application.
Hello Somayyah Mohammed;
First, check the version of nornir you are using. If version > 2.4.0 then module nornir.plugins.tasks.commands is not there. You can remove the import command it should work.

ImportError: cannot import name 'cpyHook' from partially initialized module 'pyWinhook'

This has been plaguing me for a while now, and I'm not sure what to do about it. I've tried modifying the init.py pyWinhook script's imports, but to no avail. Here's the whole error:
Traceback (most recent call last):
File "d:\myuser\Documents\Python\evil_programs\keylogger.py", line 6, in <module>
import pyWinhook as pyHook
File "C:\Users\myuser\AppData\Roaming\Python\Python310\site-packages\pyWinhook\__init__.py", line 1, in <module>
from .HookManager import *
File "C:\Users\myuser\AppData\Roaming\Python\Python310\site-packages\pyWinhook\HookManager.py", line 1, in <module>
from . import cpyHook
ImportError: cannot import name 'cpyHook' from partially initialized module 'pyWinhook' (most likely due to a circular import) (C:\Users\myuser\AppData\Roaming\Python\Python310\site-packages\pyWinhook\__init__.py)
Thanks in advance
The way I fixed this is by installing Python 3.8.
Python 3.10 and 3.11 produced this issue.
I got this idea from the executable name on GitHub "pyWinhook-1.6.2.win-amd64-py3.8.exe"
Why it does not work with newer python, I have no clue.

my-voice-analysis myspsolution module not found error

we are using python library my-voice-analysis but getting myspsolution import error please tell what is the solution
import myspsolution as mysp
p="Audio" # Audio File title
c=r"speech.wav"
mysp.myspgend(p,c)
Traceback (most recent call last):
File "C:\Users\ADITYA\AppData\Local\Programs\Python\Python36\sp.py", line 1, in <module>
import myspsolution as mysp
ModuleNotFoundError: No module named 'myspsolution'
i know its a bit late and you probs dont need it anymore but
replace
import myspsolution as mysp
with
mysp=__import__("my-voice-analysis")

Unable to run python script, error shows ModuleNotFoundError: No module named 'src'

Below is the python script(selenium webdriver) I want to execute. But I see error is being thrown that ModuleNotFoundError: No module named 'src'. I see the module src(folder) exist. I am trying to execute this in command prompt. Can some one please help me where I'm doing wrong.
from src.pages.base_page import BasePage
from src.pages.login_page import LoginPage
import unittest
class Dispatcher(BasePage, unittest.TestCase):
def setup(self):
super(Dispatcher,self).setup()
def login_eoc(self):
self.login_page.login()
test output:
C:\NASAuto\tests>py test_dispatcher.py
Traceback (most recent call last):
File "test_dispatcher.py", line 1, in
from src.pages.base_page import BasePage
ModuleNotFoundError: No module named 'src'
run a command line, go to the python folder,
python.exe import src
and verify if python is able to import src. If not try to reinstall this module
Else
You need to add that directory to the path:
import sys
sys.path.append('../src')
Maybe put this into a module if you are using it a lot.
good luck

PyQt5 import Error

I am trying to create a GUI that I can all it from the terminal (Ubuntu here). The problem is, whenever I try to run the code from the terminal, I get the following message:
Traceback (most recent call last):
File "alert.pyw", line 3, in <module>
from PyQt5.QtCore import *
ImportError: No module named 'PyQt5'
The problem is: I only get this message when I try to call the program from the terminal using
python3 alert.pyw Hello
PyQt5 is installed and when I import it from the shell it (apparently) works fine...

Resources