Pip Import Error No module named logging - python

Whenever I am running any command using pip, I am getting the following error. I have tried uninstalling python,pip and reinstalling them back again. I also used
sudo apt-get autoremove
and then updated and upgraded
sudo apt-get update
sudo apt-get upgrade
And once again installed python and pip. I am still getting the same error whenever I run any command using pip.
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
File "/home/shashank/.local/lib/python2.7/site-packages/pip/__init__.py", line 28, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/home/shashank/.local/lib/python2.7/site-packages/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/home/shashank/.local/lib/python2.7/site-packages/pip/download.py", line 34, in <module>
from pip.utils.logging import indent_log
ImportError: No module named logging
Can anybody suggest a solution?
Edit
I have read the question which is used to flag my question as a duplicate.
I am not using a virtual environment and I have already tried the answer given over there. Moreover I am encountering a problem when I run pip in my terminal
The output of the command
locate logging
/etc/java-9-openjdk/logging.properties
/home/shashank/.local/share/Trash/files/logging.py
/home/shashank/.local/share/Trash/files/logging.pyc
/home/shashank/.local/share/Trash/info/logging.py.trashinfo
/home/shashank/.local/share/Trash/info/logging.pyc.trashinfo
/lib/lsb/init-functions.d/50-ubuntu-logging
/usr/lib/jvm/java-9-openjdk-amd64/jmods/java.logging.jmod
/usr/lib/jvm/java-9-openjdk-amd64/lib/logging.properties
/usr/lib/pm-utils/sleep.d/00logging
/usr/lib/python2.7/logging
/usr/lib/python2.7/dist-packages/pip/utils/logging.py
/usr/lib/python2.7/dist-packages/pip/utils/logging.pyc
/usr/lib/python2.7/logging/__init__.py
/usr/lib/python2.7/logging/__init__.pyc
/usr/lib/python2.7/logging/config.py
/usr/lib/python2.7/logging/config.pyc
/usr/lib/python2.7/logging/handlers.py
/usr/lib/python2.7/logging/handlers.pyc
/usr/lib/python3/dist-packages/UnityTweakTool/config/logging.py
/usr/lib/python3/dist packages/UnityTweakTool/config/__pycache__/logging.cpython-35.pyc
/usr/lib/python3/dist-packages/plainbox/impl/logging.py
/usr/lib/python3/dist-packages/plainbox/impl/__pycache__/logging.cpython-35.pyc
/usr/lib/python3.5/logging
/usr/lib/python3.5/logging/__init__.py
/usr/lib/python3.5/logging/__pycache__
/usr/lib/python3.5/logging/config.py
/usr/lib/python3.5/logging/handlers.py
/usr/lib/python3.5/logging/__pycache__/__init__.cpython-35.pyc
/usr/lib/python3.5/logging/__pycache__/config.cpython-35.pyc
/usr/lib/python3.5/logging/__pycache__/handlers.cpython-35.pyc
/usr/share/icons/hicolor/16x16/categories/applications-microblogging-panel.png
/usr/share/icons/ubuntu-mono-dark/categories/22/applications-microblogging-panel.svg
/usr/share/icons/ubuntu-mono-dark/categories/24/applications-microblogging-panel.svg
/usr/share/icons/ubuntu-mono-light/categories/22/applications-microblogging-panel.svg
/usr/share/icons/ubuntu-mono-light/categories/24/applications-microblogging-panel.svg
/usr/src/linux-headers-4.4.0-59-generic/include/config/fusion/logging.h
/usr/src/linux-headers-4.4.0-59-generic/include/config/scsi/logging.h
/usr/src/linux-headers-4.4.0-59-generic/include/config/sfc/mcdi/logging.h
/usr/src/linux-headers-4.4.0-62-generic/include/config/fusion/logging.h
/usr/src/linux-headers-4.4.0-62-generic/include/config/scsi/logging.h
/usr/src/linux-headers-4.4.0-62-generic/include/config/sfc/mcdi/logging.h

It's obvious from your traceback that you have a version of pip installed in your home directory, at /home/shashank/.local/lib/python2.7/site-packages/pip/. Delete that. If you aren't certain what else is contained there, better delete all /home/shashank/.local/lib/python2.7. After you delete it, it will use the system's default pip that you installed with apt.

Related

How do I get my scikit-learn library to work on windows using pip package installer?

