Failed to import 'keystoneauth1' ... albeit installed? - python

I am using python3 via brew on MacOs.
When I do
> python3 -c "import keystoneauth1"
I get:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'keystoneauth1'
But then:
> pip3 install keystoneauth1
Requirement already satisfied: keystoneauth1 in /usr/local/lib/python3.7/site-packages (3.9.0)
Requirement already satisfied: iso8601>=0.1.11 in /usr/local/lib/python3.7/site-packages (from keystoneauth1) (0.1.12)
Requirement already satisfied: os-service-types>=1.2.0 in /usr/local/lib/python3.7/site-packages (from keystoneauth1) (1.2.0)
Requirement already satisfied: stevedore>=1.20.0 in /usr/local/lib/python3.7/site-packages (from keystoneauth1) (1.28.0)
Requirement already satisfied: pbr!=2.1.0,>=2.0.0 in /usr/local/lib/python3.7/site-packages (from keystoneauth1) (4.1.0)
Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.7/site-packages (from keystoneauth1) (1.11.0)
Requirement already satisfied: requests>=2.14.2 in /usr/local/lib/python3.7/site-packages (from keystoneauth1) (2.19.1)
Requirement already satisfied: idna<2.8,>=2.5 in /usr/local/lib/python3.7/site-packages (from requests>=2.14.2->keystoneauth1) (2.7)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from requests>=2.14.2->keystoneauth1) (2018.4.16)
Requirement already satisfied: urllib3<1.24,>=1.21.1 in /usr/local/lib/python3.7/site-packages (from requests>=2.14.2->keystoneauth1) (1.23)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.7/site-packages (from requests>=2.14.2->keystoneauth1) (3.0.4)
Nothing else shows up there. When I then verify the installation, things look good:
> pip3 show keystoneauth1
Name: keystoneauth1
Version: 3.9.0
Summary: Authentication Library for OpenStack Identity
Home-page: https://docs.openstack.org/keystoneauth/latest/
Author: OpenStack
Author-email: openstack-dev#lists.openstack.org
License: UNKNOWN
Location: /usr/local/lib/python3.7/site-packages
Requires: stevedore, requests, pbr, os-service-types, six, iso8601
Required-by: openstacksdk, keystoneauth
But as shown, already importing that module doesn't work.
For me, the problem manifested itself after upgrading brew python to the lastest version 3.7.6.
I explicitly upgraded brew, and pip3 as well, but no luck.
And sorry for the repeated typos. The module name is really keystoneauth1.

I really don't understand what exactly is going on here.
So this isn't really an answer that explains and solves the issue, but the workaround that worked for me:
First, I force removed python brew uninstall --ignore-dependencies python
Then, I only installed it again brew install python
And afterwards, my scripts (that in the end used that import) work again without any problems?!

Related

Having problems installing modules on python (Mac)

I'm a bit new to using pip to install modules on Python. I believe I have pip installed, however when I try to use the module I've tried to install using pip it says there is no such module. I'll post terminal response to see what happened. I'd really appreciate if somebody can let me know if I'm making a mistake installing modules, thanks for your time.
faizrahman#138-38-186-80 ~ % sudo pip install matplotlib
Password:
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/faizrahman/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.
Requirement already satisfied: matplotlib in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (1.3.1)
Requirement already satisfied: numpy>=1.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) (1.8.0rc1)
Requirement already satisfied: python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) (1.5)
Requirement already satisfied: tornado in /Library/Python/2.7/site-packages (from matplotlib) (5.1.1)
Requirement already satisfied: pyparsing>=1.5.6 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib) (2.0.1)
Requirement already satisfied: nose in /Library/Python/2.7/site-packages (from matplotlib) (1.3.7)
Requirement already satisfied: singledispatch in /Library/Python/2.7/site-packages (from tornado->matplotlib) (3.4.0.3)
Requirement already satisfied: futures in /Library/Python/2.7/site-packages (from tornado->matplotlib) (3.3.0)
Requirement already satisfied: backports-abc>=0.4 in /Library/Python/2.7/site-packages (from tornado->matplotlib) (0.5)
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from singledispatch->tornado->matplotlib) (1.12.0)
faizrahman#138-38-186-80 ~ %
You will need to call pip from python3:
sudo python3 -m pip install matplotlib

