Module not found, after installing with pip in stash
Hi, relative Python newcomer here, but with a couple of scripts under my belt, developed on Windows. I've been playing with Pythonista the last few days, but I'm struggling with one aspect. I've installed stash, from there installed some modules via pip, but the script I've written produces a Module Not Found error every time I run it.
My script resides in a folder under Documents/myapp on This iPad but when running it consistently fails to find the pip installed modules in site-packages-3. The modules in question are google.api_core and google.auth.
Is this some kind of permissions issue? Happy to give more information if it helps.
It’s likely that the module has dependencies that you haven’t installed, or that the module isn’t pure python. Both these problems will prevent you from using your module, but only the second one will prevent files from being downloaded to your phone.
In the first case, find out the dependencies and install them too. In the second case, you’re kinda sol. You could try figuring out what the code does and rewrite it in python.
More information like the error message and what module you’re trying to pip install would be helpful!
@Quicky, can’t say I would have successfully used those libraries, although I have accessed Google services, at least the calendar.
Can you share a full stack trace of the import attempt? Could you be accidentally running your script in Python 2?
Cheers, here's the trace
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/98568767-10B5-4B13-A6E1-34E319B6C605/Pythonista3/Documents/Quickify/quickstart.py", line 10, in <module>
File "/private/var/mobile/Containers/Shared/AppGroup/98568767-10B5-4B13-A6E1-34E319B6C605/Pythonista3/Documents/site-packages-3/googleapiclient/discovery.py", line 49, in <module>
ModuleNotFoundError: No module named 'google.api_core'
The pip installs I ran were:
pip install google-api-python-client
pip install google-auth-oauthlib google-auth-httplib2
For testing before trying to get it working on my own script, I'm using Google's example for getting a YouTube channel list:
# -*- coding: utf-8 -*- # Sample Python code for youtube.channels.list # See instructions for running these code samples locally: # https://developers.google.com/explorer-help/guides/code_samples#python import os import google_auth_oauthlib.flow import googleapiclient.discovery import googleapiclient.errors scopes = ["https://www.googleapis.com/auth/youtube.readonly"] def main(): # Disable OAuthlib's HTTPS verification when running locally. # *DO NOT* leave this option enabled in production. os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" api_service_name = "youtube" api_version = "v3" client_secrets_file = "client_secret.json" # Get credentials and create an API client flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file( client_secrets_file, scopes) credentials = flow.run_console() youtube = googleapiclient.discovery.build( api_service_name, api_version, credentials=credentials) request = youtube.channels().list( part="snippet,contentDetails,statistics", forUsername="GoogleDevelopers" ) response = request.execute() print(response) if __name__ == "__main__": main() ```
so, I will ask the obvious question....
does the site-packages-3/google/api_core folder exist?
if not, you may need to pip install google-api-core.
pip on pythonista does not always figure out every dependency. also, some pip installs fail, and you need to use wget to download, and tar to untar/gz to copy into site packages.
or, use the workng copy app to download modules from git and copy the appropriate folder to site-packages
Ah right, cheers for that Jon. Obvious questions are welcome at my level! That's pointed me in the right direction, it looks like pip hasn't picked up on the dependencies. Thanks for the advice with regards to workarounds.