ImportError: No module named dns.exception - python

I am trying to use the dnspython in my code but when it gets to the import statement, I get the following error:
>>> import DNS.resolver
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\python27\lib\site-packages\DNS\resolver.py", line 31, in <module>
import dns.exception
ImportError: No module named dns.exception
I have tried installing with pip, easy_install and manually from the git repo but nothing seems to do the trick. Any ideas??
Code:
import DNS.resolver
if __name__ == "__main__":
domain = 'hotmail.com'
for x in dns.resolver.query(domain, 'MX'):
print x.to_text()

Another thing you can do to fix problems with this package is to install python-dnspython again using Synaptic. (Whether no having previous problems about duplicity)
Sometimes if you try to install this package using pip could appear some problems like that:
Command python setup.py egg_info failed with error code 1 in
/tmp/pip_build_root/dnspython Storing debug log for failure in
/root/.pip/pip.log
Using Synaptic cleans the old files and install the new ones, from that package. I know this issue is solved but I wanted to add more information about this :)

That's because package and module names are lowercase (see PEP 8). This works just fine :
import dns.resolver
import dns.exception
You should also be careful that none of your own *.py filename conflicts with the dns package. Your *.py file should not be named dns.py. Pay also attention to the *.pyc files.

First, your code should be : import dns.resolver.
There seems to be an issue installing dnspython using pip, you should clone the dnspython repository using git and run the file setup.py as follows:
git clone https://github.com/rthalley/dnspython
cd dnspython\
python setup.py install
If you don't have git installed on your machine, you can just download the repository manually .

Related

ModuleNotFoundError: No module named 'cryptography'

these are the Error messages I am geeting on running any of my project modules.
Traceback (most recent call last):
File "C:\Users\hsnl\BlockchainCodesTutor\Wallet.py", line 3, in <module>
import Transactions
File "C:\Users\hsnl\BlockchainCodesTutor\Transactions.py", line 2, in <module>
import Signatures
File "C:\Users\hsnl\BlockchainCodesTutor\Signatures.py", line 2, in <module>
import cryptography
ModuleNotFoundError: No module named 'cryptography'
I have already installed the cryptography module and was working perfectly until today I start getting this message that " No module named 'cryptography'".
I have again installed the cryptography as well as pip package but still showing the same error.
There might be loose versions running on your system. Please try the following:
python -m pip uninstall cryptography
python -m pip install cryptography
You can also check out this with python -m to make sure you are not using a loose pip.
You might not have cryptogtaphy installed correctly. I see you are using windows. Open commandline as an administrator and run pip install cryptography again. Enshure that the installation finishes without any errors and consider to restart your python interpreter after installation.
For further help you should post more details like the output of pip and your code leading to the error, so a more detailed answer for your problem can be given.
Try download cryptography whl from here.
Then use pip install cryptography-XXX.whl
For example:
pip install cryptography-3.3.1-cp36-abi3-win_amd64.whl
And now just supports python2.7 and python3.6.

I have uploaded a Python package in pip, then pip installed this package, but I can't import this package in Python Interpreter

I have just uploaded a Python package into pip called hqc:
https://pypi.org/project/hqc/0.0.1/
then successfully pip installed the package using:
pip install hqc
but I can't seem to import the package in Python Interpreter. When I do this, I get the following error message:
>>> import hqc
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import hqc
ModuleNotFoundError: No module named 'hqc'
What am I missing? Do I need to set the environment variable PATH or is it something else?
In the folder where setup.py is, make a folder called hqc and put an empty file called __init__.py (thats two underscores on each side). Right now, there's no file to import so python fails when importing it.
hqc-0.0.1:
hqc:
You can test the package by going to the directory where setup.py is and running
pip install .
Before trying again, be sure to uninstall
pip uninstall hqc
I had a quick look at your github repository and found that the package name, i.e. your folder name is skltemplate.
So, your import will be: (verified it to be working)
import skltemplate
And found that skltemplate package exposes the following modeules:
TemplateClassifier, TemplateTransformer and TemplateEstimator.
You can import the above by doing:
from skltemplate import TemplateClassifier
Now, if you want your package to be named as hqc, you need to rename skltemplate directory to hqc AND run the setup.py again. (You can refer this stackoverflow answer for more details).
Ensure that you increment the package version inside setup.py before running it.

Trouble shooting when tring to install and import `stats_exporter` from `opencensus.ext.stackdriver`

