Python Firebird WinError 193 connection error - python

import fdb
def main():
con = fdb.connect(dsn='C:\AKINSOFT\Wolvox8\Database_FB\SIRKET.FDB', user='sysdba', password='masterkey')
if __name__ == '__main__':
main()
I wrote a simple code for connecting a Firebird database with Python and fdb. When I run this, I get an winerror 193
Traceback (most recent call last):
File "C:\Users\grand\PycharmProjects\DatabaseTest\main.py", line 9, in <module>
main()
File "C:\Users\grand\PycharmProjects\DatabaseTest\main.py", line 5, in main
con = fdb.connect(dsn='C:\AKINSOFT\Wolvox8\Database_FB\SIRKET.FDB', user='sysdba', password='masterkey')
File "C:\Users\grand\PycharmProjects\DatabaseTest\venv\lib\site-packages\fdb\fbcore.py", line 803, in connect
load_api(fb_library_name)
File "C:\Users\grand\PycharmProjects\DatabaseTest\venv\lib\site-packages\fdb\fbcore.py", line 231, in load_api
setattr(sys.modules[__name__], 'api', ibase.fbclient_API(fb_library_name))
File "C:\Users\grand\PycharmProjects\DatabaseTest\venv\lib\site-packages\fdb\ibase.py", line 1396, in __init__
fb_library = WinDLL(fb_library_name)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\ctypes\__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 geçerli bir Win32 uygulaması değil

The English error is "[WinError 193] %1 is not a valid Win32 application", and it means you're trying to load a 32-bit DLL in a 64-bit process (or a 64-bit DLL in a 32-bit process). This means that you don't have a valid fbclient.dll on the PATH that matches the bitness of your Python process, but do have one of the wrong bitness.
So, find out if you're using a 32-bit or 64-bit Python (likely 64-bit these days), and use a Firebird installer of the appropriate bitness to install the client library.
If you don't have or don't want fbclient.dll on the PATH, you can also use fdb.load_api(..) or the fb_library_name connection property to specify the path to a fbclient.dll of the appropriate bitness.
As an aside, fdb has been superseded by the firebird-driver library.

Related

cant open programs with ".lnk" extension using subprocess.call function

it seems subprocess.call function just can be used for the files with '.exe' extension.
This is the code i tried for Firefox.lnk in which this is the same code i tried for a git program that has '.exe' extension and worked without error.
import subprocess
subprocess.call('C:/users/m.m/Desktop/Programs/Firefox')
This is the error I get with Firefox.lnk :
Traceback (most recent call last):
File "C:/Users/m.m/PycharmProjects/untitled5/pros.py", line 2, in <module>
subprocess.call('C:/users/m.m/Desktop/Programs/Firefox.lnk')
File
"C:\Users\m.m\AppData\Local\Programs\Python\Python37\lib\subprocess.py",
line 323, in call
with Popen(*popenargs, **kwargs) as p:
File
"C:\Users\m.m\AppData\Local\Programs\Python\Python37\lib\subprocess.py",
line 775, in __init__
restore_signals, start_new_session)
File
"C:\Users\m.m\AppData\Local\Programs\Python\Python37\lib\subprocess.py",
line 1178, in _execute_child
startupinfo)
OSError: [WinError 193] %1 is not a valid Win32 application
Firefox (Without extension) gives me FileNotFoundError: [WinError 2] The system cannot find the file specified.
when i try the code without extension for those programs with '.exe' extension i have no problem but with any program without '.exe' extension i get error... just like firefox that has '.lnk' extension.
To process .lnk files on Windows there is os.startfile() (Windows only) in the standard library.
If you want to add parameters to the command, you can also use the start command. It is a builtin command (no start.exe) therefore a shell is needed to run it.
You can also use shell=True to make this work!
lnk_path = 'C:/users/m.m/Desktop/Programs/Firefox.lnk'
subprocess.call(lnk_path, shell=True)

Error in using c-code in python

I am trying to use C-code in Python. I complied the c code in linux and using .so file in windows as I found it on internet. My code of python is given below:
from ctypes import *
add1 = CDLL('./adder.dll')
sum_c = add1.add_int(5,4)
The C-code is a simple adder. This works fine with Python in linux but I get the following error in windows:
test.py line 6, in <module>
add1 = CDLL('./adder.dll')
File "..\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 is not a valid Win32 application
Please let me know what is the problem.

py2exe and cx_Oracle failed loading cx_Oracle.pyd

