Linux Users

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with PyVisa (Ni-Visa/SL 5)

I am hoping that someone on these forums has seen this error, because I can't find anyone else reporting this problem on python forums or using a google search, which are my normal go-to problem solvers.

I am running Scientific Linux 5.2, and I was able to install the NI-VISA driver (5.1.2) with no problems. I was able to install PyVISA using their installer, but during the install it throws the following error

Extracting PyVISA-1.4-py2.4.egg to /usr/lib/python2.4/site-packages

  File "/usr/lib/python2.4/site-packages/PyVISA-1.4-py2.4.egg/pyvisa/visa.py", line 311

    CR = b"\r"

             ^

SyntaxError: invalid syntax

Despite this error, I can install from their egg in easy install. However, when I go to use PyVisa in python, if I try to call it as stated in the documentation

>>> import visa

Traceback (most recent call last):

  File "<stdin>", line 1, in ?

  File "visa.py", line 1, in ?

    from pyvisa.visa import *

  File "/usr/lib/python2.4/site-packages/PyVISA-1.4-py2.4.egg/pyvisa/visa.py", line 311

    CR = b"\r"

             ^

SyntaxError: invalid syntax

Has anyone seen this error before? I have moderate experience with linux systems and python, and I have never had so much trouble installing things. Unfortunately, I don't know enough to know why this throws an error or what to do about it since I can't find any information on it with a google search.

Any help would be greatly appreciated.

0 Kudos
Message 1 of 10
(16,338 Views)

cstahl wrote:

Extracting PyVISA-1.4-py2.4.egg to /usr/lib/python2.4/site-packages

  File "/usr/lib/python2.4/site-packages/PyVISA-1.4-py2.4.egg/pyvisa/visa.py", line 311

    CR = b"\r"

             ^

SyntaxError: invalid syntax

It looks like your version of python might be confused by the string literal's representation. Does your system's python match what PyVISA requires?

Python documentation: String Literals

http://docs.python.org/reference/lexical_analysis.html#strings

Joe Friedchicken
NI Configuration Based Software
Get with your fellow OS users
[ Linux ] [ macOS ]
Principal Software Engineer :: Configuration Based Software
Senior Software Engineer :: Multifunction Instruments Applications Group (until May 2018)
Software Engineer :: Measurements RLP Group (until Mar 2014)
Applications Engineer :: High Speed Product Group (until Sep 2008)
Message 2 of 10
(5,779 Views)

My system has Python 2.4, and PyVISA documentation states it requires a minimum of 2.3. The README file states  that their instructions were tested with Python 2.4, though not with my operating system, and with an older version of ctypes (they tested up to 0.9.5 and I have 1.0.2).

0 Kudos
Message 3 of 10
(5,779 Views)

PEP 3112 says:

A string literal with a b in the prefix is always a syntax error in Python 2.5, so this syntax can be introduced in Python 2.6, along with the bytes type.

---
Brad Keryan
NI R&D
0 Kudos
Message 4 of 10
(5,779 Views)

Can you see what's written on and around line 311 of the file throwing the error?

Extracting PyVISA-1.4-py2.4.egg to /usr/lib/python2.4/site-packages

  File "/usr/lib/python2.4/site-packages/PyVISA-1.4-py2.4.egg/pyvisa/visa.py", line 311

    CR = b"\r"

             ^

SyntaxError: invalid syntax

To me the variable name "CR" with a value of '\r' looks like it's just trying to define the carriage return as the byte representing '\r', which is usually the Mac version of the Unix '\n'. Usually I think this sort of thing is done when processing a file. However, if you look here:

http://www.python.org/dev/peps/pep-3137/#summary

it seems like that 'b' type is only defined in python 3.0a1 and up, i.e. not 2.4 or 2.7 or anything normal people use. In any event, with python 2.7.3 I can execute that statement without an error. Odd! Maybe you can redefine it, but it seems like a larger problem may be afoot.