I am using the windows command prompt to install the scikit learn library using the command pip install -U scikit-learn. However, whenever I try to import it into my program I get an error stating that there is no module named 'sklearn'. Also, whenever I download the library using pip, for some reason, my pip package installer seems to break and pip is no longer recognized as a command on my cmd. I have numerous other modules which work perfectly fine so I don't see a reason as to why I can't get this specific library to work. I am still quite new to this kind of thing, so maybe I am missing something.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in
import sklearn
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn_init_.py", line 82, in
from .base import clone
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\base.py", line 17, in
from .utils import IS_32BIT
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils_init.py", line 20, in
from scipy.sparse import issparse
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse_init_.py", line 227, in
from .base import *
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse\base.py", line 4, in
from .sputils import (isdense, isscalarlike, isintlike,
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse\sputils.py", line 8, in
from scipy._lib._util import prod
ModuleNotFoundError: No module named 'scipy._lib._util'
Try to upgrade pip to newest version by python -m pip install --upgrade pip considering you are still using Windows. And then try to download sciKitLearn by pip install sklearn
This is how I had solved my problem but keep note that it was about a year ago
If all this doesn't work, try VirtualEnv.

Ubuntu 16.04 pip seems broken

I was installing some packages, after that pip doesn't work anymore. Even if I try some command such as: sudo pip show requets I get this error.
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip import main
File "/usr/local/lib/python3.5/dist-packages/pip/__init__.py", line 28, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/lib/python3.5/dist-packages/pip/vcs/subversion.py", line 9, in <module>
from pip.index import Link
File "/usr/local/lib/python3.5/dist-packages/pip/index.py", line 31, in <module>
from pip.wheel import Wheel, wheel_ext
File "/usr/local/lib/python3.5/dist-packages/pip/wheel.py", line 6, in <module>
import compileall
File "/usr/lib/python3.5/compileall.py", line 20, in <module>
from concurrent.futures import ProcessPoolExecutor
File "/usr/local/lib/python3.5/dist-packages/futures-3.1.1-py3.5.egg/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/usr/local/lib/python3.5/dist-packages/futures-3.1.1-py3.5.egg/concurrent/futures/_base.py", line 381
raise exception_type, self._exception, self._traceback
^
SyntaxError: invalid syntax
Thanks anyways!
You seem to have installed the futures package on python3.5.
That is a python2 only backport of a python3.2+ package.
You need to delete /usr/local/lib/python3.5/dist-packages/futures-3.1.1-py3.5.egg then it should work again.
You don't need that package on python3.5, it is already included in the standard library.
You should try reinstalling pip if nothing else is working for you. Execute the following:
sudo apt-get install --reinstall python2.7
sudo apt-get purge python-pip
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
sudo python get-pip.py
That should work. After doing that, run pip --version and please post the results.
Looks like your pip is broken, can you check pip version using pip --version and maybe upgrading pip to latest version might solve your problem, just try
sudo pip install --upgrade pip , now check pip version and if it still shows the old version try to recreate the simlink using ln -s /usr/local/bin/pip /usr/bin/

No module named 'requests_toolbelt'

So, I'm trying to upload my python app to heroku but when I use a script with 'requests_toolbelt' it says is not found.
Here my log:
Traceback (most recent call last):
File "girl.py", line 12, in <module>
from Coffe import CoffeAPI
File "/app/CoffeAPI/__init__.py", line 29, in <module>
from requests_toolbelt import MultipartEncoder
ImportError: No module named 'requests_toolbelt'
Here my requeriments.txt:
requests-toolbelt==0.7.1
moviepy==0.2.2.11
requests==2.13.0
Do I need an specific buildpack to run 'requests_toolbelt'?
Try installing requests-toolbelt. Use below command to do that.
# pip install requests-toolbelt
Have you tried to install the package using your command line?
Navigate your command line to the path where you have python installed:
>path\easy_install.exe requests_toolbelt
or
>path\easy_install.exe requests-toolbelt
or
>path\python -m pip install requests_toolbelt
Hopefully this helps you
I had the same issue, and my solution was that
the package was installed by root user
and after changing the access properties of the files, it worked fine.
The command I specifically issued (on ubuntu-like system) was:
sudo chown $USER.$USER -R ~/.local/lib/python3.7/site-packages/

How to install ruamel.yaml python library offline?

I am trying to install ruamel.yaml python library in a Centos 7 machine where I don't have internet connection. I tried this:
installed libyaml-devel, python-devel, python-pip using a local repository
downloaded ruamel.yaml-0.13.14.tar & ruamel.ordereddict-0.4.6.tar(dependency) from pypi.
now I am able to install ruamel.ordereddict using pip install .,
but when I tried to install ruamel.yaml in the same way, I got the following exception:
[root#limulus ruamel.yaml-0.13.14]# pip install .
Processing /tmp/python/ruamel.yaml-0.13.14
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/setuptools/__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "/usr/lib/python2.7/site-packages/setuptools/extension.py", line 5, in <module>
from setuptools.dist import _get_unpatched
File "/usr/lib/python2.7/site-packages/setuptools/dist.py", line 7, in <module>
from setuptools.command.install import install
File "/usr/lib/python2.7/site-packages/setuptools/command/__init__.py", line 8, in <module>
from setuptools.command import install_scripts
File "/usr/lib/python2.7/site-packages/setuptools/command/install_scripts.py", line 3, in <module>
from pkg_resources import Distribution, PathMetadata, ensure_directory
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 74, in <module>
import parser
File "parser.py", line 77, in <module>
from ruamel.yaml.error import MarkedYAMLError # type: ignore
File "/usr/lib64/python2.7/site-packages/ruamel/__init__.py", line 5, in <module>
__import__('pkg_resources').declare_namespace(__name__)
AttributeError: 'module' object has no attribute 'declare_namespace'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-oOWX1x-build/
What is the correct way of installing a python library in offline mode?
It looks like you have been expanding the tar files, which is not necessary, but I am not sure if that is the reason why you get this error, you probably are also missing the typing dependency.
What you shouldn't do is use the system installed pip, it is almost out of date and on some systems actually causes problems because of unfixed bugs in those old versions.
What you also should not do is install packages using pip outside of a Python virtualenv, as this might break your system when it updates/overwrites things in the systems site-packages/dist-packages directory. The solution provided below only installs pip/wheels/virtualenv in the system directory, that is AFAIK safe, but there are ways around that as well if it would necessary.
You should also consider using the provided wheels to install packages. That way C extension don't need compilation.
On a machine that is online do:
mkdir /tmp/offline
cd /tmp/offline
# your python-pip installed pip might not support wheels
wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz
wget https://pypi.python.org/packages/a7/37/947b4329c4a3c72093b6c8e9b4be8c7f10c32dbb78848d3a234ce01c059d/wheel-0.30.0a0.tar.gz
wget https://pypi.python.org/packages/6f/86/3dc328ee7b1a6419ebfac7896d882fba83c48e3561d22ddddf38294d3e83/virtualenv-15.1.0-py2.py3-none-any.whl
Now download the required wheels (.tar.gz if not available):
wget https://pypi.python.org/packages/96/4b/5251bf469f37e49e0c92f841b5b3ef01a1c9d652cc018df470e5ae235eb8/ruamel.ordereddict-0.4.9-cp27-cp27mu-manylinux1_x86_64.whl
wget https://pypi.python.org/packages/63/40/c38b857ec6a083e534ee9a9f655741120d4bfd9139232681f976cf44272b/ruamel.yaml-0.13.14-cp27-cp27mu-manylinux1_x86_64.whl
wget https://pypi.python.org/packages/b6/0c/53c42edca789378b8c05a5496e689f44e5dd82bc6861d1ae5a926ee51b84/typing-3.5.3.0.tar.gz
Copy the six files to a new directory your offline system, and there do
sudo pip install pip*.tar.gz wheel*.tar.gz
sudo pip install virtualenv*
virtualenv ~/ruamel
source ~/ruamel/bin/activate
pip install typing* ruamel*
That gives you a virtualenv with ruamel.yaml installed, just add your application in there as well.
The downloads used here are current as of 2017-01-07, you can get more up-to-date ones using your browser (on the on-line system) if necessary.

Python Elasticsearch urllib3 exception

I have to use python-elasticsearch library on a machine where I could only execute programs. I am trying to use elasticsearch module by appending sys.path as mentioned below. I am facing below issue. It looks like the problem related to what is mentioned here
https://github.com/elastic/elasticsearch-py/issues/253 . But how do I resolve this when I dont have sudo access or any sort of upgrade access.
**Note :**I don't have sudo access on this machine so I cannot have venv, pip etc.
import sys
sys.path.append('/tmp/elasticpy/elasticsearch-2.3.0')
from elasticsearch import Elasticsearch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/elasticpy/elasticsearch-2.3.0/elasticsearch/__init__.py", line 17, in <module>
from .client import Elasticsearch
File "/tmp/elasticpy/elasticsearch-2.3.0/elasticsearch/client/__init__.py", line 5, in <module>
from ..transport import Transport
File "/tmp/elasticpy/elasticsearch-2.3.0/elasticsearch/transport.py", line 4, in <module>
from .connection import Urllib3HttpConnection
File "/tmp/elasticpy/elasticsearch-2.3.0/elasticsearch/connection/__init__.py", line 3, in <module>
from .http_urllib3 import Urllib3HttpConnection
File "/tmp/elasticpy/elasticsearch-2.3.0/elasticsearch/connection/http_urllib3.py", line 2, in <module>
import urllib3
ImportError: No module named urllib3
#nehal Thanks for your suggestion I was able to get it fixed. Please find the
series of steps I used to install
Used easy_install to install package pip
Appended PYTHONPATH
used pip to install virtualenv
Activated new virtualenv
Installed elasticsearch using pip
export PYTHONPATH="${PYTHONPATH}:/tmp/pytest/"
easy_install --install-dir /tmp/pytest/ pip
pip install virtualenv --prefix /tmp/pytest/
export PATH="${PATH}:/tmp/pytest:/tmp/pytest/bin"
export PYTHONPATH="${PYTHONPATH}:/tmp/pytest/lib/python2.7/site-packages"
cd /tmp/
virtualenv venv
source venv/bin/activate
pip install elasticsearch

Categories