Can't connect python to looker - python

I've downloaded the looker_sdk for python.
Wrote a very simple program:
from looker_sdk import client, models
def test_looker():
sdk = client.setup("./looker.ini")
if __name__ == "__main__":
test_looker()
However, when I'm running it I'm getting the error:
ImportError: cannot import name 'client' from 'looker_sdk'.
I do see the models and was able to perform:
sdk = looker_sdk.init31()
what am I missing?
Thanks,
Nir.

It seems there may be a missing client.py file in looker_sdk version 0.1.3b8, or in your installation - I tested this on 0.1.3b4 and found no such issue.
I recommend that you uninstall the package and re-install the latest version from PyPI.

Related

How to restart windows service through Python script?

I am creating a script to restart windows service through Python script but getting the below error:
Script error
Code:
import win32serviceutil
class serviceRestart:
serviceName = "MySQL57"
win32serviceutil.RestartService(serviceName)
if __name__ == '__main__':
lm = serviceRestart()
The error message pretty much says it all. You need to install the module.
http://sourceforge.net/projects/pywin32/files/pywin32/
If you have pip installed then you can use "pip install pypiwin32"

openstack API python - no module named version

I'm trying to instanciate VM on openstack using the NovaClient API in python. More precisely with mq-rabbit celery tasks.
Unfortunatly I got this error :
from novaclient import client
File "/usr/local/lib/python2.7/dist-packages/novaclient/__init__.py", line 15, in <module>
import pbr.version
ImportError: No module named version
I already tested with a simple python file and it works, my VM was created but when I try to do this throught a celery tash I got the error above...
My version is the latest python-novaclient-6.0.2, but as our servers are in version 2 I use the version 2 API.
Here is my code in my celery task, who works when I test in python shell :
loader = loading.get_plugin_loader('password')
auth = loader.load_from_options(auth_url=auth_url, username=username, password=password, project_name=tenant_name)
sess = session.Session(auth=auth)
nova = client.Client('2', session=sess) #API version and session
Seems it's the same error and this one
Basically what you need is to make sure you have pbr installed.
If you had it already, reinstalling might help
pip uninstall pbr
pip install pbr

ImportError: No module named netifaces

I'm trying to get the IP address and MAC address of my pc's network card by python. I got some code from here
I create a proj "getip".
create "main.py". And I modify the code of "main.py" as follow
from netifaces import interfaces, ifaddresses, AF_INET
def ip4_addresses():
ip_list = []
for interface in interfaces():
for link in ifaddresses(interface)[AF_INET]:
ip_list.append(link['addr'])
return ip_list
def main():
print ip4_addresses()
if __name__ == "__main__":
main()
and I create "app.yaml"
application: getip
version: 1
runtime: python
api_version: 1
handlers:
- url: .*
script: main.py
and when I run the main.py at console as "python main.py", I got the ip addresses.
and when I run as "dev_appserver.py getip", the server is setup. When I browse the page as localhost:8080, the web page is white screen and I got the following error at console.
from netifaces import interfaces, ifaddresses, AF_INET
ImportError: No module named netifaces
How can I solve the problem?
just install netifaces
pip install netifaces if you have pip installed, or download the source, unpack it run and python setup.py install
warning: this will install it globally on your system, so use caution, or use virtualenv
If you are using ubuntu:
sudo apt install python3-netifaces
Came here for the same question but in my case pip install would say that requirement is already satisfied. However:
pip uninstall netifaces && pip install netifaces
fixed it.
Leaving this here for posterity. Use sudo if you need to.
Actually, the problem here is you must be root when installed with pip, or it will not install globally. Therefore would not be able to find the module unless in the same directory or path as the module directory
so you need this:
sudo pip install netifaces
or on windows install with an elevated command prompt!
It seems that you have installed netifaces in your local development environment. But Google App Engine does not recognize it.
If you run your script with python main.py, Python interpreter will look for your libraries in the PYTHONPATH. GAE does not follow that rule.
To install a library in GAE, usually you just need to put the library module directory in the root of your app path(whee the app.yaml is). But I don't think Google will allow you to install libraries that can get hardware information in their PaaS for security reasons.
Updates:
Becaue you just need a web server to output the result, I recommend you to choose a simple, well documented, micro Python web framework, like Flask or bottle.
Installation:
pip install Flask or easy_install Flask
code:
from flask import Flask
from netifaces import interfaces, ifaddresses, AF_INET
app = Flask(__name__)
def ip4_addresses():
ip_list = []
for interface in interfaces():
for link in ifaddresses(interface)[AF_INET]:
ip_list.append(link['addr'])
return ip_list
#app.route("/")
def main():
return str(ip4_addresses())
if __name__ == "__main__":
app.run()
Run: python main.py

python import error "No module named appengine.ext"

