SAP / PyRFC

Asynchronous, non-blocking SAP NW RFC SDK bindings for Python
http://sap.github.io/PyRFC
Apache License 2.0
501 stars 133 forks source link

ImportError: cannot import name 'Connection' #54

Closed mgopic closed 6 years ago

mgopic commented 6 years ago

Hi Guys, Sorry if this is obvious question. I am new to python, exploring the python/SAP workings. I have followed the documentation steps. Unfortunately, I am getting "cannot import name Connection" error. It looks like basic error but no clue where I need to check. Could you please help.

Regards, Gopi

wandss commented 6 years ago

Hi @mgopic, can you paste your code please?

mgopic commented 6 years ago

Hi Wandss - thanks for response. I have copied the files again, now import error gone. But I see error now as.. File "C:\Users\XXXXXX\AppData\Roaming\Python\Python36\site-packages\pyrfc-1.9.3-py2.7-win-amd64.egg\pyrfc__init__.py", line 22, in from pyrfc._pyrfc import get_nwrfclib_version, Connection, TypeDescription, FunctionDescription, Server ImportError: DLL load failed: %1 is not a valid Win32 application.

My code just one single line to check the connection: from pyrfc import Connection

I tried with windows 32 bit and 64 bit nwrfcsdk files, no luck. I see that NWRFC_20 is not available in market place, took the latest 32bit/64 bit and tried.

bsrdjan commented 6 years ago

Hi @mgopic, using the latest NW RFC SDK library is absolutely correct. The lib is backwards compatible and using the latest version is always recommended.

There is a simple test, to verify if SAP NW RFC lib is properly installed. Just cd to \bin subfolder of SAP NW RFC lib installation folder and run rfcexec.exe, without parameters. If the above mentioned DLL import error happens also here, check if the Microsoft C/C++ redistributable is missing. In that case, just download and install (see issue41 and issue19 for more details).

If the redistributable is installed, check if the \lib subfolder is added to PATH.

wandss commented 6 years ago

Hi @mgopic, I had the same "issue" here in the past.

It has been a little time since then, but as far I can remember, like you I was trying to use the SAP NW RFC 64bits version with the pyrfc-1.9.3-py2.7-win-amd64.egg .

So I changed to ia32bits instead, provided by the "NWRFC_42-20004566.SAR" package and user a 32 bits pyrfc as well. I finally could make everything work by using the "pyrfc-1.9.3-py2.7-win32.egg" file.

According to this link: https://sap.github.io/PyRFC/install.html This error means you're using NWRFC 64bits with Python 32 bits install.

So I'd try to change everything to 32 bits and use Python 2.7 and not 3.6

bsrdjan commented 6 years ago

Looks clarified.