I'm trying to launch an ansible playbook from a python script but I have the following error:
Traceback (most recent call last):
File "py_runner.py", line 1, in <module>
from ansible import context
ModuleNotFoundError: No module named 'ansible'
I'm using one of the code that I found on this link Running ansible-playbook using Python API and here is my ansible location:
ansible 2.8.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Could you help me figure out why my pythom program doesn't found the ansible module?
Many thanks
Please ignore that.
A figured out that I had two python releases installed on the server: Python2.7 and 3.6.
The Python3.6 directory doesn't have the module installed so I need to launch the program using Python2.7.
Related
as you can see from the code snippet below, ansible's executable seems to be ignoring the ansible_python_interpreter variable. Without resorting to an inventory file (this is for a gitlab pipeline based on hashicorp's packer - which calls ansible), how could I enforce ansible to use whatever python version I have? In this case, it's an Ubuntu 18.04, so I want to switch from python-2.7 to python-3.6.
Another related cause couldto be the fact that ansibles pkg (policy?) always installs python-2.7 on bionic.
root#ubuntu18:~# ansible --version
ansible 2.9.27
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.17 (default, Feb 27 2021, 15:10:58) [GCC 7.5.0]
root#ubuntu18:~# /usr/bin/python3.6 --version
Python 3.6.9
root#ubuntu18:~# ansible --version -e 'ansible_python_interpreter=/usr/bin/python3.6'
ansible 2.9.27
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.17 (default, Feb 27 2021, 15:10:58) [GCC 7.5.0]
root#ubuntu18:~#
My last resort seems to be installing ansible using pip3, but that would require a significant rewrite of both the pipeline yaml and packer's json.
Any help would be greatly appreciated.
Cheers
You have not provided any evidence that the parameter is being ignored. ansible_python_intepreter applies to the execution of modules on the targets, not to the execution of Ansible itself.
The Ansible control process always uses the Python interpreter it was installed under; the best way to change this is to change your install process.
A few weeks ago, I installed Selenium on a Linux Mint (an Ubuntu derivative) machine and developped a few Puthon scrapping scripts with it. Everyhting worked fine.
Now, I am trying to replicate the installation on another machine, also under Linux Mint, and I am stuck. This is what I get:
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> l_driver = webdriver.Firefox()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/webdriver.py", line 62, in __init__
firefox_options.binary_location = self.binary if isinstance(self.binary, basestring) else self.binary._get_firefox_start_cmd()
NameError: name 'basestring' is not defined
I installed Selenium exactly the same way as before:
sudo pip3 install -U Selenium
The installation seems ok and does not report any error. Previously, I had installed pip3 with the apt command:
sudo apt-get install python3-pip
Also no errors or problems. I installed a couple of other Python modules with pip3 and they all work.
None of my scripts will run. They all fail on the first line where I want to open a Firefox WebDriver. On my earlier machine however, everything still works fine and all my scripts run flawlessly as before.
What the heck is going on ? What am I missing ? Is this a Python 2 vs. 3 issue (the 'basestring' name points that way) ?
It's a bug in the latest version of selenium (2.53.0).
I successfully compiled net-snmp-5.7.3 on Ubuntu. :D This is the specific version of Ubuntu:
Linux loserBox 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
I seemed to have successfully installed the Python bindings for net-snmp too. This is included with the net-nsmp download as a different folder titled 'Python' with the setup.py file in it. However when running the command python setup.py test I noticed some problems. I thought this may be nothing to worry about so I went ahead and executed python setup.py install I was not sure what the instructions meant in the README file that say, "python setup.py test (requires a locally running agent w/ config provided)". So, this is why I installed it with the failed test or something. Anyways, I am not sure if this is a problem or not.
After successfully installing the python bindings for net-snmp I switched directories back to my Desktop and opened up an interactive python shell. From here I imported the netsnmp module and received the below error. It almost looks like there is a spelling error in the variable netsnmp_memdup that is throwing the error in the Traceback. This looks like a problem with the C code and not python.
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import netsnmp
/usr/lib/python2.7/dist-packages/pkg_resources.py:1031: UserWarning:
/home/loser_user/.python-eggs is writable by group/others and vulnerable to attack
when used with get_resource_filename. Consider a more secure location
(set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
warnings.warn(msg, UserWarning)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-x86_64/egg/netsnmp/__init__.py", line 1, in <module>
File "build/bdist.linux-x86_64/egg/netsnmp/client.py", line 1, in <module>
File "build/bdist.linux-x86_64/egg/netsnmp/client_intf.py", line 7, in <module>
File "build/bdist.linux-x86_64/egg/netsnmp/client_intf.py", line 6, in __bootstrap__
ImportError: /home/loser_user/.python-eggs/netsnmp_python-1.0a1-py2.7-linux-x86_64.egg-
tmp/netsnmp/client_intf.so: undefined symbol: netsnmp_memdup
Does anyone know how to fix this problem? I looked on the mailing list page on sourceforge for this project and searched the supoort archives but did not find anything.
Thanks for listening to a crazy man's Python problems.
Happy Holidays,
user_loser
Alrgihty, thanks to my good friend Naveen, we have traced this down to an actual bug in the Python Net-SNMP bindings in the 5.7.3.
There are two ways around this:
Use the Python bindings in Net-SNMP 5.7.2
See this commit on our fork of the Net-SNMP Python library (only started yesterday so bear with us): https://github.com/fgimian/easysnmp/commit/fa86af977b563f65e7d70243752d48b94a8d5686 and replicate this in your download of Net-SNMP.
OK so for school I am having to set up a computer using Ubuntu 12.04 to run Python programs written in Python 3.3. I was aware that 12.04 came with Python 3.2, so I followed the procedure in the first reply in this thread to install Python 3.3:
Now when I open the Terminal, I type ~/bin/py to get it to display the following at the top of the terminal:
Python 3.3.2 (default, Dec 10 2013, 11:35:01)
[GCC 4.6.3] on Linux
Type "help", "copyright", "credits", or "license" for more information.
>>>
So far so good. Now I am having trouble replicating the functionality of the same Python program that I execute as follows on my Windows laptop.
(This is what I type in the Python commandline on windows)
import filereader
from filereader import *
reader = filereader("C:\Python33\ab1copy.ab1")
reader.show_entries()
The end result is a directory of data types found in the file. The filereader class is located in Python33\Lib\site-packages\filereader.py in the above example. On the Ubuntu computer its location is Python-3.3.2\Lib\site-packages\filereader.py. Also on Ubuntu, the ab1copy.ab1 file is located in the home directory for now.
After I achieve the recognition of Python 3.3.2 in the Ubuntu Terminal as noted above, how can I replicate my program's functionality there? If I try to put in the same first command "import filereader" I get the following error:
>>>import filereader
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'filereader'
try this in the terminal
python3 your_file.py
It's probably not in your python path.
Check this to see where it looks for your source:
import sys
print(sys.path)
I tried to run one of my AppEnigne projects (python) today but it will no longer launch, this is the stack trace I'm getting.
*** Running dev_appserver with the following flags:
--admin_console_server= --port=8080 --clear_datastore
Python command: /usr/bin/python2.5
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py", line 77, in <module>
run_file(__file__, globals())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py", line 73, in run_file
execfile(script_path, globals_)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_main.py", line 138, in <module>
import logging
ImportError: No module named logging
I thought it could be a python 2.6 error but I adjusted my path to /usr/bin/python2.5 and its still not working. I'm running OSX 10.6.8 and have the latest AppEngineLauncher 1.5.4
The only thing I changed recently that might have affected this is when I updated my XCode to the latest version, v4.2 build 4C199
Has anyone else faced this issue recently?
EDIT
I can't import logging from the terminal either, same message. Here's Python's path.
Chriss-MacBook-Pro:bin chris$ /usr/bin/python2.5
Python 2.5.4 (r254:67916, Aug 2 2010, 20:09:39)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python25.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload',
'/Library/Python/2.5/site-packages',
'/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/PyObjC',
'/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/wx-2.8-mac-unicode']
>>>
Thanks to Nick and Wobble I've figured it out. I recently updated my XCode install to the 4.2 GM release and removed the beta versions. Along the way OSX forgot where gcc was installed and prevented it from compiling the python modules like logging. This resulted in missing .pyo files inside /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python25/logging which prevents import logging from working.
Logging wasn't the only module that wasn't compiled, just the first one AppEngine tried to import.
Solution: uninstall and do a clean install of XCode. Make sure gcc can be found on your PATH and everything should be fine.