Boto Syntax Error? - python

I am importing boto.dynamodb.table and getting a syntax error. I don't see how it is related to what I'm doing. I haven't implemented / used it and yet upon launching it finds a syntax error.
The error from my console looks like this:
File "api.py", line 10, in <module>
import dynamoAccess
File "/Users/tai/Documents/workspace/testSelenium/testS/dynamoAccess.py", line 6, in <module>
from boto.dynamodb2.table import Table
File "/Library/Python/2.7/site-packages/boto/dynamodb2/table.py", line 3, in <module>
from boto.dynamodb2.fields import (HashKey, RangeKey,
File "/Library/Python/2.7/site-packages/boto/dynamodb2/fields.py", line 1, in <module>
from boto.dynamodb2.types import STRING
File "/Library/Python/2.7/site-packages/boto/dynamodb2/types.py", line 4, in <module>
from boto.dynamodb.types import Dynamizer
File "/Library/Python/2.7/site-packages/boto/dynamodb/types.py", line 112
]
^
SyntaxError: invalid syntax
The code that I believe this is related to is the first few lines (aka the dynamo table import) of dynamoAccess:
This is what I have:
import cleaner
import datetime
import awsAccess
import boto
from boto import dynamodb2
from boto.dynamodb2.table import Table
#create a connection to amazon s3
#aws_access_key_id=getenv('AWS_ACCESS_KEY');
#aws_secret_access_key=getenv('AWS_SECRET_KEY');
#aws_dynamo_region=getenv('DYANAMO_REGION')
#for running in pydev
aws_access_key_id=awsAccess.aws_access_key_id
aws_secret_access_key=awsAccess.aws_secret_access_key
aws_dynamo_region=awsAccess.aws_dynamo_region
decompiled_dynamo_table="decompiled_swfs"
text_dynamo_table="decompiled_swf_text"
image_dynamo_table="images_decompiled"
_dynamo_table="decompiled_swf_text"
Has anyone encountered this? I haven't modified the boto file.
Edit:
resinstalled boto but still getting the error:
Name: boto
Version: 2.31.1
Edit 2: Solved see answer below. Boto had a bug

Fixed - I replaced the boto dynamodb/types.py file with the one in github: https://github.com/boto/boto
There was a ] out of place that needed to be fixed. This was already fixed in the github version but apparently not yet pushed to pip
I believe that this may occur for other people due to the above error. If you encounter this simply update your file from github (or edit it yourself)

Related

Streamlit + Spacy causing "AttributeError: 'PathDistribution' object has no attribute '_normalized_name'"