Im trying to install and use stats_exporter from opencensus.ext.stackdriver using the following guide: opencensus-ext-stackdriver
after installing it through pip:
pip install opencensus-ext-stackdriver
Im trying to import it and:
from opencensus.ext.stackdriver import stats_exporter as stackdriver
ImportError: cannot import name 'stats_exporter' from 'opencensus.ext.stackdriver'
When comparing the Git repo, and my local venv/lib/python3.7/site-packages/... it seems like the pip version isn't compatible with Github , so i tried to install it though cloning, and using setup.py
pip install ../opencensus-python/contrib/opencensus-ext-stackdriver/dist/opencensus-ext-stackdriver-0.2.dev0.tar.gz
which gives me the following error:
(venv) Yehoshaphats-MacBook-Pro:present-value yehoshaphatschellekens$ pip install ../opencensus-python/contrib/opencensus-ext-stackdriver/dist/opencensus-ext-stackdriver-0.2.dev0.tar.gz
Processing /Users/yehoshaphatschellekens/opencensus-python/contrib/opencensus-ext-stackdriver/dist/opencensus-ext-stackdriver-0.2.dev0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/s2/y6vcdc1105s8xlpb12slr9z00000gn/T/pip-req-build-7m1ibdpd/setup.py", line 17, in <module>
from version import __version__
ModuleNotFoundError: No module named 'version'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/s2/y6vcdc1105s8xlpb12slr9z00000gn/T/pip-req-build-7m1ibdpd/
Similar errors of this type indicated that i need to upgrade setuptools, tried that also :(
This post suggests that it might related to the fact that i'm using python3, which isn't completable with version though i really need to install this package on my python3 venv.
Any Help on this issue would be great!
Try this:
#!/usr/bin/env python
import os
from opencensus.common.transports.async_ import AsyncTransport
from opencensus.ext.stackdriver import trace_exporter as stackdriver_exporter
from opencensus.trace import tracer as tracer_module
from opencensus.stats import stats as stats_module
def main():
sde = stackdriver_exporter.StackdriverExporter(
project_id=os.environ.get("PROJECT_ID"),
transport=AsyncTransport)
tracer = tracer_module.Tracer(exporter=sde)
with tracer.span(name='doingWork') as span:
for i in range(10):
continue
if __name__ == "__main__":
main()
and
grpcio==1.19.0
opencensus==0.3.1
opencensus-ext-stackdriver==0.1.1
NB The OpenCensus libraries need gRPC too.
You will need:
a GCP Project and it's Project ID (${PROJECT_ID})
a service account with roles/cloudtrace.agent and its key.
Then:
virtualenv venv
source venv/bin/activate
export PROJECT_ID=[[YOUR-PROJECT-ID]]
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/key.json
pip3 install --requirement requirements.txt
python3 stackdriver.py

ModuleNotFoundError after installing requests package

I am on Mac OS Sierra, with home-brew, pip and python3 installed. I Tried running a script that required the requests module, but I keep getting this error:
Traceback (most recent call last):
File "listing_seq.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Despite running:
sudo pip3 install requests
sudo pip install requests
sudo pip install requests --upgrade
Any suggestions?
Update:
When I try running using virtualenv I get:
Running virtualenv with interpreter /usr/local/bin/python3
ERROR: File already exists and is not a directory.
Please provide a different path or delete the file.
The most common error is having another file with the name of any of the libraries you requested in the same path.
The other possible error is if the python you are using to execute the file is not python 3 but rather the defalut python from your OSX. See the accepted answer on this for better understanding of a possible issue. Also share your code to identify the bug.

Python Module Import Error "ImportError: No module named mrjob.job"

System: Mac OSX 10.6.5, Python 2.6
I try to run the python script below:
from mrjob.job import MRJob
class MRWordCounter(MRJob):
def mapper(self, key, line):
for word in line.split():
yield word, 1
def reducer(self, word, occurrences):
yield word, sum(occurrences)
if __name__ == '__main__':
MRWordCounter.run()
I get the following error:
:~ vskarich$ python mrjob_test.py < words
Traceback (most recent call last):
File "mrjob_test.py", line 1, in <module>
from mrjob.job import MRJob
ImportError: No module named mrjob.job
I had used easy_install like so:
sudo easy_install mrjob
This command downloaded the needed .egg file, and my site-packages directory for python looks like this:
:~ vskarich$ cd /Library/Python/2.6/site-packages
:site-packages vskarich$ ls
PyYAML-3.09-py2.6-macosx-10.6-universal.egg
easy-install.pth
README
mrjob-0.2.0-py2.6.egg
boto-2.0b3-py2.6.egg
simplejson-2.1.2-py2.6-macosx-10.6-universal.egg
I am not sure what to do here as I am somewhat new to python; any help would be much appreciated. Thank you!
Two suggestions:
Make sure you don't have any file or directory permissions problems for the installed eggs and files in the site-packages directory.
If you have installed another instance of Python 2.6 (besides the Apple-supplied one in /usr/bin/python2.6), make sure you have installed a separate version of easy_install for it. As is, your output indicates it was almost certainly installed using the Apple-supplied easy_install in /usr/bin which is for the Apple-supplied Python. The easiest way to do that is to install the Distribute package using the new Python.
I had the same problem, I tried pip install mrjob, sudo easy_install mrjob. It looked like it installed successfully, but when I ran a simple example script, I got the import error.
I got it to work by following the instructions at: http://pythonhosted.org//mrjob/guides/quickstart.html#installation.
In a nutshell, I cloned the source code from github and ran python setup.py install. My problem might be different from yours, though. There was nothing in my site-packages directory for mrjob after running pip-install and easy_install.
mrjob package can be installed by running following command:
pip install mrjob
After installation, the error will be solved.
It worked in my case.

Categories