Python: Httplib2 Module Not Found - python

I tried to import the module but i am getting the error shown below:-
sh-3.2# python -V
Python 2.6.4
sh-3.2# python -c "import httplib2"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named httplib2
How to fix this Error?

httplib2 is not part of the Python standard library. It's an external package you must install yourself.
using pip:
pip install httplib2

You need to install the httplib2 package from your package manager.
On Ubuntu:
sudo apt-get install python-httplib2

I suppose you could start by installing httplib2.

Download it?
Make sure it's on your PYTHONPATH

Suppose you can start by installing it like :
$ pip install httplib2
you can try the same thing with easy install too, or if you wanted to install in locally and not over the network then go to httplib2 github .
Clone/download it to your computer. Now go to the downloaded httplib2 folder location and run the setup.py like this :
$ setup.py install
If on windows, make sure you have successfully installed python first and have set the environment variables path successfully.
This is a common command to install any module using pip or by locally downloading and looking for the foldert location>setup.py file and trying the second command mentioned above.

FOR WINDOWS:
if python is installed & set as environment variable
python -m pip install httplib2

Related

package installed but cannot import it

I have successfully installed the bitarray package, because I can find it after the command: pip list.
But when I try to import it I get :
>>> from bitarray import bitarray
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
from bitarray import bitarray
ModuleNotFoundError: No module named 'bitarray'
What can I try to solve it ?
I'm using Ubuntu 18.04.5 .
You can install package as python3 -m pip install bitarray. May be when you did pip install bitarray, it install your package for python2.
Ubuntu comes with two python versions. If you just ran pip install x it installed it into python 2.7. You're probably using python3, so you wanna install with pip3 install x
Just to make sure you are running correct pip, try running "pip -V" or "pip --version", it gives you which version of python it refers to. In terminal it looks something like this pip version check
Its also possible that you might have pip for say python 2.7, pip3 for python 3.6, and pip3.7 for python 3.7, if you have multiple versions of python installed.
For simplicity you can set the most frequently used pip version as pip by setting an alias in ~/.bashrc. This is done by adding the following line in bashrc:
alias pip=pip3.6.
After this you can try and install the packages and import it swiftly.

Understanding twisted installation in Linux Mint

I wanted to install twisted on my Mint Linux 17 machine. I downloaded the source file (from here). I extracted the contents into a folder, changed to that folder and ran the following commands to install the library.
$ python setup.py build
$ sudo python setup.py install
I had to use sudo for the second command, because I could not get it to work without sudo.
Everything was installed without any problem, but when I try to run a sample code I got a import error.
$ python datagram.py
Traceback (most recent call last):
File "datagram.py", line 3, in <module>
from twisted.internet.protocol import DatagramProtocol
ImportError: No module named twisted.internet.protocol
But it works when I run the same with sudo.
$ sudo python datagram.py
Why is this happening? What do I need to fix to get twisted programs running without the need for sudo?
sudo setup.py install is one of the ways to screw up your installation of Python and its libraries. Other members of the club include sudo easy_install <package> and sudo pip install <package>.
If you want to do a system-wide installation of a Python library (or any piece of software, probably): use your system package manager.
If you want to install a version of a Python library different from the version available from your system package manager, use virtualenv and install the library into that.

Debian-box and pip3 install <module> [duplicate]

