I wanted to download some live data about Trams in my city from API. I have working code, but it works only if i copy it and open linux terminal, enter python3 command and paste it there. In PyCharm i got an error(recommended option install package google didn't work):
from google.transit import gtfs_realtime_pb2
ModuleNotFoundError: No module named 'google'
from google.transit import gtfs_realtime_pb2
import requests
feed = gtfs_realtime_pb2.FeedMessage()
response = requests.get('https://www.ztm.poznan.pl/pl/dla-deweloperow/getGtfsRtFile/?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0Mi56dG0ucG96bmFuLnBsIiwiY29kZSI6MSwibG9naW4iOiJtaFRvcm8iLCJ0aW1lc3RhbXAiOjE1MTM5NDQ4MTJ9.ND6_VN06FZxRfgVylJghAoKp4zZv6_yZVBu_1-yahlo&file=feeds.pb')
feed.ParseFromString(response.content)
for entity in feed.entity:
if entity.HasField('trip_update'):
print(entity.trip_update)
Related
i ran the following code
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
# Instantiates a client
client = vision.ImageAnnotatorClient()
# The name of the image file to annotate
file_name = os.path.abspath('resources/wakeupcat.jpg')
# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
content = image_file.read()
image = vision.Image(content=content)
# Performs label detection on the image file
response = client.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
print(label.description)
the error i get is the following
Traceback (most recent call last):
File "F:\coding\pythonfolder\main.py", line 4, in <module>
from google.cloud import vision
ModuleNotFoundError: No module named 'google'
the library is installed is the following
pip install google-cloud-vision
I am fairly new to the google vision api so maybe there's some point I am missing
kindly let me know what the issue is, I tried pip install --upgrade google-cloud-vision as well but does not seems to work
my python version is Python 3.10.0
kindly let me know if there's any issue or missing information in my question
thank you!!
I'm pretty sure you messed up with the venv, since it worked fine for me. Try using PyCharm (if you don't already do) and setup a venv, or install virtualenv and launch these commands inside your project folder:
virtualenv venv
source venv/bin/activate
pip install google-cloud-vision
python your_file.py
deactivate
Last one is to properly exit the venv
The problem
I am trying to add the sqlite module to my python script that uses 2.7.13 in the streamlabs chatbot app.
When I run my script from 2.7.13 idle it works no problem. However when I run it from the streamlabs chatbot it gives the error no module named _sqlite3.
The streamlabs chatbot allows you to select the directory of where your lib is which mine is set to. I checked the lib folder and it has an sqlite folder inside of it already.
https://streamlabs.com/content-hub/post/chatbot-scripts-desktop
I assume that the module would need to be placed where the other scripts are which is C:\users\user folder\app data\roaming\streamlabs chatbot\services\scripts. For example, the boiler plate example made on git hub here:https://github.com/AnkhHeart/Streamlabs-Chatbot-Python-Boilerplate/tree/master/Boilerplate shows a lib folder in the specific script folder where he can import his custom module. Would have to do the same thing to make sqlite work in the streamlabs chatbot?
Here is the code:
import sys
import os
import time
import sqlite
ScriptName = "VLC Search and play"
Website = "twitch.tv/masterjx9"
Description = "VLC search and play app"
Creator = "masterjx9"
Version = "1.0.0"
settings = {}
searchRequest = ""
resetTime = 0
#more stuff
Here is the result in idle python:
>>>
#which is perfect
Here is the result in streamlabs chatbot:
no module named _sqlite3
Any ideas or suggestions would be awesome. Thank you
I was able to find my own answer thanks to the Streamlabs chatbot discord channel.
Streamlabs uses ironpython instead of python and they handle somethings different. They were able to give me an example of a script that uses a sqlite db and the major difference is that you need the following in order for sqlite3 to be imported:
import clr
clr.AddReference("IronPython.SQLite.dll")
clr.AddReference("IronPython.Modules.dll")
#Now you can import SQLite as shown in the line below
import sqlite3
#no errors in the chat bot
Hope this helps for anyone else.
New to Python..., well actually new to programming in general, so pls bear with me. On Ubuntu 20.04 (yes, new to Linux as well) with Python 3.8.2
I'm trying to run a script that uses PyPDF2. I was able to install it just fine with:
sudo apt-get install python3-pypdf2
and I can import it from the command line without any error:
import PyPDF2
When i try to import it from Pycharm, however, it generates a ModuleNotFoundError error:
Traceback (most recent call last):
File "/home/surista/.config/JetBrains/PyCharm2020.1/scratches/scratch_2.py", line 1, in <module>
from PyPDF2 import PdfFileReader
ModuleNotFoundError: No module named 'PyPDF2'
Here's the script I'm using.
from PyPDF2 import PdfFileReader
def get_info(path):
with open(path, 'rb') as f:
pdf = PDFFileReader(f)
info = pdf.getDocumentInfo()
number_of_pages = pdf.getNumPages()
print(info)
author = info.author
creator = info.creator
producer = info.producer
subject = info.subject
title = info.title
if __name__ == '__main__':
path = '/home/surista/Documents/pdfs/test_eng-1.pdf'
get_info(path)
Probably missing something obvious here, but any help would be appreciated.
First of all you should install python packages via pip. Run pip install PyPDF2, that might fix it already.
Also check which interpreter is selected for your project in pycharm. If Pycharm isn't using your system python, it won't see packages installed from a normal shell.
You'll find it in the Settings -> Project: your_project -> Project Interpreter.
When I try to run a python program with Bash (Windows) I get the error "ModuleNotFoundError:No module named 'Spotipy'" Is there something I am doing wrong?
I have already tried installing the Spotipy packet using pip and easy install on Bash but I still get the error. I have also downloaded the packet on the file directory ,not sure if that makes a difference, still got the same error.
import os
import sys
import json
import spotipy
import webbrowser
import spotipy.util as util
from json.decoder import JSONDecodeError
#Get the username from terminal
username = sys.argv[1]
#Erase cahce and prompt for user permission
try:
token = util.prompt_for_user_token(username)
except:
os.remove(f".cache-{username}")
token = util.prompt_for_user_token(username)
#Create spotifyObject
spotifyObject = spotipy.Spotify(auth=token)
This program is supposed to run on my terminal. Send me to a spotify login page then redirect me to a URL already set through a Spotify API.
install it using git: git clone https://github.com/plamere/spotipy.git
then go to the directory of the package and run: python setup.py install
I want to create a web server using http.server module in Python. But when execute the code it shows an error ImportError: cannot import name 'BaseHTTPRequestHandler'
I have Python27 and Python34 both installed on the same system.