3

Closed

Compiled .exe gives"URI formats are not supported"-error when importing pyVISA package

description

For an application I need te pyVISA Python package. I can run the application fine via cmd "ipy.exe Program.py", but when running the compiled exe (with pyc.py) I get following error and the app terminates:
 

Unhandled Exception: System.ArgumentException: URI formats are not supported.
at Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[ arg
s, Boolean& shouldOptimize)
at IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`6.Call5(Cal
lSite site, CodeContext context, TFuncType func, T0 arg0, T1 arg1, T2 arg2, T3 a
rg3, T4 arg4)
at System.Dynamic.UpdateDelegates.UpdateAndExecute7[T0,T1,T2,T3,T4,T5,T6,TRet
](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
at IronPython.Runtime.Importer.Import(CodeContext context, String fullName, P
ythonTuple from, Int32 level)
at IronPython.Runtime.Operations.PythonOps.InitializeModule(Assembly precompi
led, String main, String[ references)
at PythonMain.Main()

 
The Program.py looks like this:

import sys
sys.path.append(r'C:\Program Files\IronPython 2.6 for .NET 4.0\Lib')
sys.path.append(r'C:\Program Files\IronPython 2.6 for .NET 4.0\Lib\site-packages')
print sys.path
 
import visa
 
print ""
print "Hello, World!"

 
I've tested it on both IP 2.7 and 2.6
Closed Dec 9 at 8:36 PM by jdhardy
Migrated to GitHub.

comments

geniedelsh wrote Feb 14, 2011 at 2:10 PM

I get the same error when importing VISA via ironpython. What I get translates to the following in Pythons ConfigParser.py:

fp = open("file:///C:/Users/eugene/Project/Win32/Debug/IronPython.DLL/share/pyvisa/.pyvisarc")

If I remove the 'file:///' (i.e. URI) everything is fine.

Now what in IronPython is passing filesystem paths out like that? And how do I fix this without patching my Python installation?

debbes wrote Jul 28, 2011 at 9:17 AM

Yes, indeed. That did the trick for me to. Although it wasn't that obvious, I patched the ConfigParser.py file in my "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib" folder like this:

Search for the only instance:

fp = open(filename)

and replace it with:

fp = open(str(filename).strip(r"file:///"))

Maybe it has to do with calling a file like that inside a .dll file, that's causing the problem?