Python can't import dns package - python-3.x

I wanna learn coding in python, my first project should display dns setting from domains.
I use python 3.5 on my ubuntu 16.04 server : here the code from my dns.py:
#!/usr/bin/python3
import dns.resolver
r = dns.resolver.query('padaru.de', 'a')
print (r)
the output is:
Traceback (most recent call last):
File "./dns.py", line 4, in <module>
import dns.resolver
File "/home/users/boogieman/www/bin/dns.py", line 4, in <module>
import dns.resolver
ImportError: No module named 'dns.resolver'; 'dns' is not a package
my dns modul are here:
/usr/local/lib/python3.5/dist-packages/dns
but I have an python2.7/dist-packages/-dir too, and this directory is empty.
It's possible that, my script wanna use the module from the python2.7 dir?
can't find other issues there :/ can somebody help me with this problem?

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.

ModuleNotFoundError: No module named 'torch._C'

I want to import the torch,but then the interpreter return this result,i have no idea how to deal with it
Traceback (most recent call last):
File "D:/Programing/tool/Python/learn_ml_the_hard_way/ML/scipy1.py", line 1, in <module>
import torch
File "D:\Programing\python\Anaconda3.5\lib\site-packages\torch\__init__.py", line 84, in <module>
from torch._C import *
ModuleNotFoundError: No module named 'torch._C'
I had the same problem and followed the instructions in this link
You can also find the torch path with this command if needed:
sudo find / -iname torch
In my case it was issue with python version, created python 3.7 environment and re-installed it. worked just fine
Initially I was running in a Conda environment got this error. Just deactivated the environment now it works.

Can't import cv2 in Python 2.7 linux

I'm trying to get OpenDroneMap to run on my linux mint machine. I've been working my way through a number of problems in the current release's dependency chain.
At the moment, I'm stumped on getting the OpenCV module, cv2 to import.
OpenCV is required by an OpenDroneMap dependency, OpenSfM and it's one of the OpenSfM py files that tries to import the module cv2.
Anyway, running OpenDroneMap generates the error:
Traceback (most recent call last):
File "~/OpenDroneMap/src/OpenSfM/bin/opensfm", line 10, in <module>
from opensfm import commands
File "~/OpenDroneMap/src/OpenSfM/opensfm/commands/__init__.py", line 3, in <module>
import extract_metadata
File "~/OpenDroneMap/src/OpenSfM/opensfm/commands/extract_metadata.py", line 5, in <module>
from opensfm import dataset
File "~/OpenDroneMap/src/OpenSfM/opensfm/dataset.py", line 12, in <module>
import cv2
ImportError: dynamic module does not define init function (PyInit_cv2)
b
quitting cause:
PYTHONPATH=~/OpenDroneMap/lib/python2.7/dist-packages "~/OpenDroneMap/src/OpenSfM/bin/run_all" opensfm
returned with code 256.
From what I can tell, the import error cause typically suggests that the cv2 module was not found. I've ensured that cv2.so does exist in the path specified, as well as the usr/lib/python27/dist-packages path, where it seems to me it should really be looking...
In any case, I was hoping someone might be able to give me some direction on what to try next.

Running Python in Windows

Am new to python, i installed python 3.2 in my windows and tried the following code,
import urllib, urllister
usock = urllib.urlopen("http://diveintopython.net/")
parser = urllister.URLLister()
parser.feed(usock.read())
usock.close()
parser.close()
for url in parser.urls: print(url)
Its showing,
Traceback (most recent call last):
File "demo.py", line 1, in <module>
import urllib, urllister
ImportError: No module named urllister
How to add that module?
urllister is not part of the standard library.
You must download file urllister.py from here, and save it next to the script you're running.

Resources