Message 5 of 10
(5,779 Views)

mariogiov wrote:

Can you see what's written on and around line 311 of the file throwing the error?

Extracting PyVISA-1.4-py2.4.egg to /usr/lib/python2.4/site-packages

  File "/usr/lib/python2.4/site-packages/PyVISA-1.4-py2.4.egg/pyvisa/visa.py", line 311

    CR = b"\r"

             ^

SyntaxError: invalid syntax

To me the variable name "CR" with a value of '\r' looks like it's just trying to define the carriage return as the byte representing '\r', which is usually the Mac version of the Unix '\n'. Usually I think this sort of thing is done when processing a file. However, if you look here:

http://www.python.org/dev/peps/pep-3137/#summary

it seems like that 'b' type is only defined in python 3.0a1 and up, i.e. not 2.4 or 2.7 or anything normal people use. In any event, with python 2.7.3 I can execute that statement without an error. Odd! Maybe you can redefine it, but it seems like a larger problem may be afoot.

Line 311 is

CR = b"\r"

I was initially tempted to try commenting it out, but a large portion of the file depends on it.

In a previous installation, I tried to update to Python 2.7, which resulting in more errors, but may or may not have been related to the fact that it was a 32-bit system.

I will try to upgrade python to 2.7 on this installation, since you were able to execute it without error, and report back.

0 Kudos
Message 6 of 10
(5,779 Views)

I installed Python 2.7.3 and tested the line CR = b"\r" with no errors.

I installed PyVISA into Python 2.7.3, with no errors being thrown either during the initial installation or the installation of the egg.

However,  when I try to import it into Python

Python 2.7.3 (default, Jul  6 2012, 14:20:57)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import visa

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "visa.py", line 1, in <module>

    from pyvisa.visa import *

  File "/usr/local/lib/python2.7/site-packages/PyVISA-1.4-py2.7.egg/pyvisa/visa.py", line 231, in <module>

    resource_manager = ResourceManager()

  File "/usr/local/lib/python2.7/site-packages/PyVISA-1.4-py2.7.egg/pyvisa/vpp43.py", line 105, in __new__

    it.init(*args, **kwds)

  File "/usr/local/lib/python2.7/site-packages/PyVISA-1.4-py2.7.egg/pyvisa/visa.py", line 227, in init

    self.session = self.vi = vpp43.open_default_resource_manager()

  File "/usr/local/lib/python2.7/site-packages/PyVISA-1.4-py2.7.egg/pyvisa/vpp43.py", line 758, in open_default_resource_manager

    visa_library().viOpenDefaultRM(byref(session))

  File "/usr/local/lib/python2.7/site-packages/PyVISA-1.4-py2.7.egg/pyvisa/vpp43.py", line 175, in __call__

    self.load_library()

  File "/usr/local/lib/python2.7/site-packages/PyVISA-1.4-py2.7.egg/pyvisa/vpp43.py", line 146, in load_library

    self.__lib = self.__cdecl_lib = cdll.LoadLibrary(path)

  File "/usr/local/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary

    return self._dlltype(name)

  File "/usr/local/lib/python2.7/ctypes/__init__.py", line 365, in __init__

    self._handle = _dlopen(self._name, mode)

OSError: /usr/local/vxipnp/linux/bin/libvisa.so.7: wrong ELF class: ELFCLASS32

This is the same error I got using a different computer. At the time I though it was related to the fact that  the computer was a 32-bit. However, the computer I am now working on is a 64-bit, so that seems unlikely.

Has anyone seen anything like this before, or perhaps its a problem with the particular computers I'm using?

