Getting this below error while trying to run ansible(version >2) with python 3.5.2
I have looked into the github issues terming it as resolved, but can't sort out what needs to be done. https://github.com/ansible/ansible/issues/16013
How to resolve this?
virtual#xxxxxxxxxx:~/ansible-spike> ansible all -m ping -vvv
Using /home/virtual/ansible-spike/ansible.cfg as config file
ERROR! Unexpected Exception: name 'urllib2' is not defined
the full traceback was:
Traceback (most recent call last):
File "/home/virtual/.pyenv/versions/3.5.2/bin/ansible", line 92, in <module>
exit_code = cli.run()
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/cli/adhoc.py", line 193, in run
result = self._tqm.run(play)
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/executor/task_queue_manager.py", line 202, in run
self.load_callbacks()
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/executor/task_queue_manager.py", line 171, in load_callbacks
for callback_plugin in callback_loader.all(class_only=True):
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/plugins/__init__.py", line 368, in all
self._module_cache[path] = self._load_module_source(name, path)
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/plugins/__init__.py", line 319, in _load_module_source
module = imp.load_source(name, path, module_file)
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 693, in _load
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/plugins/callback/hipchat.py", line 32, in <module>
from ansible.module_utils.urls import open_url
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/module_utils/urls.py", line 330, in <module>
if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib2, 'HTTPSHandler'):
NameError: name 'urllib2' is not defined
Urllib2 is specific to Python v2.
Urllib2 documentation at http://docs.python.org/library/urllib2.html:
The urllib2 module has been split across several modules in Python 3.0
named urllib.request and urllib.error.
I don't think Ansible is compatible with Python 3 yet.
The ansible python API does not support Python 3. The PyPI page lists only 2.6 and 2.7 .
Ansible is currently not able to run with Python3. That is also stated in the linked Github Issue.
If you are using
import urllib2
Instead, you can call the library as
import urllib.request
Then use it like
urllib.request.urlopen('your url goes here')
This should get rid of the error you are getting
Related
hope you're all fine
You'll see, I'm using PyCharm 2022.3 (Community Edition) with Python 3.9.7, and I'm trying to execute the following code:
#!/usr/bin/env python3
# Required libraries for the program.
import requests as req
from requests.auth import HTTPBasicAuth
import json
url = "https://your-domain.atlassian.net/rest/api/2/user"
auth = HTTPBasicAuth("your#email.com", "xXx_token_xXx")
headers = {
"Accept": "application/json"
}
query = {
'accountId': '934250915yfe67e125d6062v'
}
response = req.request(
"GET",
url,
headers=headers,
params=query,
auth=auth
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
It comes from: Jira REST API - Get user
And I'm getting the following error:
Traceback (most recent call last):
File "C:\Users\username\Desktop\GitHubProjects\Tests\email.py", line 4, in <module>
import requests as req
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\__init__.py", line 43, in <module>
import urllib3
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\__init__.py", line 11, in <module>
from . import exceptions
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\exceptions.py", line 3, in <module>
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 565, in module_from_spec
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 234, in create_module
return self.load_module(spec.name)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 209, in load_module
mod = mod._resolve()
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 118, in _resolve
return _import_module(self.mod)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 87, in _import_module
__import__(name)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 71, in <module>
import email.parser
File "C:\Users\username\Desktop\GitHubProjects\Tests\email.py", line 5, in <module>
from requests.auth import HTTPBasicAuth
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\auth.py", line 16, in <module>
from ._internal_utils import to_native_string
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\_internal_utils.py", line 10, in <module>
from .compat import builtin_str
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\compat.py", line 47, in <module>
from http import cookiejar as cookielib
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\http\cookiejar.py", line 36, in <module>
import urllib.parse, urllib.request
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1379, in <module>
if hasattr(http.client, 'HTTPSConnection'):
AttributeError: module 'http' has no attribute 'client'
The weird thing is... it only happens when I run the code like this:
Running code with Pycharm default runner
But, it works when I select "Run File in Python Console" (as you can see the choice in the image above)
So... I don't know what is going on
I have tried some things:
pip install http
pip install -U http
pip install -U setuptools
And a lot of other bunch of commands
I'm a bit lost on what to do...
Could you give me a hand?
Thanks in advance
The name of your file that you created is email.py. The name of a module required for the JIRA Python library to work is also called email. This causes a conflict which creates the error.
This is noticeable in your traceback:
import email.parser
File "C:\Users\username\Desktop\GitHubProjects\Tests\email.py", line 5, in <module>
You can fix this by renaming your file to something else.
I'm currently using the following code (as learned in the DataCamp courses I followed):
import pandas as pd
pd.read_excel('C:\Users\jeenb\OneDrive\Bureaublad\Master Finance\Master Thesis\Input Python\Training Set.xlsx')
I'm getting the following error message:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
I've tried the following as was suggested in this forum before:
pd.read_excel('C:\\Users\\jeenb\\OneDrive\\Bureaublad\\Master Finance\\Master Thesis\\Input Python\\Training Set.xlsx')
pd.read_excel(r'C:\Users\jeenb\OneDrive\Bureaublad\Master Finance\Master Thesis\Input Python\Training Set.xlsx')
pd.read_excel(r"C:\Users\jeenb\OneDrive\Bureaublad\Master Finance\Master Thesis\Input Python\Training Set.xlsx")
All of these give the following error message:
Traceback (most recent call last):
File "C:\Users\jeenb\AppData\Roaming\Python\Python310\site-packages\pandas\compat\_optional.py", line 126, in import_optional_dependency
module = importlib.import_module(name)
File "C:\Program Files\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'openpyxl'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
pd.read_excel(r"C:\Users\jeenb\OneDrive\Bureaublad\Master Finance\Master Thesis\Input Python\Training Set.xlsx")
File "C:\Users\jeenb\AppData\Roaming\Python\Python310\site-packages\pandas\util\_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "C:\Users\jeenb\AppData\Roaming\Python\Python310\site-packages\pandas\io\excel\_base.py", line 457, in read_excel
io = ExcelFile(io, storage_options=storage_options, engine=engine)
File "C:\Users\jeenb\AppData\Roaming\Python\Python310\site-packages\pandas\io\excel\_base.py", line 1419, in __init__
self._reader = self._engines[engine](self._io, storage_options=storage_options)
File "C:\Users\jeenb\AppData\Roaming\Python\Python310\site-packages\pandas\io\excel\_openpyxl.py", line 524, in __init__
import_optional_dependency("openpyxl")
File "C:\Users\jeenb\AppData\Roaming\Python\Python310\site-packages\pandas\compat\_optional.py", line 129, in import_optional_dependency
raise ImportError(msg)
ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
I'm typing this code in the IDLE Shell 3.10.2. Previously I got an error message while importing the pandas however since I don't get this anymore I feel like I fixed this.
Seems like you need to open your command prompt, activate the environment you are using and type: pip install openpyxl
I found the answer. Thought I would post it if anyone in the future would be struggeling with this and found this post. My slashes were facing the wrong way, just changing \ to / fixed the problem.
In my case of using pycharm, I needed to go to File -> settings -> Project: projectName -> Python interpreter. Then click on + button will show you a pop up window to install packages. Then you can search for openpyxl and get the latest package. Then click Install package to install it.
Here is my problem: I am working on the German text classification project. I use spacy for that and decided to fine-tune its pretrained BERT model to get better results. However, when I try to load it to the code, it shows me errors.
Here is what I've done:
Installed spacy-transformers: pip install spacy-transformers
Downloaded German BERT model: python -m spacy download de_trf_bertbasecased_lg. It was downloaded successfully and showed me: ✔ Download and installation successful
You can now load the model via spacy.load('de_trf_bertbasecased_lg')
Wrote the following code:
import spacy
nlp = spacy.load('de_trf_bertbasecased_lg')
And the output was:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
nlp = spacy.load('de_trf_bertbasecased_lg')
File "C:\Python\Python37\lib\site-packages\spacy\__init__.py", line 30, in load
return util.load_model(name, **overrides)
File "C:\Python\Python37\lib\site-packages\spacy\util.py", line 164, in load_model
return load_model_from_package(name, **overrides)
File "C:\Python\Python37\lib\site-packages\spacy\util.py", line 185, in load_model_from_package
return cls.load(**overrides)
File "C:\Python\Python37\lib\site-packages\de_trf_bertbasecased_lg\__init__.py", line 12, in load
return load_model_from_init_py(__file__, **overrides)
File "C:\Python\Python37\lib\site-packages\spacy\util.py", line 228, in load_model_from_init_py
return load_model_from_path(data_path, meta, **overrides)
File "C:\Python\Python37\lib\site-packages\spacy\util.py", line 196, in load_model_from_path
cls = get_lang_class(lang)
File "C:\Python\Python37\lib\site-packages\spacy\util.py", line 70, in get_lang_class
if lang in registry.languages:
File "C:\Python\Python37\lib\site-packages\catalogue.py", line 56, in __contains__
has_entry_point = self.entry_points and self.get_entry_point(name)
File "C:\Python\Python37\lib\site-packages\catalogue.py", line 140, in get_entry_point
return entry_point.load()
File "C:\Python\Python37\lib\site-packages\importlib_metadata\__init__.py", line 94, in load
module = import_module(match.group('module'))
File "C:\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Python\Python37\lib\site-packages\spacy_transformers\__init__.py", line 1, in <module>
from .language import TransformersLanguage
File "C:\Python\Python37\lib\site-packages\spacy_transformers\language.py", line 5, in <module>
from .util import is_special_token, pkg_meta, ATTRS, PIPES, LANG_FACTORY
File "C:\Python\Python37\lib\site-packages\spacy_transformers\util.py", line 2, in <module>
import transformers
File "C:\Python\Python37\lib\site-packages\transformers\__init__.py", line 20, in <module>
from .file_utils import (TRANSFORMERS_CACHE, PYTORCH_TRANSFORMERS_CACHE, PYTORCH_PRETRAINED_BERT_CACHE,
File "C:\Python\Python37\lib\site-packages\transformers\file_utils.py", line 37, in <module>
import torch
File "C:\Python\Python37\lib\site-packages\torch\__init__.py", line 81, in <module>
ctypes.CDLL(dll)
File "C:\Python\Python37\lib\ctypes\__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
If I run the same code in PyCharm, it also shows me these two lines before all of those above:
2020-05-19 18:00:55.132721: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not
load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
2020-05-19 18:00:55.132990: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart
dlerror if you do not have a GPU set up on your machine.
If I got it right, these two lines complain that I don't have a GPU. However, according to the docs, I should be able to use BERT even without GPU.
So I am really stuck right now and looking for your help.
I should also mention, that I used de_core_news_sm model before and it worked fine.
I have also already tried several solutions, but none of them worked. I tried:
this and this. I have also tried to uninstall all spacy-related libraries and installed them again. Didn't help either.
I am working with:
Windows 10 Home
Python: 3.7.2
Spacy: 2.2.4
Spacy-transformers: 0.5.1
Would appreciate any help or advice!
It's probably a problem with your installation of torch. Start in a clean virtual environment and install torch using the instructions here with CUDA as None: https://pytorch.org/get-started/locally/. Then install spacy-transformers with pip.
Try:
python -m spacy download de_trf_bertbasecased_lg
python -m spacy download de_trf_bertbasecased_lg-2.2.0
python -m spacy link de_trf_bertbasecased_lg
python -m spacy link de_trf_bertbasecased_lg-2.2.0
Or:
python -m spacy download de
python -m spacy.de.download all
Or download directly from:
https://deepset.ai/german-bert
Then load:
nlp = spacy.load(r'Path_To_File\de_trf_bertbasecased_lg-2.2.0')
I'm new to this. I have begun learning OpenCV with Python and following the course directions I've successfully created an Anaconda environment from which I can easily import CV2 and carry out my course. So far, I have experienced no problems in working with this environment.
Now, I would like to begin using Spyder which launches well from the default/base environment but does not launch from the "opencv-course" environment which I created. By contrast, Jupyter Labs and Notebooks launch well on either environment.
I've attempted to uninstall/reinstall Spyder using Administrator privileges when launching Anaconda, but to no avail.
Could anyone forward a suggestion?
Many thanks!
MD
The following error message is displayed:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\envs\opencv-course\Scripts\spyder-script.py", line 10, in
sys.exit(main())
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\app\start.py", line 205, in main
mainwindow.main()
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\app\mainwindow.py", line 3734, in main
mainwindow = run_spyder(app, options, args)
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\app\mainwindow.py", line 3590, in run_spyder
main.setup()
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\app\mainwindow.py", line 977, in setup
'spyder.plugins.{}'.format(plugin_name))
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\plugins\pylint\__init__.py", line 14, in
from .plugin import Pylint as PLUGIN_CLASS
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\plugins\pylint\plugin.py", line 29, in
from spyder.plugins.pylint.confpage import PylintConfigPage
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\plugins\pylint\confpage.py", line 16, in
from spyder.plugins.pylint.widgets.pylintgui import PylintWidget
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\plugins\pylint\widgets\pylintgui.py", line 37, in
from spyder.plugins.pylint.utils import get_pylintrc_path
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\plugins\pylint\utils.py", line 16, in
import pylint.config
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\pylint\config.py", line 54, in
import toml
ModuleNotFoundError: No module named 'toml'
After checking out this answer here:
Spyder failed to launch in Anaconda after update (4.1.2)
I've solved the problem by downgrading the version of Pylint from 2.5 to 2.4.4. It now works fine.
Many thanks!
MD
I'm using Python3.5 in Windows with pip version 8.0.2. I installed ddt library using 'pip install ddt'. While using ddt library in code, getting import error. How to get rid of this error?
import unittest
from selenium import webdriver
from ddt import ddt, data ,unpack
import time
#ddt
class Search(unittest.TestCase):
def setUp(self):
#some code
#data(("phones",2),("music", 5))
#unpack
def test_searchproducts(self, searchterm, results):
#some code
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
unittest.main()
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.5.4\helpers\pycharm\utrunner.py", line 120, in <module>
modules = [loadSource(a[0])]
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.5.4\helpers\pycharm\utrunner.py", line 41, in loadSource
module = imp.load_source(moduleName, fileName)
File "C:\Program Files (x86)\Python 3.5\lib\imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 693, in _load
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "C:\Users\murugamx\PycharmProjects\New Project\Selenium Learning\ddt.py", line 3, in <module>
from ddt import ddt, data ,unpack
ImportError: cannot import name 'ddt'
The name of your py file is ddt. This is an error. You cannot name your file after the name of a library that you are importing.
From the Python Doc:
When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. sys.path is initialized from these locations:
The directory containing the input script (or the current directory when no file is specified).
So when you use import, the first place it searches is your current directory. This is why your error occurred.