Note: This is not a duplicate question as I have gone through this answer and made the necessary package downgrade but it still results in the same error. Details below.
# System Details
MacBook Air (M1, 2020)
MacOS Monterey 12.3
Python 3.10.8 (Miniconda environment)
Relevant library versions from pip freeze
importlib-metadata==3.4.0
PyMuPDF==1.21.1
spacy==3.4.4
spacy-alignments==0.9.0
spacy-legacy==3.0.11
spacy-loggers==1.0.4
spacy-transformers==1.2.0
streamlit==1.17.0
flair==0.11.3
catalogue==2.0.8
# Setup
I am trying to use Spacy for some text processing over a pdf document uploaded to a Streamlit app.
The Streamlit app basically contains an upload button, submit button (which calls the preprocessing and spacy functions), and a text_area to display the processed text.
Here is the working code for uploading a pdf document and extracting its text -
import streamlit as st
import fitz
def load_file(file):
doc = fitz.open(stream=uploaded_file.read(), filetype="pdf")
text = []
with doc:
for page in doc:
text.append(page.get_text())
text = "\n".join(text)
return text
#####################################################################
st.title("Test app")
col1, col2 = st.columns([1,1], gap='small')
with col1:
with st.expander("Description -", expanded=True):
st.write("This is the description of the app.")
with col2:
with st.form(key="my_form"):
uploaded_file = st.file_uploader("Upload",type='pdf', accept_multiple_files=False, label_visibility="collapsed")
submit_button = st.form_submit_button(label="Process")
#####################################################################
col1, col2 = st.columns([1,3], gap='small')
with col1:
st.header("Metrics")
with col2:
st.header("Text")
if uploaded_file is not None:
text = load_file(uploaded_file)
st.text_area(text)
# Reproduce base code
install necessary libraries
save above code to a test.py file
from terminal navigate to folder and run streamlit run test.py
navigate to http://localhost:8501/ in browser
download this sample pdf and upload it to the app as an example
This results in a functioning app -
# Issue I am facing
Now, the issue comes when I add spacy to the python file using import spacy and rerun the streamlit app, this error pops up -
AttributeError: 'PathDistribution' object has no attribute '_normalized_name'
Traceback:
File "/Users/akshay_sehgal/miniconda3/envs/demo_ui/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
exec(code, module.__dict__)
File "/Users/akshay_sehgal/Library/CloudStorage/________/Documents/Code/Demo UI/Streamlit/keyphrase_extraction_template/test.py", line 3, in <module>
import spacy
File "/Users/akshay_sehgal/miniconda3/envs/demo_ui/lib/python3.10/site-packages/spacy/__init__.py", line 6, in <module>
from .errors import setup_default_warnings
File "/Users/akshay_sehgal/miniconda3/envs/demo_ui/lib/python3.10/site-packages/spacy/errors.py", line 2, in <module>
from .compat import Literal
File "/Users/akshay_sehgal/miniconda3/envs/demo_ui/lib/python3.10/site-packages/spacy/compat.py", line 3, in <module>
from thinc.util import copy_array
File "/Users/akshay_sehgal/miniconda3/envs/demo_ui/lib/python3.10/site-packages/thinc/__init__.py", line 5, in <module>
from .config import registry
File "/Users/akshay_sehgal/miniconda3/envs/demo_ui/lib/python3.10/site-packages/thinc/config.py", line 1, in <module>
import catalogue
File "/Users/akshay_sehgal/miniconda3/envs/demo_ui/lib/python3.10/site-packages/catalogue/__init__.py", line 20, in <module>
AVAILABLE_ENTRY_POINTS = importlib_metadata.entry_points() # type: ignore
File "/Users/akshay_sehgal/miniconda3/envs/demo_ui/lib/python3.10/importlib/metadata/__init__.py", line 1009, in entry_points
return SelectableGroups.load(eps).select(**params)
File "/Users/akshay_sehgal/miniconda3/envs/demo_ui/lib/python3.10/importlib/metadata/__init__.py", line 459, in load
ordered = sorted(eps, key=by_group)
File "/Users/akshay_sehgal/miniconda3/envs/demo_ui/lib/python3.10/importlib/metadata/__init__.py", line 1006, in <genexpr>
eps = itertools.chain.from_iterable(
File "/Users/akshay_sehgal/miniconda3/envs/demo_ui/lib/python3.10/importlib/metadata/_itertools.py", line 16, in unique_everseen
k = key(element)
# What have I tried?
First thing I tried was to isolate the spacy code and run it in a notebook in the specific environment, which worked without any issue.
Next, after researching SO (this answer) and the github issues, I found that importlib.metadata could be the potential culprit and therefore I downgraded this using the following code, but it didn't fix anything.
pip uninstall importlib-metadata
pip install importlib-metadata==3.4.0
I removed the complete environment, and setup the whole thing again, from scratch, following the same steps I used the first time (just in case I had made some mistake during its setup). But still the same error.
Final option I would be left with, is to containerize the spacy processing as an API, and then call it via the streamlit app using requests
I would be happy to share the requirements.txt if needed, but I will have to figure out how to upload it somewhere via my office pc. Do let me know if that is required and I will find a way.
Would appreciate any help in solving this issue!
Upgrade importlib-metadata to importlib-metadata>=4.3.0 to avoid this particular error.
There can be complicated interactions between the built-in importlib.metadata and the additional importlib_metadata package, and you need a newer version of importlib-metadata to get some of the updates/fixes related to this.
With python 3.10 and importlib-metadata==3.4.0, you can see this error with the following example (spacy and streamlit are not required):
import importlib_metadata
import importlib.metadata
importlib.metadata.entry_points()

i was creating a REST api using flask and while i was about to test it on postman I saw that error

File "c:\Users\kally\rest\code\app.py", line 3, in <module>
from flask_jwt import JWT
File "C:\Users\kally\AppData\Roaming\Python\Python310\site-packages\flask_jwt\__init__.py", line 16, in <module>
import jwt
File "C:\Users\kally\AppData\Roaming\Python\Python310\site-packages\jwt\__init__.py", line 19, in <module>
from .api_jwt import (
File "C:\Users\kally\AppData\Roaming\Python\Python310\site-packages\jwt\api_jwt.py", line 5, in <module>
from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections' (C:\Program Files\Python310\lib\collections\__init__.py)
Expanding on my comment:
As described in the documentation, Mapping was moved to collections.abc in v3.3 and is deprecated since v3.9 (while still left visible for backwards compatability until v3.8).
Your error stems from using outdated imports - you would need to upgrade the used pyjwt/jwt - especially its /api_jwt.py. The current version of
https://github.com/jpadilla/pyjwt/blob/master/jwt/api_jwt.py
uses the correct imports since this commit in November 2018.
That error
from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections'
is saying to you, that there is no Mapping in collection package. Please check doc

Writing data to FireBase using Python

I am tring to write data to my firebase project using Python,
I found a code which works for the guy who show it but it does not work for me and I do not understand what the problem is.
This is the code:
from firebase import firebase
FBConn = firebase.FirebaseApplication('project-address-here',None)
while True:
price=int(input("what is the price?"))
data_to_upload = {
'Price' : price
}
result= FBConn.post('/MyTestData/',data_to_upload)
print(result)
when i run the code i get this message:
Traceback (most recent call last):
File "c:/Users/username/Desktop/folder/file.py", line 1, in module
from firebase import firebase
File "C:\Users\username\AppData\Local\Programs\Python\Python38-32\lib\site-packages\firebase_init_.py", line 3
from .async import process_pool
^
SyntaxError: invalid syntax
What does this mean? how could it be that for him it works and for me it doesn't?
Looks like a problem in the firebase module, which is not the official one by Google.
The firebase module from pypy hasn't been updated for more than 18 months.
Take a look the official SDK documentation at: https://firebase.google.com/docs/firestore/quickstart#python

Import errors on VS code

I'm new to VS code. I have downloaded a git project which has demo programs that I can run.
The directory structure is as follows:
Projectparser
>demo
>>alg1_demo.py
>>alg2_demo.py
>>alg3_demo.py
>Projectparser
>>alg1
>>>__init__ [ Has just one line : from alg1 import * ]
>>>alg1.py
>>>calg1.c
>>>calg1.h
>>alg2
>>>__init__ [ Has just one line : from alg2 import * ]
>>>alg2.py
>>>calg2.c
>>>calg2.h
>>alg3
>>>__init__ [ Has just one line : from alg3 import * ]
>>>alg3.py
>>>calg3.c
>>>calg3.h
where > indicates sub-directory. Projectparser is the folder from where I open vs code. It has a sub-directory by the same name as well which contains all the algorithms I'm interested in.
When I try running the alg1_demo.py. The below line is causing an error.
sys.append("../")
from Projectparser import alg1 (line 8)
I'm getting the following error:
ImportError: cannot import name 'alg1' from 'Projectparser' (unknown location)
So I added the line : sys.path.append("../Projectparser")
Then I'm getting the following error :
File "/home/suneha/Projectparser/demo/alg1_demo.py", line 8, in <module>
from Projectparser import alg1
File "../Projectparser/Projectparser/alg1/__init__.py", line 1, in <module>
from alg1 import *
ModuleNotFoundError: No module named 'alg1'
But the module is present in the subdirectory. So I added the line :
sys.path.append("../Projectparser/Projectparser/alg1")
Then I'm getting this error :
Traceback (most recent call last):
File "/home/suneha/Projectparser/demo/alg1_demo.py", line 8, in <module>
from Projectparser import alg1
File "../Projectparser/Projectparser/alg1/__init__.py", line 1, in <module>
from alg1 import *
File "/home//Projectparser/Projectparser/alg1/alg1.py", line 13, in <module>
from ..logmatch import regexmatch
ImportError: attempted relative import with no known parent package
The same problem persists for all the three algorithms alg1, alg2, alg3. I'm not sure how to fix this and is using sys.append.path() the best way to solve the above mentioned problems.
Can anyone suggest how to solve the final import error : ImportError: attempted relative import with no known parent package
and if there is any other compact way of solving the other import errors instead of using sys.path.append().
Thanks in advance
Use the following statement to add the path of the file that needs to be imported to the system path to help VSCode find it:
import os,sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
The following is part of the project I created that you provided:
Result:
The following points need to be noted:
When importing, the subfolders are connected with.
Please avoid using files and folders with the same name to prevent confusion when VSCode finds modules.
If the result is executable but there is still a wave line, you can add in settings.json: "python.linting.pylintArgs": [ "----extension-pkg-whitelist=1xml" ],
Update:
According to the code of the link you provided, I reproduced the problem you described locally, and the solution is as follows:
Comment out the content "from SLCT import *" of logparser-master\logparser\SLCT_init_.py.
Add import os,sys sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
to SLCT_demo.py
operation result:

python - from apache_beam.io import fileio gives error: cannot import name fileio

I want to read a csv file into a list in an apache beam application, where each element in the list is a tuple or list (don't really matter), so that I would have the csv
1,2,3
4,5,6
become
[(1,2,3) , (4,5,6)]
or
[ [1,2,3], [4,5,6] ]
I tried following the instructions in How to convert csv into a dictionary in apache beam dataflow
but when I try to use
from beam_utils.sources import CsvFileSource
I get
from beam_utils.sources import CsvFileSource
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/beam_utils/sources.py", line 9, in <module>
from apache_beam.io import fileio
ImportError: cannot import name fileio
If I try to directly import
from apache_beam.io import fileio
I get the same issue, however I can use both of
import apache_beam.io
import beam_utils
without any issues. Anyone got a good idea of what the issue might be or got a good idea of how I could do this in a different way?
I currently have
with beam.Pipeline(options = pipeline_options) as p:
csvfile = p | ReadFromText(known_args.input)
so if I can turn csvfile to the desired format in another way that works well too
Just ran into this same problem a few minutes ago. The issue is that fileio is apparently no longer in apache_beam (at least it wasn't for me). It appears to have been replaced by filesystem.
Not a great solution, but in sources.py from beam_utils I replaced all instances of "fileio" with "filesystem"
So
from apache_beam.io import fileio
becomes
from apache_beam.io import filesystem

Categories

Resources