Ansible no longer works - python

I have been learning Ansible on Windows 10 through WSL (using Pengwin, a Debian-based Linux) and it's been working fine up until last night. This morning, it's as though it doesn't exist any more:
❯ ansible
Traceback (most recent call last):
File "/usr/bin/ansible", line 34, in <module>
from ansible import context
ModuleNotFoundError: No module named 'ansible'
Literally nothing has changed since last night. Even my computer has remained on. The only difference is that I had logged out of my terminal program.
I tried running pengwin-setup to re-install Ansible, but the issue persists.
Finally, I tried installing it via the instructions on Ansible's own site. However, things got even worse:
❯ sudo apt install software-properties-common
[sudo] password for sturm:
Reading package lists... Done
Building dependency tree
Reading state information... Done
software-properties-common is already the newest version (0.96.20.2-2.1).
0 upgraded, 0 newly installed, 0 to remove and 85 not upgraded.
❯ sudo apt-add-repository --yes --update ppa:ansible/ansible
gpg: keybox '/tmp/tmpg2r1t8x7/pubring.gpg' created
gpg: /tmp/tmpg2r1t8x7/trustdb.gpg: trustdb created
gpg: key 93C4A3FD7BB9C367: public key "Launchpad PPA for Ansible, Inc." imported
gpg: Total number processed: 1
gpg: imported: 1
gpg: no valid OpenPGP data found.
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 688, in addkey_func
func(**kwargs)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 386, in add_key
return apsk.add_ppa_signing_key()
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 273, in add_ppa_signing_key
cleanup(tmp_keyring_dir)
File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 234, in cleanup
shutil.rmtree(tmp_keyring_dir)
File "/usr/lib/python3.8/shutil.py", line 715, in rmtree
_rmtree_safe_fd(fd, path, onerror)
File "/usr/lib/python3.8/shutil.py", line 672, in _rmtree_safe_fd
onerror(os.unlink, fullname, sys.exc_info())
File "/usr/lib/python3.8/shutil.py", line 670, in _rmtree_safe_fd
os.unlink(entry.name, dir_fd=topfd)
FileNotFoundError: [Errno 2] No such file or directory: 'S.gpg-agent.extra'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apt/cache.py", line 570, in update
res = self._cache.update(fetch_progress, slist,
apt_pkg.Error: E:The repository 'http://ppa.launchpad.net/ansible/ansible/ubuntu groovy Release' does not have a Release file.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/apt-add-repository", line 168, in <module>
if not sp.add_source_from_shortcut(shortcut, options.enable_source):
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 759, in add_source_from_shortcut
cache.update(sources_list=new_debsrc_entry.file)
File "/usr/lib/python3/dist-packages/apt/cache.py", line 573, in update
raise FetchFailedException(e)
apt.cache.FetchFailedException: E:The repository 'http://ppa.launchpad.net/ansible/ansible/ubuntu groovy Release' does not have a Release file.
Now I'm out of options. How can I get Ansible running again?

Your issue is coming from the fact that you are using the instructions to install Ansible on an Ubuntu distribution, when, as you stated it, Pengwin is a Debian based one.
So you should use the chapter on how to install Ansible on Debian and not how to install Ansible on Ubuntu.
Better, still, because Pengwin is a very particular distribution, since it is a WSL one, you might want to try the installation via pip:
Ansible can be installed with pip, the Python package manager. If
pip isn’t already available on your system of Python, run the
following commands to install it:
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python get-pip.py --user
Then install Ansible:
$ pip install --user ansible
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-with-pip

Related

runsnake fails in ubuntu with error in squaremap

When I start runsnake with
$ runsnake test.profile
the window opens, but with no graphics and no source code (only the list of calls, etc. is present). On the console, I see the following error message:
11:18:17: Debug: Adding duplicate image handler for 'PNG file'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/wx/core.py", line 3282, in <lambda>
lambda event: event.callable(*event.args, **event.kw) )
File "/usr/lib/python3/dist-packages/runsnakerun/runsnake.py", line 701, in load
self.SetModel(self.loader)
File "/usr/lib/python3/dist-packages/runsnakerun/runsnake.py", line 738, in SetModel
self.squareMap.SetModel(tree, self.adapter)
File "/usr/lib/python3/dist-packages/squaremap/squaremap.py", line 221, in SetModel
self.UpdateDrawing()
File "/usr/lib/python3/dist-packages/squaremap/squaremap.py", line 247, in UpdateDrawing
self.Draw(dc)
File "/usr/lib/python3/dist-packages/squaremap/squaremap.py", line 257, in Draw
font = self.FontForLabels(dc)
File "/usr/lib/python3/dist-packages/squaremap/squaremap.py", line 267, in FontForLabels
font.SetPointSize(scale * font.GetPointSize())
TypeError: Font.SetPointSize(): argument 1 has unexpected type 'float'
I installed runsnake using
sudo apt-get install runsnake
The versions of the dependencies are, according to pip list:
RunSnakeRun 2.0.5
SquareMap 1.0.5
wxPython 4.0.7
My system is
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
A quick hack is to change the code that you run by modifying the code:
$ sudo $EDITOR /usr/lib/python3/dist-packages/squaremap/squaremap.py
Go to line 267
Then replace the line with:
font.SetPointSize(int(scale * font.GetPointSize()))
or hardcode someting:
font.SetPointSize(18)

