{"id":1245,"date":"2012-07-13T16:34:03","date_gmt":"2012-07-13T21:34:03","guid":{"rendered":"http:\/\/bardagjy.com\/?p=1245"},"modified":"2013-04-14T20:28:54","modified_gmt":"2013-04-15T01:28:54","slug":"pyvisa-on-osx","status":"publish","type":"post","link":"https:\/\/bardagjy.com\/?p=1245","title":{"rendered":"PyVISA on OSX"},"content":{"rendered":"<p>So after some persistance, I&#8217;ve managed to get <a href=\"http:\/\/pyvisa.sourceforge.net\/\">PyVISA<\/a> working under OS X 10.6.8 Snow Leopard on a late 2008 MacBook Pro. <\/p>\n<ol>\n<li>Download and install <a href=\"http:\/\/ftp.ni.com\/support\/softlib\/visa\/NI-VISA\/5.1.2\/mac\/NI-VISA-5.1.2.dmg\">NI VISA 5.1.2 for OSX<\/a><\/li>\n<li>In your home directory, create the file <code>.pyvisarc<\/code> with the contents<br \/>\n<code>[Paths]<br \/>\nVISA library: \/Library\/Frameworks\/VISA.framework\/VISA<\/code><\/li>\n<li>Download and untar <a href=\"http:\/\/sourceforge.net\/projects\/pyvisa\/files\/latest\/download\">PyVISA 1.4<\/a><\/li>\n<li>Install as root with <code>easy_install<\/code><br \/>\n<code>$ sudo easy_install PyVISA-1.4<\/code><\/li>\n<\/ol>\n<p>Now, NI VISA 5.1.2 was compiled for 32 bit systems &#8211; check this with:<br \/>\n<code>$ file \/Library\/Frameworks\/VISA.framework\/VISA<\/code><\/p>\n<p>If it returns i386, not x86_64, you&#8217;ve got a 32 bit binary. If you try to use PyVISA as shipped with OSX, it will default to 64 bit mode. When you try to <code>import visa<\/code>, you&#8217;ll get several errors reading <code>no suitable image found<\/code> and <code>no matching architecture in universal wrapper<\/code>. <\/p>\n<p>This is a CTYPES problem and discussed in this <a href=\"http:\/\/stackoverflow.com\/questions\/3481508\/python-ctypes-not-loading-dynamic-library-on-mac-os-x\">stackoverflow<\/a> question.<\/p>\n<p>It is possible to force OSX to run Python in 32 bit mode by<br \/>\n<code>$ export VERSIONER_PYTHON_PREFER_32_BIT=yes<\/code><\/p>\n<p>Which you could put in your <code>.profile<\/code> or <code>.bashrc<\/code> to run every time you open a new shell. But I didn&#8217;t want to default to 32 bit python, I&#8217;d rather force it into 32 bit mode when needed. <\/p>\n<p>So, to my <code>.profile<\/code> I added<br \/>\n<code>alias python386='arch -i386 python'<\/code><\/p>\n<p>To force a script to execute under 32 bit Python, rather than including the line <code>#!\/usr\/bin\/python<\/code>, I start my script with <code>#!\/usr\/bin\/env arch -i386 python<\/code>.<\/p>\n<p>I&#8217;m still working on a way to force iPython to run in 32 bit mode, if started with <code>arch<\/code> it still calls system <code>python<\/code>. Most unfortunately, I do not have 32 bit versions of many useful packages (e.g., <code>numpy<\/code> and <code>pylab<\/code>) forcing me to save data (say as a CSV file) and process it with 64 bit Python). That will become really tiresome if I try to be interactive with a PyVISA.<\/p>\n<p>I specified the version numbers that I used, but am unsure if they are required, just what worked for me.<\/p>\n<p>Below, I&#8217;ve included a short demo, verifying proper operation of the HP\/Agilent 34401A.<\/p>\n<pre lang=\"python\" line=\"1\">\r\n#!\/usr\/bin\/env arch -i386 python\r\n# pyvisa calls NI visa which is compiled with 32 bits, so run python in 32 bit\r\nfrom visa import *\r\n\r\ninst = SerialInstrument('ASRL1',\r\n                        baud_rate = 9600,\r\n                        data_bits = 7,\r\n                        stop_bits = 2,\r\n                        parity = even_parity,\r\n                        term_chars = CR+LF,\r\n                        end_input = term_chars_end_input,\r\n                        send_end = True,\r\n                        delay = 2\r\n                        )\r\n\r\ninst.write('SYST:REM')\r\ninst.write('*RST')\r\nsleep(10)\r\ninst.write('SYST:REM')\r\nprint inst.ask('*IDN?')\r\n<\/pre>\n<p>It should print <code>HEWLETT-PACKARD,34401A,0,11-5-2<\/code>, or whatever your software version is.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So after some persistance, I&#8217;ve managed to get PyVISA working under OS X 10.6.8 Snow Leopard on a late 2008 MacBook Pro. Download and install NI VISA 5.1.2 for OSX In your home directory, create the file .pyvisarc with the contents [Paths] VISA library: \/Library\/Frameworks\/VISA.framework\/VISA Download and untar PyVISA 1.4 Install as root with easy_install [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1267,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[19],"tags":[99,75,74,100,98],"_links":{"self":[{"href":"https:\/\/bardagjy.com\/index.php?rest_route=\/wp\/v2\/posts\/1245"}],"collection":[{"href":"https:\/\/bardagjy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bardagjy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bardagjy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bardagjy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1245"}],"version-history":[{"count":25,"href":"https:\/\/bardagjy.com\/index.php?rest_route=\/wp\/v2\/posts\/1245\/revisions"}],"predecessor-version":[{"id":1352,"href":"https:\/\/bardagjy.com\/index.php?rest_route=\/wp\/v2\/posts\/1245\/revisions\/1352"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bardagjy.com\/index.php?rest_route=\/wp\/v2\/media\/1267"}],"wp:attachment":[{"href":"https:\/\/bardagjy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bardagjy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bardagjy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}