I am trying to pip install the MySQL-python package, but I get an ImportError.
Jans-MacBook-Pro:~ jan$ /Library/Frameworks/Python.framework/Versions/3.3/bin/pip-3.3 install MySQL-python
Downloading/unpacking MySQL-python
Running setup.py egg_info for package MySQL-python
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in <module>
from setup_posix import get_config
File "./setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in <module>
from setup_posix import get_config
File "./setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python
Storing complete log in /Users/jan/.pip/pip.log
Jans-MacBook-Pro:~ jan$
Any ideas?
You can instead use the mysqlclient package as a drop-in replacement for MySQL-python. It is a fork of MySQL-python with added support for Python 3.
I had luck with simply
pip install mysqlclient
in my python3.4 virtualenv after
sudo apt-get install python3-dev libmysqlclient-dev
which is obviously specific to ubuntu/debian, but I just wanted to share my success :)
In Python 3, ConfigParser has been renamed to configparser for PEP 8 compliance. It looks like the package you are installing does not support Python 3.
Here is a code that should work in both Python 2.x and 3.x
Obviously you will need the six module, but it's almost impossible to write modules that work in both versions without six.
try:
import configparser
except:
from six.moves import configparser
pip install configparser
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py
Then try to install the MYSQL-python again.
That Worked for me
MySQL-python is not supported on python3 instead of this you can use mysqlclient
If you are on fedora/centos/Red Hat install following package
yum install python3-devel
pip install mysqlclient
Additional info:
Python 2x
import ConfigParser
Python 3x
import configparser
Compatibility of Python 2/3 for configparser can be solved simply by six library
from six.moves import configparser
If you are using CentOS, then you need to use
yum install python34-devel.x86_64
yum groupinstall -y 'development tools'
pip3 install mysql-connector
pip install mysqlclient
I was having the same problem. Turns out, I needed to install python3 devel on my centos. First, you need to search for the package that is compatible with your system.
yum search python3 | grep devel
Then, install the package as:
yum install -y python3-devel.x86_64
Then, install mysqlclient from pip
pip install mysqlclient
Do pip3 install PyMySQL and then pip3 install mysqlclient.
Worked for me
I got further with Valeres answer:
pip install configparser
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py
Then try to install the MYSQL-python again. That Worked for me
I would suggest to link the file instead of copy it. It is save to update. I linked the file to /usr/lib/python3/ directory.
For me the following command worked:
sudo python3 -m pip install mysql-connector
Try this solution which worked fine for me.
Basically it's to reinstall/upgrade to latest version of mysql from brew, and then installing mysqlclient or MySQL-Python from global pip3 instead of virtualenv pip3.
Then accessing the virtualenv and successfully install mysqlclient or MySQL-Python.
I still have this issue, so I go to /usr/lib/python3.8 and type as sudoer:
cp configparser.py ConfigParser.py
You may have another python version than 3.8.
Following #MaciejNg I tried making a copy, which didn't work:
sudo cp ./env/lib/python3.8/site-packages/configparser.py ./env/lib/python3.8/site-packages/ConfigParser.py
Because configparser.py and ConfigParser.py are identical, I renamed the file:
sudo mv ./env/lib/python3.8/site-packages/configparser.py ./env/lib/python3.8/site-packages/ConfigParser.py
how about checking the version of Python you are using first.
import six
if six.PY2:
import ConfigParser as configparser
else:
import configparser
I run kali linux- Rolling and I came across this problem ,when I tried running cupp.py in the terminal, after updating to python 3.6.0. After some research and trial I found that changing ConfigParser to configparser worked for me but then I came across another issue.
config = configparser.configparser()
AttributeError: module 'configparser' has no attribute 'configparser'
After a bit more research I realised that for python 3 ConfigParser is changed to configparser but note that it has an attribute ConfigParser().
I was getting the same error on Mac OS 10, Python 3.7.6 & Django 2.2.7. I want to use this opportunity to share what worked for me after trying out numerous solutions.
Steps
Installed Connector/Python 8.0.20 for Mac OS from link
Copy current dependencies into requirements.txt file, deactivated the current virtual env, and deleted it using;
create the file if not already created with; touch requirements.txt
copy dependency to file; python -m pip3 freeze > requirements.txt
deactivate and delete current virtual env; deactivate && rm -rf <virtual-env-name>
Created another virtual env and activated it using; python -m venv <virtual-env-name> && source <virtual-env-name>/bin/activate
Install previous dependencies using; python -m pip3 install -r requirements.txt
base on your OS is centos use python3
if you don't known where is configparser.py or ConfigParser.py
pip3 install configparser
find / -name "configparser.py"
cd /usr/local/lib/python3.6/site-packages(base on your environment )
cp configparser.py ConfigParser.py
solved the issue
Kindly to see what is /usr/bin/python pointing to
if it is pointing to python3 or higher change to python2.7
This should solve the issue.
I was getting install error for all the python packages. Abe Karplus's solution & discussion gave me the hint as to what could be the problem.
Then I recalled that I had manually changed the /usr/bin/python from python2.7 to /usr/bin/python3.5, which actually was causing the issue. Once I reverted the same. It got solved.
This worked for me
cp /usr/local/lib/python3.5/configparser.py /usr/local/lib/python3.5/ConfigParser.py

How to install Python docx module on mac osx

