I have a Python script that executes a SQL query using the pyhive and presto libraries. The script retrieves the query output and converts it into a Pandas DataFrame. Then, I perform some transformations on the DataFrame and use it to generate a PDF file.
The script runs smoothly when executed through PyCharm, which I use for development and testing. However, when I use PyInstaller to create an executable (using either –onefile or –onedir), I encounter the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter__init__.py", line 1968, in __call__
File "gerador_extrato.py", line 1880, in selected
File "gerador_extrato.py", line 692, in query_buyer
File "pandascoreframe.py", line 10374, in apply
File "pandascoreapply.py", line 916, in apply
File "pandascoreapply.py", line 1063, in apply_standard
File "pandascoreapply.py", line 1081, in apply_series_generator
File "gerador_extrato.py", line 680, in pix_replace
TypeError: can only concatenate str (not "NoneType") to str
The error occurs in the following function:
def pix_replace(row):
value = row['fund_transaction_type']
orides_nome = row['orides_nome']
orides_taxid_masked = row['orides_taxid_masked']
transaction_type = row['TRANSACTION_TYPE']
if value not in [17, 18, 34, 57]:
return transaction_type
if value == 17:
return 'PIX ENVIADO PARA n ' + orides_nome.upper() + ' - ' + orides_taxid_masked
if value == 18:
return 'PIX RECEBIDO DE n ' + orides_nome.upper() + ' - ' + orides_taxid_masked
if value == 34:
return 'PIX RECEBIDO DE n ' + orides_nome.upper() + ' - ' + orides_taxid_masked
if value == 57:
return 'PIX RETORNADO'
df['Tipo de Transação'] = df.apply(pix_replace, axis=1)
I’m trying to apply this function to transform info of the ‘Tipo de Transação’ column.
I suspect that the error is related to concatenating a None value with a string. The script runs successfully in my development environment, so I’m unsure why it fails after being transformed into an executable.
I have done the testing using the same inputs on Pycharm and the Executable, but it seems that my executable does not generate the same data and I don’t know why.
The values of the column ‘orides_taxid_masked’, which are considered on this function are:
On Pycharm:
7 None
8 ***.273.748-**
9 None
Name: orides_taxid_masked, dtype: object
On Executable:
7 None
8 None
9 None
Name: orides_taxid_masked, dtype: object
I run pyinstaller through a virtual environment, to only use specific libraries to optimize my executable.
I would appreciate any insights or suggestions on how to resolve this issue when running the script as an executable.
10
So, i figured it out, it seems that the line below was working just fine on Pycharm but when I compiled using Pyinstaller it was not working, impacting my functions, I think this might be due to the Python/Pandas version of my virtual environment.
Pycharm:
df['orides_taxid'] = df['orides_taxid'].str.replace(r'.', '').str.replace(r'-', '').str.replace(r'/', '')
Pyinstaller:
df['orides_taxid'] = df['orides_taxid'].str.replace(r'.', '').str.replace(r'-', '').str.replace(r'/', '')