Mac OS 11.4 Big Sur - fixing python cryptography package in /System/Library/Frameworks/Python.framework/Versions/2.7

I bought a MacBook Pro 13 M1 (16 GB RAM, 1 TB SSD) and I'm trying to get it setup for work and part of that is using python 2 (yes I know it's end of life, I still need to use it till we finish porting to go). I have some python packages I'd like to remove from my system python2 (I'm sure I must've run sudo pip install on these at some point, which I know was stupid, but what is done is done) and now that I'm on Big Sur I can't remove these packages. I tried disabling SIP until I can get them removed (csrutil disable from recovery), but now I'm getting errors that I can't remove files from a read only filesystem
sudo pip uninstall cryptography   2  14:34
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
WARNING: The directory '/Users/darren/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Found existing installation: cryptography 3.3.2
Uninstalling cryptography-3.3.2:
Would remove:
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography-3.3.2-py2.7.egg-info
Proceed (y/n)? y
ERROR: Exception:
Traceback (most recent call last):
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/pip/_internal/cli/base_command.py", line 223, in _main
status = self.run(options, args)
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/pip/_internal/commands/uninstall.py", line 90, in run
auto_confirm=options.yes, verbose=self.verbosity > 0,
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/pip/_internal/req/req_install.py", line 686, in uninstall
uninstalled_pathset.remove(auto_confirm, verbose)
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/pip/_internal/req/req_uninstall.py", line 403, in remove
moved.stash(path)
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/pip/_internal/req/req_uninstall.py", line 292, in stash
renames(path, new_path)
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/pip/_internal/utils/misc.py", line 355, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 323, in move
rmtree(src)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 270, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 275, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 273, in rmtree
os.remove(fullname)
OSError: [Errno 30] Read-only file system: '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/_der.py'
but I can't remount root as read/write and get this error when I try:
sudo mount -uw /
mount_apfs: volume could not be mounted: Permission denied
mount: / failed with 66
How do I remove these files from /System/Library if it's read only? Do I have to format my system and start from scratch now that mac os put these files in a read only filesystem or is there a way to remove them?
Edit:
So I have broken packages in /System/Library that are preventing fabric from running so I can't get our stuff up and running. The main one being the cryptography package. So I either need to fix these packages so fabric can run or remove them or something.
The other part that makes this such a pain is that I'm trying to run python 2 on an M1 Mac which means either using the built in python or using rosetta with an x86 python2 as I have found no method for installing arm python 2 on an M1 Mac (there isn't an installer from python.org or brew since python2 was end of life when the M1 Macs shipped).
Edit2:
Maybe these packages that I'm having issues with did ship with Mac OS as the package's folder's created timestamp is "Jan 1 01:00:00 2020" just like every other file & folder in that same folder. If so I guess I need to fix them somehow. When I try to run fab from the command line I get this error in the cryptography package:
fab
/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
from cryptography.hazmat.backends import default_backend
Traceback (most recent call last):
File "/Users/darren/Library/Python/2.7/bin/fab", line 5, in <module>
from fabric.main import program
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/fabric/__init__.py", line 3, in <module>
from .connection import Config, Connection
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/fabric/connection.py", line 16, in <module>
from paramiko.agent import AgentRequestHandler
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/__init__.py", line 22, in <module>
from paramiko.transport import SecurityOptions, Transport
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py", line 129, in <module>
class Transport(threading.Thread, ClosingContextManager):
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py", line 190, in Transport
if KexCurve25519.is_available():
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/kex_curve25519.py", line 30, in is_available
X25519PrivateKey.generate()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/primitives/asymmetric/x25519.py", line 39, in generate
from cryptography.hazmat.backends.openssl.backend import backend
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/backends/openssl/backend.py", line 117, in <module>
from cryptography.hazmat.bindings.openssl import binding
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/bindings/openssl/binding.py", line 14, in <module>
from cryptography.hazmat.bindings._openssl import ffi, lib
ImportError: dlopen(/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/bindings/_openssl.so, 2): Symbol not found: _DTLS_client_method
Referenced from: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/bindings/_openssl.so
Expected in: flat namespace
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py", line 120, in _join_lingering_threads
for thr in _active_threads:
TypeError: 'NoneType' object is not iterable
Error in sys.exitfunc:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py", line 120, in _join_lingering_threads
for thr in _active_threads:
TypeError: 'NoneType' object is not iterable
Has anyone else had this problem or have a fix for it?
I was able to install python2 for Apple Silicon/M1 from nix and then I had to manually install pip which let me install cryptography & cffi (I had libffi installed from brew). Here are the steps I used, I'm not sure if they're all necessary, but it's what I did:
Install Nix
see https://nixos.org/manual/nix/stable/#sect-macos-installation for more details, but if you have a mac with a T2 chip or M1 this will still be encrypted
sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume --daemon
Install python2 from nix
nix-env -i python-2.7.18
verify that you're using this python in a new terminal session (you'll need to start a new shell to get the updated path)
run which python
if it doesn't return something like /Users/user/.nix-profile/bin/python you'll want to add ~/.nix-profile/bin to the front of your path, start a new shell, and run which python again
Install pip
See https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py for more details, but if you curl the get-pip.py in this url and run it with python 2 it'll tell you to instead download and use the get-pip.py from https://bootstrap.pypa.io/pip/2.7/get-pip.py
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python ./get-pip.py
Use brew to install libiff and openssl#1.1
I had done this step previously and I'm not 100% sure it's necessary, but I believe it is
brew install libiff openssl#1.1
Add the following to your .bashrc, .zshrc, .profile, or wherever you set your environment variables:
export LDFLAGS="-L$(brew --prefix openssl#1.1)/lib"
export CFLAGS="-I$(brew --prefix openssl#1.1)/include"
use pip to install cryptography
pip install cryptography
After this I had a functional python with cryptography installed and I was then able to install fabric (via pip install fabric==1.14.1 since 1.14.1 is the version I need for this old project, use what you need)
Edit:
Thanks to #CharlesDuffy for all of his help and as he correctly mentions in the comments bellow, you could (and probably should) install all of the dependencies and cryptography from nix instead of using a combination of brew and nix. I had brew and the dependancies installed before I had Nix installed so I haven't tested it out, but it should work.