I'm trying to generate .docx files using Python. I searched the web and posts here and found a module:
https://github.com/mikemaccana/python-docx/blob/master/README.markdown
It says to install using easy_install or pip, which I have no idea how to do. I went to python website to install pip from the instructions given on python documentation:
http://guide.python-distribute.org/installation.html
So I downloaded and followed directions:
$ tar xzf pip-0.7.2.tar.gz
$ cd pip-0.7.2
$ python setup.py install
But when I do python setup.py install, I get error message:
Johns-MacBook-Pro:pip-0.7.2 John$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 2, in <module>
from setuptools import setup
ImportError: No module named setuptools
Can someone please help me install step by step for a newb? Thanks in advance for all of your help!
Pip can install straight from the git repository
You just have to tell him to use git and give him the URL of the git rep
pip install git+git://github.com/mikemaccana/python-docx.git
You will also need to install lxml (as written in the setup.py) and PIL (as you will discover when you try to import the module).
pip install PIL
pip install lxml
pip install python-dateutil

ImportError: No module named Cython.Distutils

I'm having a strange problem while trying to install the Python library zenlib, using its setup.py file. When I run the setup.py file, I get an import error, saying
ImportError: No module named Cython.Distutils`
but I do have such a module, and I can import it on the python command line without any trouble. Why might I be getting this import error?
I think that the problem may have to do with the fact that I am using Enthought Python Distribution, which I installed right beforehand, rather than using the Python 2.7 that came with Ubuntu 12.04.
More background:
Here's exactly what I get when trying to run setup.py:
enwe101#enwe101-PCL:~/zenlib/src$ sudo python setup.py install
Traceback (most recent call last):
File "setup.py", line 4, in <module>
from Cython.Distutils import build_ext
ImportError: No module named Cython.Distutils
But it works from the command line:
>>> from Cython.Distutils import build_ext
>>>
>>> from fake.package import noexist
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named fake.package
Note the first import worked and the second throws an error. Compare this to the first few lines of setup.py:
#from distutils.core import setup
from setuptools import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import os.path
I made sure that the Enthought Python Distribution and not the python that came with Ubuntu is what is run by default by prepending my bash $PATH environment variable by editing ~/.bashrc, adding this as the last line:
export PATH=/usr/local/epd/bin:$PATH
and indeed which python spits out /usr/local/epd/bin/python... not knowing what else to try, I went into my site packages directory, (/usr/local/epd/lib/python2.7/site-packages) and give full permissions (r,w,x) to Cython, Distutils, build_ext.py, and the __init__.py files. Probably silly to try, and it changed nothing.
Can't think of what to try next!? Any ideas?
Install Cython:
pip install cython
Your sudo is not getting the right python. This is a known behaviour of sudo in Ubuntu. See this question for more info. You need to make sure that sudo calls the right python, either by using the full path:
sudo /usr/local/epd/bin/python setup.py install
or by doing the following (in bash):
alias sudo='sudo env PATH=$PATH'
sudo python setup.py install
For python3 use
sudo apt-get install cython3
For python2 use
sudo apt-get install cython
Details can be read at this
Run
which python
Thats the path to the python that your system has defaulted too
then go to #tiago's method of:
sudo <output of which python> setup.py install
I only got one advice for you : Create a virtualenv. This will ensure you have only one version of python and all your packages installed locally (and not on your entire system).
Should be one of the solutions.
In the CLI-python, import sys and look what's inside sys.path
Then try to use export PYTHONPATH=whatyougot
Running the following commands resolved the issue for me in ubuntu 14.04:
sudo apt-get install python-dev
sudo apt-get install libusb-1.0-0-dev
sudo apt-get install libsystemd-daemon-dev
sudo pip install cython
This link helped me: https://github.com/trezor/python-trezor/issues/40
Ran into this again in modern times. The solution was simple:
pip uninstall cython && pip install cython
Read like a thousand of these threads and finally got it for Python 3. (replace pip with pip3 if you have that kind of installation, and run pip uninstall cython if you have tried other solutions before running any of these)
Mac:
brew install cython
pip install --upgrade cython
Ubuntu
sudo apt-get install cython3 python-dev
pip install --upgrade cython
Windows (must have conda, and MinGW already in path)
conda install cython
conda install --upgrade cython
That is easy.
You could try install cython package first.
It will upgrade your easy_install built in python.
I had dependency from third party library on Cython, didn't manage to build the project on Travis due to the ImportError. In case someone needs it - before installing requirements.txt run this command:
pip install Cython --install-option="--no-cython-compile"
Installing GCC also might help.
Just install Cython from
http://cython.org/#download
and install it using this command
sudo python setup.py install
Then run the command
sudo python -c 'import Cython.Distutils'
and it will be installed and the error message will disappear.

Categories

Resources