Python Linux Google drive API client install modules not found - python

I'm trying to start working with google drive API from python on my local Linux machine. I want to be able to move files back and forth to Google drive from my local machine. I just started learning Python yesterday and I'm having problems with the Google quickstart instructions. when I try to run the quickstart code at https://developers.google.com/drive/v3/web/quickstart/python with python3 I get this error:
ImportError: No module named 'apiclient.discovery'
which results from these import statements at the top of the file.
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
As per the instructions I installed what I thought i needed with the command
pip install --upgrade google-api-python-client
But I'm getting this error. I notice if i comment out the line
from apiclient.discovery import build
then the rest of the import statements are ok, and the script starts executing and browser pops up asking for authentication, but then obviously when it reachs the 'build' function call in the script it breaks. What am I doing wrong?
I've tried installing the lib folder containing the modules to the local directory where my script is executing, but I think that's only important if you're using google app engine which I am .... not? I don't think I am right? When i did that i tried changing the import statement to
from lib.googleapiclient.discovery import build
I get the same error, but I've actually opened up that file in lib/googleapiclient/discovery.py in my local directory and in the code is
...
def build(serviceName,
version,
http=None,
discoveryServiceUrl=DISCOVERY_URI,
developerKey=None,
model=None,
requestBuilder=HttpRequest,
credentials=None,
cache_discovery=True,
cache=None):
...
So why in the world wouldn't this import statement work? I've also tried changing the statements from
from apiclient.discovery import build
to
from googleapiclient.discovery import build
and I get the same error, No module named 'googleapiclient'
I've installed 3rd party modules yesterday with pip and I never had any problems. What's going on? Thanks for your help.

Check your python and pip version, and try pip freeze to check the installed package.
python --version
pip --version
pip freeze
Please check your python version, where your pip is from (/usr/lib/python2.7 or /usr/lib/python3.6 or the other virtualenv) and whethergoogle-api-python-client is in the output of pip freeze.
Try to reinstall google-api-python-client.
sudo pip install --force-reinstall google-api-python-client
apiclient is the old name, so it is better to use googleapiclient for import.
from googleapiclient.discovery import module

Related

Unable to fully package my Python script with all the modules and dependencies it needs for Linux

I have a Python 2.7 script that uses BeautifulSoup4 and requests modules.
The issue is, that I need to deploy this script on a machine to which we can not directly install any new modules/libaries via pip install or anything else.
We can copy this script and any files it needs to run to that machine, but we can not directly install any modules.
I have tried PyInstaller, PEX and Nuitka to create an executable file or a bundle (in any format, for example .zip) so that we can copy the entire file or bundle into the machine and run the python script from there, without the need to do pip install or installing the modules manually via Wheel file. All without success.
Environment details:
Target machine on which the script needs to run: RHEL-based Linux OS with Python 2.7.
My development machine: Windows 10 but I also have access to Fedora Linux machine both with Python 3 and Python 2.7.
The import section of my script looks like this:
from __future__ import with_statement
from __future__ import absolute_import
import requests
import re
from bs4 import BeautifulSoup
from io import open
Can someone, please, help me out here?
We have the script ready to be deployed, but we are not able to run it in our target machine because of the missing modules/libraries.
Thank you very much
EDIT:
Mentioning this since it may not be clear at first - we do not have the issue with a network connection or anything of this gender. We were prohibited to use pip install or a manual method of installing a module. Therefore, we can only bundle the modules directly with the script or something so that would not need to directly install the modules on the target machine itself.

Can not import google.cloud module in python script