Transforming python code to HDL using hls4ml

I am following this tutorial: https://fastmachinelearning.org/hls4ml/setup/QUICKSTART.html
when I give the command:
root#ubuntu:~/Desktop/vivado/hls4ml/example-models$ hls4ml convert -c keras-config.yml
hls4ml: command not found
What should I do? I tried
pip install hls4ml
I get this:
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
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. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: hls4ml in /home/mojito/.local/lib/python2.7/site-packages (0.2.0)
Requirement already satisfied: numpy in /home/mojito/.local/lib/python2.7/site-packages (from hls4ml) (1.16.6)
Requirement already satisfied: six in /home/mojito/.local/lib/python2.7/site-packages (from hls4ml) (1.14.0)
Requirement already satisfied: pyyaml in /home/mojito/.local/lib/python2.7/site-packages (from hls4ml) (5.3.1)
Requirement already satisfied: h5py in /home/mojito/.local/lib/python2.7/site-packages (from hls4ml) (2.10.0)
Requirement already satisfied: onnx>=1.4.0 in /home/mojito/.local/lib/python2.7/site-packages (from hls4ml) (1.6.0)
Requirement already satisfied: typing>=3.6.4; python_version < "3.5" in /home/mojito/.local/lib/python2.7/site-packages (from onnx>=1.4.0->hls4ml) (3.7.4.1)
Requirement already satisfied: protobuf in /home/mojito/.local/lib/python2.7/site-packages (from onnx>=1.4.0->hls4ml) (3.11.3)
Requirement already satisfied: typing-extensions>=3.6.2.1 in /home/mojito/.local/lib/python2.7/site-packages (from onnx>=1.4.0->hls4ml) (3.7.4.1)
Requirement already satisfied: setuptools in /home/mojito/.local/lib/python2.7/site-packages (from protobuf->onnx>=1.4.0->hls4ml) (44.1.0)
Try this:
$ git clone https://github.com/hls-fpga-machine-learning/hls4ml.git
$ cd hls4ml/
$ pip install .
Git repo: https://github.com/hls-fpga-machine-learning/models .
Also you can use pip as a module: $ python -m pip <command> [options]

Python cannot see module after installing via pip