after runing this code,I found import error:-
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')
application = webapp.WSGIApplication([('/', MainPage)],debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
how to use google.apengine.ext
import sys
sys.path.insert(1, '/Users/<username>/google-cloud-sdk/platform/google_appengine')
sys.path.insert(1, '/Users/<username>/google-cloud-sdk/platform/google_appengine/lib/yaml/lib')
sys.path.insert(1, 'lib')
if 'google' in sys.modules:
del sys.modules['google']
this solves the problems for me
It looks like the App Engine SDK is not installed, or at least the Python runtime cannot find it.
read and follow the instructions here: https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python
They tell you, how to install App Engine SDK for Python.
Try:
import google
print google.__path__
to see what exactly you're importing.
I had this same issue because I pip installed gcloud before downloading and installing the SDK. The pip install created a python package google which didn't contain the appengine submodule (which is found in the SDK folder). I uninstalled the gcloud and related packages. Then just pip installed the google-cloud-bigquery which is the only package I needed from gcloud. Everything works fine now.
I faced similar error while calling Google Analytics API using AWS Lambda.
Workaround from (Schweigi1) helped me.
import googleapiclient
from googleapiclient.discovery_cache.base import Cache
class MemoryCache(Cache):
_CACHE = {}
def get(self, url):
return MemoryCache._CACHE.get(url)
def set(self, url, content):
MemoryCache._CACHE[url] = content
Usage:
service = googleapiclient.discovery.build("analyticsreporting", "v4", http=http, credentials=credentials,cache=MemoryCache())
Hope this helps someone who is facing this issue in AWS Lambda.
First possible reason:
you don't install the python library in google cloud sdk, so you can run in cmd (as administrator):
gcloud components install app-engine-python.
Second possible reason:
your IDE is not success get into google libraries, they exist in:
C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine
or in:
C:\Users\[your user]\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine
You can see in attached link explain how to add these libraries to IDE external libraries: https://stackoverflow.com/a/24206781/8244338
I got this error in python:
from google.appengine.api import search
ImportError: No module named appengine.api
I thought this would be something along the similar lines of what is happening in this thread.
So, my solution was to run "dev_appserver.py 'your yaml file' ". I got this solution following the below links:
1) https://cloud.google.com/appengine/docs/standard/python/tools/using-local-server
2) https://www.youtube.com/watch?v=BdqUY8lCuBI
Hope this helps!
check if you named some file google.py :) in the same package, because this can shadow the import of google.appengine.ext. I had the same error:
python import error “No module named appengine.ext”
and deleteting the file solved the problem.

Import error in twilio

I am having the same problem as this thread regarding twilio-python:
twilio.rest missing from twilio python module version 2.0.8?
However I have the same problem but I have 3.3.3 installed. I still get "No module named rest" when trying to import twilio.rest.
Loading the library from stand alone python script works. So I know that pip installing the package worked.
from twilio.rest import TwilioRestClient
def main():
account = "xxxxxxxxxxxxxxxx"
token = "xxxxxxxxxxxxxxxx"
client = TwilioRestClient(account, token)
call = client.calls.create(to="+12223344",
from_="+12223344",
url="http://ironblanket.herokuapp.com/",
method="GET")
if __name__ == "__main__":
main()
but this does not work:
from twilio.rest import TwilioRestClient
def home(request):
client = TwilioRestClient(account, token)
Do you have any idea what I can try next?
I named a python file in my project twilio.py. Since that file was loaded first, then subsequent calls to load twilio would reference that file instead of the twilio library.
TLDR: just don't name your python file twilio.py
Check which versions of pip and python you are running with this command:
which -a python
which -a pip
pip needs to install to a path that your Python executable can read from. Sometimes there will be more than one version of pip like pip-2.5, pip-2.7 etc. You can find all of them by running compgen -c | grep pip. There can also be more than one version of Python, especially if you have Macports or brew or multiple versions of Python installed.
Check which version of the twilio module is installed by running this command:
$ pip freeze | grep twilio # Or pip-2.7 freeze etc.
The output should be twilio==3.3.3.
I hope that helps - please leave a comment if you have more questions.
This Worked For me : (Windows)
Python librarys are in G:\Python\Lib
(Python is installed at G:, it might be different for you)
Download Twilio from github at paste the library at >> G:\Python\Lib <<
import problem gone :)
I had the same issue and it drove me crazy. Finally I figured it out. When you get the error:
AttributeError: module 'twilio' has no attribute 'version'
Look 2 lines above and the error is telling you where it expects to find the twilio file. So I moved it from where it was to where it was asking it to be.
Installed to:
c:\users\rhuds\appdata\local\programs\python\python37-32\lib\site-packages
Moved it to:
Traceback (most recent call last):
File "", line 1, in
import twilio
File "C:\Users\rhuds\AppData\Local\Programs\Python\Python37-32\twilio.py", line 2, in
Now I can import twilio. Besides that, the only other thing I did was uninstall old versions of Python, but I don't think that really mattered.

Categories