0 Kudos
Message 7 of 10
(5,779 Views)

  File "/usr/local/lib/python2.7/site-packages/PyVISA-1.4-py2.7.egg/pyvisa/vpp43.py", line 175, in __call__

    self.load_library()

  File "/usr/local/lib/python2.7/site-packages/PyVISA-1.4-py2.7.egg/pyvisa/vpp43.py", line 146, in load_library

    self.__lib = self.__cdecl_lib = cdll.LoadLibrary(path)

  File "/usr/local/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary

    return self._dlltype(name)

  File "/usr/local/lib/python2.7/ctypes/__init__.py", line 365, in __init__

    self._handle = _dlopen(self._name, mode)

OSError: /usr/local/vxipnp/linux/bin/libvisa.so.7: wrong ELF class: ELFCLASS32

This is the same error I got using a different computer. At the time I though it was related to the fact that  the computer was a 32-bit. However, the computer I am now working on is a 64-bit, so that seems unlikely.

The "libvisa.so.7" file is an executable binary file (see http://en.wikipedia.org/wiki/Library_%28computing%29#Shared_libraries), and in this case it has been compiled for a 32-bit system. It doesn't look like NI-VISA for Linux supports 64-bit architectures, or if it does it only does so in 32-bit user mode: http://joule.ni.com/nidu/cds/view/p/id/2917/lang/en

Are you sure the other computer you were using was 32-bit? For 32-bit, the output of `uname -m` will be 'i686'; 64-bit will print 'x86_64'.

0 Kudos
Message 8 of 10
(5,779 Views)

mariogiov wrote:

  File "/usr/local/lib/python2.7/site-packages/PyVISA-1.4-py2.7.egg/pyvisa/vpp43.py", line 175, in __call__

    self.load_library()

  File "/usr/local/lib/python2.7/site-packages/PyVISA-1.4-py2.7.egg/pyvisa/vpp43.py", line 146, in load_library

    self.__lib = self.__cdecl_lib = cdll.LoadLibrary(path)

  File "/usr/local/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary

    return self._dlltype(name)

  File "/usr/local/lib/python2.7/ctypes/__init__.py", line 365, in __init__

    self._handle = _dlopen(self._name, mode)

OSError: /usr/local/vxipnp/linux/bin/libvisa.so.7: wrong ELF class: ELFCLASS32

This is the same error I got using a different computer. At the time I though it was related to the fact that  the computer was a 32-bit. However, the computer I am now working on is a 64-bit, so that seems unlikely.

The "libvisa.so.7" file is an executable binary file (see http://en.wikipedia.org/wiki/Library_%28computing%29#Shared_libraries), and in this case it has been compiled for a 32-bit system. It doesn't look like NI-VISA for Linux supports 64-bit architectures, or if it does it only does so in 32-bit user mode: http://joule.ni.com/nidu/cds/view/p/id/2917/lang/en

Are you sure the other computer you were using was 32-bit? For 32-bit, the output of `uname -m` will be 'i686'; 64-bit will print 'x86_64'.I

I double checked--the computer I was using is a 64-bit. I assumed it wasn't because it is rather old and in the past I had tried to install 64-bit operating systems without success, but that computer has many many problems.

Thank you for all your help. I will try to find an actual 32-bit computer try it out on.

0 Kudos
Message 9 of 10
(5,779 Views)

Hello All,

I am using 64 bit windows machine.I have paythin version 2.5 and idle version 1.2

I have installed Pyvisa 1.4_32bit on my system.I want to use GBIP interface for my project.

If i run my Python script it is giving me error as below:

Traceback (most recent call last):

  File "C:\Users\rsap\Desktop\StreetFighter\I2C_Projects_ES10\dev_py - Copy\Reset Transistion.py", line 9, in <module>

    from visa import *

  File "C:\Python25\Lib\site-packages\visa.py", line 1, in <module>

    from pyvisa.visa import *

  File "C:\Python25\lib\site-packages\pyvisa\visa.py", line 456

    self.term_chars = b""

                        ^

SyntaxError: invalid syntax

>>>

Please help as soon as possible.Its very important for me.

Thanks,

Renuka

0 Kudos
Message 10 of 10
(5,779 Views)