I am following this article trying to make my Python script read labels related to an image using Google Cloud Vision API. The problem is that I am getting this error when trying to include a reference to vision from google.cloud module.
import io
from google.cloud import vision
from google.cloud.vision import types
The error that I am getting says:
ImportError: No module named 'google.cloud'
This is weird because when I do:
$ pip show google-cloud
I can see it is there and its files are located at:
/usr/local/lib/python2.7/dist-packages/google_cloud-0.34.0.dist-info/*
Except for that, when I do pip freeze in my working folder I can see them both that I need available:
google-cloud==0.34.0
google-cloud-vision==0.33.0
I am now wondering what could be the reason for not being able to see include this module in my Python script.
The google-cloud package is deprecated, you should uninstall it and install google-cloud-vision instead.
This link might provide some assistance:
https://cloud.google.com/python/
Edited
upon looking into it further, I was able to do the following:
pip install google-cloud-vision
and import everything with:
import io
import os
from google.cloud import vision
from google.cloud.vision import types
Maybe try uninstalling the package through pip and reinstalling it with the above?

How to Import Libraries into python project from GitHub

I am trying to create a project in python using some libraries from GitHub that I found. I am using InstaPy and Instagram-API-python.
My project structure is as follows
Project(main folder)
Instapy(sub-folder)
Instagram-API-python(sub-folder)
insta.py
How would I import both these into the insta.py file? I am new to python and not sure how the imports work.
Don't copy them into your project folder, use pip to install them on your Python path.
But first, read about virtual environments.
Once you have your virtual environment set up and activated you can install the packages thus:
$ pip install git+https://github.com/timgrossmann/InstaPy.git
$ pip install git+https://github.com/LevPasha/Instagram-API-python.git
Then, in your python script just import them
from instapy import InstaPy
import InstagramAPI
and use them.
I followed these instructions and it (mostly) worked. It looks like InstagramAPI needs an executable installed (ffmpeg) which I'm not wanting to install on my laptop. It reports the error during the initial import.
I could definitely import instapy .. but notice that it is all lower case.
But since there is only the InstaPy class in the instapy module, it's best to simply import it this way.
More on InstaPy here: https://github.com/timgrossmann/InstaPy

Add python modules to Azure

When I run a python script that I set up on WebJobs in Azure - I get the following error:
import MySQLdb
ImportError: No module named MySQLdb
job failed due to exit code 1
I found some articles that seem to suggest to install python modules to a directory created on the webapp. How/Where would I install those modules?
Have you tried this?
http://nicholasjackson.github.io/azure/python/python-packages-and-azure-webjobs/
(from the site):
Step 1.
If you are using OSX and the default Python 2.7 install your packages
installed with pip will be in /usr/local/lib/python2.7/site-packages,
create a folder called site-packages in the root of your python job
and copy any packages you need for your job into it.
Step 2
Next you need to modify your run.py or any other file which requires
access to the package files. At the top of the file add….
import sys
sys.path.append("site-packages")

can't import google.appengine.api

This should be pretty basic as I've installed lots of python packages, but I can't for the life of my get google apis client library for python to install.
I'm pressure sure I've gone through the instructions on this website properly:
https://developers.google.com/api-client-library/python/start/installation
To summarize I've done the following:
$ easy_install --upgrade google-api-python-client
this seems to work fine, doesn't report any errors or warnings
downloaded and unzipped google-api-python-client-gae-1.2.zip into the directory where my project is
but if I open an iPython session in the folder where I unpacked the full dependencies I can't do the basic imports such as:
import google.appengine.api it just says "No Module named google.appengine.api"
I checked in my site-packages folder and google_api_python_client-1.2-py2.7.egg is there. But it doesn't show up in sys.path
when I do sys.path.append('C:\Anaconda\Lib\site-packages\google_api_python_cli
ent-1.2-py2.7.egg') it adds the correct path, but the import still doesn't work.
EDIT: This fixed my problem
Adding the Google SDK to my Python path did the trick. I don't know why the installer didn't do this when I ran it. but hey, this worked
So if I run:
sys.path.append('C:\\Program Files (x86)\\Google\\google_appengine')
from google.appengine import api
works!
Without knowing all the steps you took to install app engine and the client APIs, my only recommendation is to install (or reinstall) the Google App Engine Python SDK from here: https://developers.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python. Looks like you're on windows, so you would grab the MSI.
Just make sure you launch the AppEngineLauncher application after installation as it will give you the option to create symlinks so you can run commands from terminal.

Categories