I installed Ansible 2.8.2 using dnf on Fedora 30. I have an Ansible plug-in that requires a library. Using pip3 install I installed the required library.
When I run ansible-playbook directly, I see a ModuleNotFoundError for that module.
But if I run python3 /usr/bin/ansible-playbook, the module is found.
How can I get Ansible as installed by dnf to see this library?
Edit: further info: as installed from dnf, the main Ansible script has a shebang for /usr/bin/python3 -s. If I remove the -s, this problem is solved.
What's the benefit that the repo maintainers were seeking in adding this -s flag?
Is there a case to be made for asking the repo maintainers to omit the flag?
How can I get pip3 to install the library I need into a directory that will be seen when the -s flag is in effect?
Edit: Here's the output of ansible --version, and thanks for asking.
ansible 2.8.2
config file = /home/jdashton/proj/ansible-ccharacter/ansible.cfg
configured module search path = ['/home/jdashton/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.7.4 (default, Jul 9 2019, 16:32:37) [GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]
This is different from the suggested duplicate question because that question describes a "remote" task being run on localhost, in which case Ansible uses the default "remote" python interpreter. In this question, the library is being called from a local plugin, under Ansible's own python process. The -s flag in the shebang line at the top of the /usr/bin/ansible script is preventing Ansible from seeing some local libraries.
Edit: Following the suggestion from #zigarn I tried removing the library and reinstalling it as root. This resulted in the library being reinstalled into the same directory /usr/local/lib/... as before. Is there a way to get pip3 to install into the system library?
Here are the commands I attempted:
# pip3 uninstall tenacity
Uninstalling tenacity-5.0.4:
Would remove:
/usr/local/lib/python3.7/site-packages/tenacity-5.0.4.dist-info/*
/usr/local/lib/python3.7/site-packages/tenacity/*
Proceed (y/n)? y
Successfully uninstalled tenacity-5.0.4
# pip3 install tenacity
Collecting tenacity
Using cached https://files.pythonhosted.org/packages/6a/93/dfcf5b1b46ab29196274b78dcba69fab5e54b6dc303a7eed90a79194d277/tenacity-5.0.4-py2.py3-none-any.whl
Requirement already satisfied: six>=1.9.0 in /usr/lib/python3.7/site-packages (from tenacity) (1.12.0)
Installing collected packages: tenacity
Successfully installed tenacity-5.0.4
# pip show tenacity
Name: tenacity
Version: 5.0.4
Summary: Retry code until it succeeeds
Home-page: https://github.com/jd/tenacity
Author: Julien Danjou
Author-email: julien#danjou.info
License: Apache 2.0
Location: /usr/local/lib/python3.7/site-packages
Requires: six
Required-by:
Also, for clarity, here is the source for the Ansible installation:
# dnf list ansible
Last metadata expiration check: 0:09:48 ago on Mon 12 Aug 2019 11:12:58 AM EDT.
Installed Packages
ansible.noarch 2.8.2-1.fc30 #updates
According to the documentation -s option of python is "Don’t add the user site-packages directory to sys.path."
So I would guess that you did pip3 install as your user instead as root, so the library was installed at your user side instead of system wide.
Try to reinstall the library with pip3 as root and it should be ok.
Related
I have been trying to run this project
https://github.com/udacity/FSND-Deploy-Flask-App-to-Kubernetes-Using-EKS
I installed all the dependencies.
I still did not make any adjustments. I need to run it first
but I get this error when I type the command
python main.py
this is the error i get:
Traceback (most recent call last):
File "main.py", line 8, in <module>
import jwt
ImportError: No module named jwt
I worked with similar errors before and managed to solve them but not with this one I could not figure out the source of the problem
Check if PyJWTY is in the requirements file or if is installed in you system, using: pip3 install PyJWT
You could also face this error if you have running on your machine two versions of python. So the correct command will be python3 main.py
I have hit the same issue with pyjwt 2.1.0 which was clearly installed in my venv as well as globally. What helped was to downgrade it to version 1.7.1
pip install "PyJWT==1.7.1"
run the app and then to reinstall newest version 2.1.0
pip install "PyJWT==2.1.0"
And the issue disappeared.
This project has requirements that need to be installed for it to work. These can be installed via pip, pip install -r requirements.txt (I've linked to the requirements file in the project), which you can read more about here.
What worked for me was using import jwt instead of import PyJWT. I am using version PyJWT-2.3.0.
jwt image on vscode
As you can see no errors in the above screenshot. The app runs without import errors.
Image of terminal
Faced the same issue. Am using a guest VM running ubuntu 16.04.
I have multiple versions of python installed - both 3.5 and 3.7.
After repeated tries with and without using virtualenv what worked finally is:
Create a fresh virtual environment using :
priya:~$ virtualenv -p /usr/bin/python3.7 fenv
Activate the virutal environment :
priya:~$ source ./fenv/bin/activate
Note : You can find the path for python3.7 by using whereis python:
priya:~$ whereis python
python: /usr/bin/python /usr/bin/python3.5m /usr/bin/python3.5 /usr/bin/python3.7 /usr/bin/python3.5m-config /usr/bin/python3.5-config /usr/bin/python2.7 /usr/bin/python3.7m /usr/bin/python2.7-config /usr/lib/python3.5 /usr/lib/python3.7 /usr/lib/python2.7 /etc/python /etc/python3.5 /etc/python3.7 /etc/python2.7 /usr/local/lib/python3.5 /usr/local/lib/python3.7 /usr/local/lib/python2.7 /usr/include/python3.5m /usr/include/python3.5 /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
Referenced link is : https://stackoverflow.com/questions/1534210/use-different-python-version-with-virtualenv#:~:text=By%20default%2C%20that%20will%20be,%2Flocal%2Fbin%2Fpython3
For your project - FSWD Nanodegree -
After you have activated your virtualenv, run pip install -r requirements.txt
You can test by :
(fenv) priya:FSND-Deploy-Flask-App-to-Kubernetes-Using-EKS :~$ python
Python 3.7.9 (default, Aug 18 2020, 06:24:24)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
import jwt
exit()
pip3 install flask_jwt_ex.. I was doing this without sudo. And then I was working on the program as sudo.
You have to have only PyJWT installed and not JWT. Make sure you uninstall JWT (pip uninstall JWT) and install PyJWT (pip install PyJWT)
I am getting the same error as in this 4 years old thread: bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
But I am using MacOS, IntelliJ and Conda / Python 3 as my environment. Things I have tried:
$ STATIC_DEPS=true sudo pip install lxml
and
$ pip install -U lxml
Collecting lxml
Downloading https://files.pythonhosted.org/packages/16/31/be98027f5cd909e698210092ffc7d2e339492bc82cc872557b05f2ba3546/lxml-4.2.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (8.7MB)
100% |████████████████████████████████| 8.7MB 2.8MB/s
Installing collected packages: lxml
Found existing installation: lxml 4.1.1
Uninstalling lxml-4.1.1:
Successfully uninstalled lxml-4.1.1
Successfully installed lxml-4.2.4
after that:
$ python3 -m pip install lxml
Requirement already satisfied: lxml in /anaconda3/lib/python3.6/site-packages (4.2.4)
But I still get the same error upon executing my script in IntelliJ:
File "/Users/blabla/katalog-scanner/KatalogScanner.py", line 149, in <module>
soup = BeautifulSoup(html, 'lxml')
File "/anaconda3/envs/katalog-scanner/lib/python3.6/site-packages/bs4/__init__.py", line 198, in __init__
% ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
I also tried switching to html5lib in my code, resulting in the same error, saying that html5lib was requested and not found. What else can I try?
I had multiple installations of Python on my machine, provided by
homebrew
Anaconda
easy_install
package managers. I deleted the anaconda instance completely (was directly under my macintosh-hd), removed easy_install and brew uninstall python --force to remove all the instances of python (2.7, 3.6, 3.7) I had in usr/local/bin
then I installed only with homebrew: brew install python3
then you need to link python and pip commands to python3/pip3 by opening
~/.bash_profile
putting this there and saving:
alias python='python3'
alias pip='pip3'
then refresh the terminal (maybe you need to restart it completely or even the OS):
source ~/.bashrc
then python --version should show the newest 3.x version an you should be able to do: (second command starts python interpreter, fourth ends it)
pip install beautifulsoup4
python
import bs4
exit()
Now you have to go to IntelliJ > File > Project Structure and add Python 3.x SDK to Plattform Settings (SDK) and set Project Settings > Project SDK to that SDK
Before I also had an IntelliJ .iml-file, but the project seems to work fine without
I'm trying to install eric6 on ubuntu 16.04 but am running into problems which look like issues with different python versions. I am running in virtualenv but it doesn't seem to be helping. Here's what I did:
Set up virtualenv:
kira#machine:~/Downloads/eric6-18.03$ virtualenv -p /usr/bin/python3 ~/envs/eric
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/kira/envs/eric/bin/python3
Also creating executable in /home/kira/envs/eric/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
Activated:
kira#machine:~/envs/ericc$ source bin/activate
(eric) kira#machine:~/envs/ericc$ eric
Installed qt:
(eric) kira#machine:~/Downloads$ ./qt-unified-linux-x64-3.0.2-online.run
(Seemed to install successfully - confirmed in dialog box)
Installed qscintilla:
(eric) kira#machine:~/Downloads$ pip3 install qscintilla
Collecting qscintilla
Using cached QScintilla-2.10.3-5.10.1-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl
Collecting PyQt5>=5.10.1 (from qscintilla)
Using cached PyQt5-5.10.1-5.10.1-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl
Collecting sip<4.20,>=4.19.4 (from PyQt5>=5.10.1->qscintilla)
Using cached sip-4.19.8-cp35-cp35m-manylinux1_x86_64.whl
Installing collected packages: sip, PyQt5, qscintilla
Successfully installed PyQt5-5.10.1 qscintilla-2.10.3 sip-4.19.8
Check python version, install eric - note picks up python version 2.7.12:
(eric) kira#machine:~/Downloads/eric6-18.03$ python -V
Python 3.5.2
(eric) kira#machine:~/Downloads/eric6-18.03$ sudo python install.py
Checking dependencies
Python Version: 2.7.12
Sorry, please install PyQt5.
Error: No module named PyQt5.QtCore
Tried without sudo, picks up python version 3.5.2:
(eric) kira#machine:~/Downloads/eric6-18.03$ python install.py
Checking dependencies
Python Version: 3.5.2
Found PyQt5
Found pyuic5
Found QScintilla2
Found QtGui
Found QtNetwork
Found QtPrintSupport
Found QtSql
Found QtSvg
Found QtWidgets
Found QtWebEngineWidgets
Qt Version: 5.10.1
sip Version: 4.19.8
PyQt Version: 5.10.1
QScintilla Version: 2.10.3
All dependencies ok.
Cleaning up old installation ...
Creating configuration file ...
Compiling user interface files ...
Compiling source files ...
Installing eric6 ...
Error: [Errno 13] Permission denied: '/usr/local/bin/eric6_api'
Try install with admin rights.
Installation complete.
I assume the problem is something to do with the python version changing but don't know how to fix it.
Kira
I figured it out - 'sudo python' execs the command directly so was using python2 despite being run in a virtual environment. (As per this answer). Eric now installs without errors. (But doesn't run, a different issue)
I have made a bug fix in a popular python package fastparquet https://github.com/dask/fastparquet and attempting to try it out on my machine. The package comes with a setup.py and so I have attempted to use that to install:
fastparquet $ python setup.py install
This completed and appears to have done the requisite installation of files to /usr/local/lib/python2.7/site-packages:
..
Adding python-dateutil 2.6.0 to easy-install.pth file
Using /usr/local/lib/python2.7/site-packages
Finished processing dependencies for fastparquet==0.1.0
However when we examine that location - specifically for the api.py file that was updated - it is still the original github version:
11:35:38/fastparquet $ll /usr/local/lib/python2.7/site-packages/fastparquet/api.py
-rw-r--r-- 1 sboesch admin 27294 Jun 19 17:18 /usr/local/lib/python2.7/site-packages/fastparquet/api.py
After having looked a bit into setup.py it seems that were a standard approach used across most python packages: https://docs.python.org/2/distutils/setupscript.html.
So then
am I misunderstanding how the install works /what it does?
I'm having trouble when I want to install Python 3 using Homebrew.
This is my console:
$ brew install python3
Warning: You are using OS X 10.12.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
Please create pull-requests instead of filing issues.
==> Installing dependencies for python3: readline, sqlite, gdbm, makedepend, openssl
==> Installing python3 dependency: readline
==> Downloading https://ftpmirror.gnu.org/readline/readline-6.3.tar.gz
Already downloaded: /Users/slorenzo/Library/Caches/Homebrew/readline-6.3.8.tar.gz
==> Downloading https://gist.githubusercontent.com/jacknagel/d886531fb6623b60b2af/raw/746fc543e56bc37
curl: (22) The requested URL returned error: 404 Not Found
Error: Failed to download resource "readline--patch"
Download failed: https://gist.githubusercontent.com/jacknagel/d886531fb6623b60b2af/raw/746fc543e56bc37a26ccf05d2946a45176b0894e/readline-6.3.8.diff
Does anyone know how I can solve this problem?
Thanks.
Try running:
If Homebrew was updated on Aug 10-11th 2016 and brew update always says Already up-to-date you need to run:
cd "$(brew --repo)" && git fetch && git reset --hard origin/master && brew update
You are using an old version of Homebrew. The patch file that's failing to download was removed from the recipe in September 2016, and the warning about macOS 10.12 being a "pre-release version" is clearly no longer correct.
Run brew update and try again.