I'm still trying to master the science of installing packages via pip. When I run pip to install geocoder, I get the following:
(base) C:\Users\MBSanders>python -m pip install geocoder
Requirement already satisfied: geocoder in c:\programdata\anaconda3\lib\site-packages (1.38.1)
Requirement already satisfied: requests in c:\programdata\anaconda3\lib\site-packages (from geocoder) (2.21.0)
Requirement already satisfied: future in c:\programdata\anaconda3\lib\site-packages (from geocoder) (0.17.1)
Requirement already satisfied: click in c:\programdata\anaconda3\lib\site-packages (from geocoder) (7.0)
Requirement already satisfied: six in c:\programdata\anaconda3\lib\site-packages (from geocoder) (1.12.0)
Requirement already satisfied: ratelim in c:\programdata\anaconda3\lib\site-packages (from geocoder) (0.1.6)
Requirement already satisfied: certifi>=2017.4.17 in c:\programdata\anaconda3\lib\site-packages (from requests->geocoder) (2019.3.9)
Requirement already satisfied: idna<2.9,>=2.5 in c:\programdata\anaconda3\lib\site-packages (from requests->geocoder) (2.8)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in c:\programdata\anaconda3\lib\site-packages (from requests->geocoder) (1.24.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\programdata\anaconda3\lib\site-packages (from requests->geocoder) (3.0.4)
Requirement already satisfied: decorator in c:\programdata\anaconda3\lib\site-packages (from ratelim->geocoder) (4.4.0)
When I run
os.getcwd()
in spyder/python, I get
'C:\\Users\\MBSanders'
My question is, why do I get
ModuleNotFoundError: No module named 'geocoder'
When I run
import geocoder
I'm somewhat new to python. Please let me know if additional info is needed to trouble shoot. I'm within a federal agency so I do not have admin rights.
When I run sys.path in the console, I get
sys.path
Out[12]:
['F:\\Users\\MBSanders',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\python37.zip',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\DLLs',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3',
'',
'C:\\Users\\MBSanders\\AppData\\Roaming\\Python\\Python37\\site-packages',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Pythonwin',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\IPython\\extensions',
'F:\\Users\\MBSanders\\.ipython']
Assuming you're running python on the terminal, and python is the command you're using to run it, try doing python -m pip install geocoder. That'll install it for the python build you want to use. Or if you know the full path to the python build you're using, you can do something similar like /path/to/python -m pip install geocoder.
if you are using python 3.7 or 3.8 you may need to pip3.7 or pip3.8 install if you OS is recognizing a 2.x version as default

Problems importing quandl module

I am trying to create a Data Science project using some Quandl dataset, but am receiving an error on import.
As i know quandl should be imported all in lowercase, as the documentation states here and here, my import goes as follows:
import quandl
Error:
ModuleNotFoundError: No module named 'quandl'
I installed quandl using pip install quandl. My pip list output is:
Package Version
--------------- ---------
asn1crypto 0.24.0
certifi 2019.6.16
cffi 1.12.3
chardet 3.0.4
cryptography 2.7
idna 2.8
inflection 0.3.1
more-itertools 5.0.0
ndg-httpsclient 0.5.1
numpy 1.16.4
pandas 0.24.2
pip 19.1.1
pyasn1 0.4.5
pycparser 2.19
pyOpenSSL 19.0.0
python-dateutil 2.8.0
pytz 2019.1
Quandl 3.4.8
requests 2.22.0
setuptools 41.0.1
six 1.12.0
urllib3 1.25.3
wheel 0.33.4
wincertstore 0.2
I don't have pip3, as I installed Python through my Anaconda installation. I am running a Jupyter Notebook in a virtual environment I created just for this project. Just so you know, python --version output is:
Python 3.7.3
The strange part occurs when i try running a one line python script with import quandl. This time the program runs without errors, which means that the cause of the ModuleNotFoundError: No module named 'quandl' is the jupyter notebook, which is not being able to properly find the quandl module.
As a last resource, I tried installing quandl inside jupyter notebook:
!pip install quandl
import quandl
Output:
Requirement already satisfied: quandl in c:\users\not_me\.conda\envs\quant\lib\site-packages (3.4.8)
Requirement already satisfied: pandas>=0.14 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (0.24.2)
Requirement already satisfied: pyOpenSSL in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (19.0.0)
Requirement already satisfied: inflection>=0.3.1 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (0.3.1)
Requirement already satisfied: numpy>=1.8 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (1.16.4)
Requirement already satisfied: more-itertools<=5.0.0 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (5.0.0)
Requirement already satisfied: pyasn1 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (0.4.5)
Requirement already satisfied: python-dateutil in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (2.8.0)
Requirement already satisfied: six in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (1.12.0)
Requirement already satisfied: ndg-httpsclient in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (0.5.1)
Requirement already satisfied: requests>=2.7.0 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from quandl) (2.22.0)
Requirement already satisfied: pytz>=2011k in c:\users\not_me\.conda\envs\quant\lib\site-packages (from pandas>=0.14->quandl) (2019.1)
Requirement already satisfied: cryptography>=2.3 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from pyOpenSSL->quandl) (2.7)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from requests>=2.7.0->quandl) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from requests>=2.7.0->quandl) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from requests>=2.7.0->quandl) (2019.6.16)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from requests>=2.7.0->quandl) (1.25.3)
Requirement already satisfied: asn1crypto>=0.21.0 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from cryptography>=2.3->pyOpenSSL->quandl) (0.24.0)
Requirement already satisfied: cffi!=1.11.3,>=1.8 in c:\users\not_me\.conda\envs\quant\lib\site-packages (from cryptography>=2.3->pyOpenSSL->quandl) (1.12.3)
Requirement already satisfied: pycparser in c:\users\not_me\.conda\envs\quant\lib\site-packages (from cffi!=1.11.3,>=1.8->cryptography>=2.3->pyOpenSSL->quandl) (2.19)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-614264e6071a> in <module>
1 get_ipython().system('pip install quandl')
----> 3 import quandl
ModuleNotFoundError: No module named 'quandl'
Try pip3 install quandl . It usually works for Python 3.x
You can use pip using the module syntax rather than the standalone CLI for when you want to make sure you are using the version of pip associated with that interpreter.
python -m pip install quandl
Or, since you are using Conda, you could also try installing quandl with the conda CLI.
conda install quandl (or whatever the package's name is for conda).
Try installing it by running
!pip install quandl
In a cell in a Jupyter notebook. If you have things set up correctly, there's a chance that will be the same version of pip you need.
The problem was that Jupyter was not properly recognizing my virtual environment. I found my answer here, the workaround is pretty self explanatory.

import boto3 error on Mac OS

I'm trying to install boto3 on my mac (high sierra 10.13.3) and tried to follow : https://github.com/boto/boto3. I had already installed python 3 using homebrew before, but when I tried to see pip --version, I get error.
So, I did
1) modify .bash_profile to add
alias pip=pip3
2) verify
$ pip --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
3)
$ pip install boto3
Collecting boto3
Downloading boto3-1.5.36-py2.py3-none-any.whl (128kB)
100% |████████████████████████████████| 133kB 474kB/s
Collecting botocore<1.9.0,>=1.8.50 (from boto3)
Downloading botocore-1.8.50-py2.py3-none-any.whl (4.1MB)
100% |████████████████████████████████| 4.1MB 376kB/s
Requirement already satisfied: s3transfer<0.2.0,>=0.1.10 in ./Library/Python/3.6/lib/python/site-packages (from boto3)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in ./Library/Python/3.6/lib/python/site-packages (from boto3)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in ./Library/Python/3.6/lib/python/site-packages (from botocore<1.9.0,>=1.8.50->boto3)
Requirement already satisfied: docutils>=0.10 in ./Library/Python/3.6/lib/python/site-packages (from botocore<1.9.0,>=1.8.50->boto3)
Requirement already satisfied: six>=1.5 in ./Library/Python/3.6/lib/python/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.9.0,>=1.8.50->boto3)
Installing collected packages: botocore, boto3
Found existing installation: botocore 1.8.20
Uninstalling botocore-1.8.20:
Successfully uninstalled botocore-1.8.20
Successfully installed boto3-1.5.36 botocore-1.8.50
4) just to make sure this was fine, I ran
$ pip3 install boto3
Requirement already satisfied: boto3 in /usr/local/lib/python3.6/site-packages
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /Users/ond983/Library/Python/3.6/lib/python/site-packages (from boto3)
Requirement already satisfied: s3transfer<0.2.0,>=0.1.10 in /Users/ond983/Library/Python/3.6/lib/python/site-packages (from boto3)
Requirement already satisfied: botocore<1.9.0,>=1.8.50 in /usr/local/lib/python3.6/site-packages (from boto3)
Requirement already satisfied: docutils>=0.10 in /Users/ond983/Library/Python/3.6/lib/python/site-packages (from botocore<1.9.0,>=1.8.50->boto3)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /Users/ond983/Library/Python/3.6/lib/python/site-packages (from botocore<1.9.0,>=1.8.50->boto3)
Requirement already satisfied: six>=1.5 in /Users/ond983/Library/Python/3.6/lib/python/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.9.0,>=1.8.50->boto3)
5) but, now when I ran import boto3 in Idle, I get error
import boto3
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import boto3
ModuleNotFoundError: No module named 'boto3'
I even tried to change path in .bash_profile, but it did not work.
Thoughts?
It worked for me to just copy all of packages with "bolo" in the name from the Python 3.7 folder to the Python 2.7 folder:
/usr/local/lib/python3.7/site-packages $ sudo cp -R boto* /Library/Python/2.7/site-packages/.

Categories

Resources