How to resolve error: Poetry was not installed with the recommended installer. Cannot update automatically

I installed poetry using on mac using: curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - several months ago.
When I run poetry self update -v I see the following error:
[RuntimeError]
Poetry was not installed with the recommended installer. Cannot update automatically.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/clikit/console_application.py", line 131, in run
status_code = command.handle(parsed_args, io)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/clikit/api/command/command.py", line 120, in handle
status_code = self._do_handle(args, io)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/clikit/api/command/command.py", line 171, in _do_handle
return getattr(handler, handler_method)(args, io, self)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cleo/commands/command.py", line 92, in wrap_handle
return self.handle()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/poetry/console/commands/self/update.py", line 64, in handle
raise RuntimeError(
This error has been there since installation. I never found a solution. If it helps, I have Poetry version 1.0.5 installed, and when I run which -a poetry I get /Library/Frameworks/Python.framework/Versions/3.8/bin/poetry
simply add POETRY_HOME to your global env will solve this problem
e.g. in linux, add this line to your .profile
export POETRY_HOME="$HOME/.poetry/bin"

How to Install python3.8 on debian 10?

i've installed debian 10.0.4 yesterday on my pc.
it had python version 3.7.3 installed on it , so i tried to update it to version 3.8.3 and now i have version 3.8.3 installed but when i try to install pip using the official get-pip.py it throws an exception . the details is :
Traceback (most recent call last):
File "<frozen zipimport>", line 520, in _get_decompress_func
ModuleNotFoundError: No module named 'zlib'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<frozen zipimport>", line 520, in _get_decompress_func
ModuleNotFoundError: No module named 'zlib'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<frozen zipimport>", line 568, in _get_data
File "<frozen zipimport>", line 523, in _get_decompress_func
zipimport.ZipImportError: can't decompress data; zlib not available
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "get-pip.py", line 23484, in <module>
main()
File "get-pip.py", line 198, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
from pip._internal.cli.main import main as pip_entry_point
File "<frozen zipimport>", line 241, in load_module
File "<frozen zipimport>", line 709, in _get_module_code
File "<frozen zipimport>", line 570, in _get_data
zipimport.ZipImportError: can't decompress data; zlib not available
i must mention that the python (python2.7) and pip for python 2.7 is working , and i tried to reinstall python using source compilation and i got another error while installing it (zlib error)
Installing Python 3.8 on Debian 10
Building Python 3.8 on Debian is a relatively straightforward process and will only take a few minutes.
Start by installing the packages necessary to build Python source:
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev liblzma-dev
Download the latest release’s source code from the Python download page with wget or curl. At the time of writing this article, the latest release is 3.8.2:
curl -O https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz
When the download is complete, extract the tarball:
tar -xf Python-3.8.2.tar.xz
Navigate to the Python source directory and run the configure script:
cd Python-3.8.2
./configure --enable-optimizations --enable-loadable-sqlite-extensions
The script performs a number of checks to make sure all of the dependencies on your system are present. The --enable-optimizations option will optimize the Python binary by running multiple tests, which will make the build process slower.
Run make to start the build process:
make -j 4
Modify the -j to correspond to the number of cores in your processor. You can find the number by typing nproc.
Once the build is done, install the Python binaries by running the following command as a user with sudo access:
sudo make altinstall
Do not use the standard make install as it will overwrite the default system python3 binary.
At this point, Python 3.8 is installed on your Debian system and ready to be used. You can verify it by typing:
python3.8 --version
Python 3.8.2
source: https://linuxize.com/post/how-to-install-python-3-8-on-debian-10/

Install Pyicu in python 3.x

My system is Windows 10 x64
Now I would like to install pyicu but I encounter with a problem like this
Collecting pyicu
Using cached PyICU-1.9.7.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "C:\Users\ANHVU\AppData\Local\Temp\pip-build-v5fb9ri4\pyicu\setup.py", line 12, in
ICU_VERSION = os.environ['ICU_VERSION']
File "C:\Users\ANHVU\AppData\Local\Programs\Python\Python35\lib\os.py", line 725, in getitem
raise KeyError(key) from None
KeyError: 'ICU_VERSION'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ANHVU\AppData\Local\Temp\pip-build-v5fb9ri4\pyicu\setup.py", line 26, in <module>
ICU_VERSION = check_output(('icu-config', '--version')).strip()
File "C:\Users\ANHVU\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 316, in check_output
**kwargs).stdout
File "C:\Users\ANHVU\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 383, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\ANHVU\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "C:\Users\ANHVU\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 955, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\ANHVU\AppData\Local\Temp\pip-build-v5fb9ri4\pyicu\setup.py", line 33, in <module>
''')
RuntimeError:
Please set the ICU_VERSION environment variable to the version of
ICU you have installed.
How can I resolve this? Help me pls.
You can download a corresponding whl file from Unofficial Windows Binaries for Python Extension Packages
For example, the latest version (as of Jan 13 2019) for your 64-bit Windows and Python3.7 version is PyICU‑2.2‑cp37‑cp37m‑win_amd64.whl
Then open the Windows Powershell console as Administrator, cd to the directory where you put the whl file and execute the following command:
python -m pip install .\PyICU‑2.2‑cp37‑cp37m‑win_amd64.whl
or (if you already have a previous PyICU version installed)
python -m pip install -U .\PyICU‑2.2‑cp37‑cp37m‑win_amd64.whl
For the record:
My system (Win 10, 64 bit, python 3.8) gave me the exact same error message.
The solution was to install the 32-bit version of the PyICU whl file, not the 64 bit version.

Categories