Given the following python program
testconnect.py
from sqlalchemy.dialects import oracle
from sqlalchemy import create_engine
url = 'oracle+cx_oracle://user:password#oracle-rds-01.....amazonaws.com:1521/orcl'
e = create_engine(url)
e.connect()
print('Connected')
setup.py
setup(
options={
'py2exe': {
'bundle_files': 1,
'compressed': True,
'dll_excludes': ['OCI.dll'],
'includes':['cx_Oracle']
}
},
console=["testconnect.py"],
zipfile=None
)
I get the following traceback
Traceback (most recent call last):
File "testconnect.py", line 7, in <module>
e = create_engine(url)
File "c:\Python34\lib\site-packages\sqlalchemy\engine\__init__.py", line 386, in create_engine
return strategy.create(*args, **kwargs)
File "c:\Python34\lib\site-packages\sqlalchemy\engine\strategies.py", line 75, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "c:\Python34\lib\site-packages\sqlalchemy\dialects\oracle\cx_oracle.py", line 769, in dbapi
import cx_Oracle
File "c:\Python34\lib\site-packages\zipextimporter.py", line 109, in load_module
self.get_data)
ImportError: MemoryLoadLibrary failed loading cx_Oracle.pyd: The specified module could not be found. (126)
I have tried using 'includes' in the setup.py, importing cx_Oracle but to no avail.
I've tries bundle_files=3 and using 'data_files=' to copy the cx_Oracle.pyd file into the dist directory and I still get the same issue
What changes to my setup.py do I need to do to be able capture the cx_Oracle.pyd file so that it will load
Update:
The problem was I was using a cmd console that was open prior to installing cx_Oracle and instant client to build the exe with py2exe
I closed the console down re-opened it and windows was able to find the appropriate files
This now runs OK on my Windows 10 laptop (64 bit)
But when I try to deploy this EXE to my clients machine(64 bit windows 2008) I get the following still
D:\Milliman>testconnect.exe
Traceback (most recent call last):
File "testconnect.py", line 1, in <module>
File "c:\Python34\lib\site-packages\zipextimporter.py", line 109, in load_module
ImportError: MemoryLoadLibrary failed loading cx_Oracle.pyd: The specified module could not be found. (126)
Thanks for any help in advance
Andy
The Oracle instant client (or equivalent) needs to be installed on the target machine. cx_Oracle will not work without it. The DLL it is (likely) trying to find is OCI.DLL.
I finally figured out what was going on
The machine we were deploying to was windows 2008 Server 64 Bit
But It had Oracle 32 bit client on it
I was trying to deploy py2exe python 3.4 app 64 bit with Cx_Oracle 64bit
this was finding the 32 bit OCI.dll and failing to load
My solution was to package the 64 bit Instant Client in the data_files.
Then in my app modify the path within the app
import os
if os.path.exists('./instant_client'):
pth = os.environ.get('path')
pth = '{0};{1}'.format('./instant_client' ,pth)
os.environ['path'] = pth
This way I could guarantee that the cx_Oracle would find the correct OCI.dll without interfering with global paths and the already installed oracle on that machine

Python bindings for VLC

I am on Windows, and I wish to use Python Bindings for VLC. I've already downloaded the module from https://github.com/geoffsalmon/vlc-python , and did as per the read me. But, still I'm stuck at importing the module. The error looks like this :
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
import vlc
File "c:\python27\python-vlc-1.1.2\vlc.py", line 173, in <module>
dll, plugin_path = find_lib()
File "c:\python27\python-vlc-1.1.2\vlc.py", line 150, in find_lib
dll = ctypes.CDLL('libvlc.dll')
File "C:\Python27\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
Any Solution on where to place the module ? My main aim is to play MP3 audio files through vlc, which would be part of some other activity.
I had same problem.
It turns out for me if you have 64bit python, you need 64bit vlc player.
If you have 32bit python, you need 32bit vlc player.
Hope that works for you too.
I paired with 64bit I solved as follows. Of course
# first set the environment which is required from vlc.py
import os
os.environ['PYTHON_VLC_MODULE_PATH'] = """C:\Program Files\VideoLan"""
os.environ['PYTHON_VLC_LIB_PATH'] = """C:\Program Files\VideoLan\VLC\libvlc.dll"""
# now you can import vlc
import vlc

VLC Python Bindings -- Error 193

Have downloaded VLC.py, and placed it in my VLC install directory, where libvlc.dll is also present
On typing import vlc
I get the following error
Traceback (most recent call last):
File "C:\Program Files
(x86)\VideoLAN\VLC\vlc.py", line 88,
in
dll = ctypes.CDLL('libvlc.dll') File
"C:\Python27\lib\ctypes__init__.py",
line 353, in init
self._handle = _dlopen(self._name, mode) WindowsError: [Error 193] %1 is
not a valid Win32 application
Any ideas why?
If needed, my config is:
Win7 pro 64 bit
4GB RAM
Reposting my comment as an answer, since it fixed the problem:
I'm going to guess that the problem is trying to load a 32-bit DLL from a 64-bit process. You may be able to fix it by using a 32-bit Python build.

Categories