Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Exodriver and libusb install into a Unix virtual environment

unix U3 Mac

  • Please log in to reply
15 replies to this topic

#1 Paul.L.

Paul.L.
  • Members
  • 22 posts

Posted 25 March 2015 - 02:16 PM

I’m trying to install libusb and Exodriver into a virtual environment in unix (Mac) so I can isolate my Python projects. I installed libusb from “~/.virtualenvs/labjack$ pip install libusb1” and I installed Exodriver from “Exodriver_NativeUSB_Setup.pkg”. Both reported successful installation. 

I can run this from terminal which, I think, confirms successful connection to the U3. 

Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46) 

[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin

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

>>> import u3

>>> d = u3.U3()

>>> d.getCalibrationData()

{'lvSESlope': 3.783055581152439e-05, 'vRegAtCal': 0.0, 'vRefAtCAl': 2.490722060902044, 'hvAIN0Slope': 0.0003207332920283079, 'hvAIN0Offset': -10.5473404917866, 'hvAIN1Slope': 0.00032037775963544846, 'hvAIN2Offset': -10.496328913373873, 'vRef1.5AtCal': 0.0, 'hvAIN1Offset': -10.518026813166216, 'lvDiffOffset': -2.4940691615920514, 'lvDiffSlope': 7.579824887216091e-05, 'hvAIN2Slope': 0.00032011326402425766, 'dac0Slope': 51.28191462205723, 'lvSEOffset': 0.002814129926264286, 'tempSlope': 0.012561686336994171, 'dac1Slope': 51.28704376355745, 'hvAIN3Offset': -10.529342665569857, 'hvAIN3Slope': 0.00032064737752079964, 'dac1Offset': -0.7033130372874439, 'dac0Offset': -0.6869004622567445}

>>>

 

However, when I run a Python script I get this: 

Pauls:PaulSan ~$ cd '/Users/PaulSan/Desktop/LabJack Scripts/' && '/usr/local/bin/pythonw'  '/Users/PaulSan/Desktop/LabJack Scripts/labjack_2_channel_0319.py'  && echo Exit status: $? && exit 1

Traceback (most recent call last):

  File "/Users/PaulSan/Desktop/LabJack Scripts/labjack_2_channel_0319.py", line 5, in <module>

    import u3

ImportError: No module named u3

Pauls:PaulSan ~/Desktop/LabJack Scripts$

 

Can you suggest where I look to find the disconnect? Do you have a version of Exodriver on PYPI? 

Thanks



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 25 March 2015 - 03:17 PM

We do not have a version of Exodriver for PYPI but you can move around the libusb and liblabjackusb libraries if needed or build them from source code.

 

It seems like you have LabJackPython installed for the version of Python you ran in your terminal and is working with your U3, but the problem you are seeing is that the LabJackPython modules (including u3.py) can't be found when running your script. Is /usr/local/bin/pythonw the same version of Python you ran in your terminal which is working?

 

You can try installing the latest version of LabJackPython from GitHub and use pip on that zip file for installation. For example:

 

cd <path-to-download>

pip install LabJackPython-master.zip

 

If that doesn't help, make sure LabJackPython is installed for /usr/local/bin/pythonw:

 

cd <path-to-download>/LabJackPython-master

/usr/local/bin/pythonw setup.py install



#3 Paul.L.

Paul.L.
  • Members
  • 22 posts

Posted 25 March 2015 - 04:05 PM

 

 

the LabJackPython modules (including u3.py) can't be found when running your script

Where is u3.py usually located ?



#4 Paul.L.

Paul.L.
  • Members
  • 22 posts

Posted 25 March 2015 - 04:29 PM

 

 

Is /usr/local/bin/pythonw the same version of Python you ran in your terminal which is working?

I seem to have 2 versions of python in /usr/local/bin/; python and pythonw. Which is needed by LabJackPython? 

 

This is the contents of the virtual environment. 

Pauls:PaulSan ~/.virtualenvs/labjack$ ll

total 16

drwxr-xr-x   8 PaulSan  staff  272 Mar 24 13:58 .

drwxr-xr-x  16 PaulSan  staff  544 Mar 17 21:40 ..

lrwxr-xr-x   1 PaulSan  staff   56 Mar 17 21:40 .Python -> /Library/Frameworks/Python.framework/Versions/2.7/Python

[email protected] 10 PaulSan  staff  340 Mar 18 09:42 LabJackPython-4-24-2014

drwxr-xr-x  19 PaulSan  staff  646 Mar 18 09:16 bin

drwxr-xr-x   3 PaulSan  staff  102 Mar 17 21:40 include

drwxr-xr-x   3 PaulSan  staff  102 Mar 17 21:40 lib

-rw-r--r--   1 PaulSan  staff   60 Mar 18 09:15 pip-selfcheck.json

 

libusb and liblabjackusb are in /usr/local/lib$. My hunch is they should be in the lib directly above. 



#5 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 25 March 2015 - 05:21 PM

Where u3.py and all other LabJack related modules are installed depends on your version/build of Python. For example, on one of my Macs it is under "/usr/local/lib/python2.7/site-packages" and on another it is under "/Library/Python/2.7/site-packages". LabJackPython needs to be installed for the version of Python you are using so the modules are placed in the correct directories and it can find them. If you are using python, install with:

 

sudo python setup.py install

 

If using /usr/local/bin/pythonw (whose lib directory structure differs than python it seems) install with:

 

sudo /usr/local/bin/pythonw setup.py install

 

When installing it will display where the files are being copied.

 

The libs are fine in /usr/local/lib, but would also run in /usr/lib (with the correct permissions). The libs are running fine however as indicated in your terminal run of "d = u3.U3()" and "d.getCalibrationData()" without error.



#6 Paul.L.

Paul.L.
  • Members
  • 22 posts

Posted 26 March 2015 - 12:42 PM

I've continued with installation of the libusb and exodriver into an isolated virtual environment. Except for a warning, libusb seems to be installed. Please let me know if I need to address the warning in some way. 

 

Pauls:PaulSan ~/.virtualenvs/labjack/libusb-1.0.19$ make

/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-recursive

Making all in libusb

  CC       libusb_1_0_la-core.lo

  CC       libusb_1_0_la-descriptor.lo

  CC       libusb_1_0_la-io.lo

  CC       libusb_1_0_la-strerror.lo

  CC       libusb_1_0_la-sync.lo

  CC       libusb_1_0_la-hotplug.lo

  CC       os/libusb_1_0_la-threads_posix.lo

  CC       os/libusb_1_0_la-darwin_usb.lo

os/darwin_usb.c:1281:27: warning: expression which evaluates to zero treated as a null pointer constant of type

      'IOUSBInterfaceInterface550 **' (aka 'struct IOUSBInterfaceStruct550 **') [-Wnon-literal-null-conversion]

  cInterface->interface = IO_OBJECT_NULL;

                          ^~~~~~~~~~~~~~

/System/Library/Frameworks/IOKit.framework/Headers/IOTypes.h:164:24: note: expanded from macro 'IO_OBJECT_NULL'

#define IO_OBJECT_NULL  ((io_object_t) 0)

                        ^~~~~~~~~~~~~~~~~

1 warning generated.

  CC       os/libusb_1_0_la-poll_posix.lo

  CCLD     libusb-1.0.la

Making all in doc

make[2]: Nothing to be done for `all'.

make[2]: Nothing to be done for `all-am'.

 
When I try to install liblabjackusb I receive a fatal error:
 
Pauls:PaulSan ~/.virtualenvs/labjack/liblabjackusb$ make

cc -fPIC -g -Wall  -c labjackusb.c

labjackusb.c:25:10: fatal error: 'libusb-1.0/libusb.h' file not found

#include <libusb-1.0/libusb.h>

         ^

1 error generated.

make: *** [labjackusb.o] Error 1

Pauls:PaulSan ~/.virtualenvs/labjack/liblabjackusb$ cd ..

Pauls:PaulSan ~/.virtualenvs/labjack$ cd lib

Pauls:PaulSan ~/.virtualenvs/labjack/lib$ ll

total 960

drwxr-xr-x   8 PaulSan  staff     272 Mar 26 11:47 .

drwxr-xr-x  10 PaulSan  staff     340 Mar 26 12:26 ..

-rwxr-xr-x   1 PaulSan  staff  109024 Mar 26 11:47 libusb-1.0.0.dylib

-rw-r--r--   1 PaulSan  staff  372632 Mar 26 11:47 libusb-1.0.a

lrwxr-xr-x   1 PaulSan  staff      18 Mar 26 11:47 libusb-1.0.dylib -> libusb-1.0.0.dylib

-rwxr-xr-x   1 PaulSan  staff     960 Mar 26 11:47 libusb-1.0.la

drwxr-xr-x   3 PaulSan  staff     102 Mar 26 11:47 pkgconfig

drwxr-xr-x  51 PaulSan  staff    1734 Mar 17 21:40 python2.7

Pauls:PaulSan ~/.virtualenvs/labjack/lib$ 

 
The liblabjackusb 'make' is looking for libusb.h but can't find it, not surprising since there is no libusb-1.0 directory. 
(The file listing is of 'labjack/lib')
 
Would you tell me how to correct this ?
Thanks


#7 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 26 March 2015 - 02:13 PM

I'm not sure about the libusb warning, but it should probably be fine. Run Exodriver and see if there are issues when it uses it.

 

As for the Exodriver build and the libusb.h header, typically that is installed either in /usr/local/include/libusb-1.0/ or /usr/include/libusb-1.0/ ("make install" does this in the libusb build). You could try making a labjack/lib/libusb-1.0 directory and copy the libusb.h file to it. The libusb.h file is in its source code. If that doesn't work, make a /usr/local/lib/libusb-1.0/ directory and copy libusb.h there, or modify the Makefile and use the "-I" flag to specify where the libusb-1.0 directory is, which contains the libusb.h header file, is.



#8 Paul.L.

Paul.L.
  • Members
  • 22 posts

Posted 26 March 2015 - 03:32 PM

I changed 'PREFIX ?= /usr/local'    to    'PREFIX ?= /Users/PaulSan/.virtualenvs/labjack'

and

'LIBFLAGS = -lusb-1.0 -lc'    to    LIBFLAGS = -l/Users/PaulSan/.virtualenvs/labjack/include/usb-1.0 -lc

 

but I get the same error. 

 

Just looking now more closely at the LIBFLAGS line I see the -l flag is for 'usb-1.0', but the fatal error is looking for 'libusb-1.0'. Is this an issue ?

 

libusb.h is in the directory: /Users/PaulSan/.virtualenvs/labjack/include/libusb-1.0/

 

Looking in 'Makefile' I don't see any reference to libusb-1.0. Is it referenced labjackusb.c:25:10: ?



#9 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 26 March 2015 - 04:28 PM

Try "-l/Users/PaulSan/.virtualenvs/labjack/include/" instead. The labjackusb.c code is looking for libusb-1.0/libusb.h (#include <libusb-1.0/libusb.h>). With that "-I" directory, it should be trying this path: /Users/PaulSan/.virtualenvs/labjack/include/libusb-1.0/libusb.h

 

With "-I/Users/PaulSan/.virtualenvs/labjack/include/usb-1.0" it will try to incorrectly search for /Users/PaulSan/.virtualenvs/labjack/include/libusb-1.0/libusb-1.0/libusb.h. You need to point to the directory which has the libusb-1.0 directory which I might not have been clear about in my previous post.

 

Also, PREFIX is used when installing/copying the lib files in the "make install" step.



#10 Paul.L.

Paul.L.
  • Members
  • 22 posts

Posted 26 March 2015 - 04:59 PM

I edited Makefile to  "-l/Users/PaulSan/.virtualenvs/labjack/include/" but received the same error. 

I keep looking at it to see if I have a typo, but I don't see one. 

 

This is where libusb.h sits:

Pauls:PaulSan ~/.virtualenvs/labjack/include/libusb-1.0$ ll

total 144

drwxr-xr-x  3 PaulSan  staff    102 Mar 26 11:47 .

drwxr-xr-x  4 PaulSan  staff    136 Mar 26 11:47 ..

[email protected] 1 PaulSan  staff  70156 Mar 26 11:47 libusb.h

 

This is where I have liblabjackusb; and the result of 'make'. 

 

Pauls:PaulSan ~/.virtualenvs/labjack/liblabjackusb$ ll

total 128

[email protected]  6 PaulSan  staff    204 Mar 26 15:03 .

drwxr-xr-x  10 PaulSan  staff    340 Mar 26 12:26 ..

[email protected]  1 PaulSan  staff   1496 Mar 26 15:02 Makefile

[email protected]  1 PaulSan  staff    286 Sep 15  2014 add_ldconfig_path.sh

[email protected]  1 PaulSan  staff  37671 Sep 15  2014 labjackusb.c

[email protected]  1 PaulSan  staff  13189 Sep 15  2014 labjackusb.h

Pauls:PaulSan ~/.virtualenvs/labjack/liblabjackusb$ nano Makefile

Pauls:PaulSan ~/.virtualenvs/labjack/liblabjackusb$ nano Makefile

Pauls:PaulSan ~/.virtualenvs/labjack/liblabjackusb$ make

cc -fPIC -g -Wall  -c labjackusb.c

labjackusb.c:25:10: fatal error: 'libusb-1.0/libusb.h' file not found

#include <libusb-1.0/libusb.h>

         ^

1 error generated.

make: *** [labjackusb.o] Error 1



#11 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 27 March 2015 - 11:26 AM

Add "-l/Users/PaulSan/.virtualenvs/labjack/include/" to the CFLAGS. That should do it.



#12 Paul.L.

Paul.L.
  • Members
  • 22 posts

Posted 27 March 2015 - 12:57 PM

I wonder if I have the correct syntax in CFLAGS. Here's what CFLAGS looks like:

 

CFLAGS += -fPIC -g -Wall -l/Users/PaulSan/.virtualenvs/labjack/include/ $(ARCHFLAGS)

 

and here is the result. 

 

Pauls:PaulSan ~/.virtualenvs/labjack/liblabjackusb$ make

cc -fPIC -g -Wall -l/Users/PaulSan/.virtualenvs/labjack/include/  -c labjackusb.c

clang: warning: -l/Users/PaulSan/.virtualenvs/labjack/include/: 'linker' input unused

labjackusb.c:25:10: fatal error: 'libusb-1.0/libusb.h' file not found

#include <libusb-1.0/libusb.h>

         ^

1 error generated.

make: *** [labjackusb.o] Error 1

Pauls:PaulSan ~/.virtualenvs/labjack/liblabjackusb$ 



#13 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 27 March 2015 - 02:10 PM

I'll use a different font in this post for less confusion since "I" looks like "l" in the default font.

 

The "-I" flag is an uppercase "i". You are using a lowercase "L" (l). Having this flag and correct directory path and it should work. So (double check the path, but I did use "-I" in the CFLAGS with success):

 

CFLAGS += -fPIC -g -Wall -I/Users/PaulSan/.virtualenvs/labjack/include/ $(ARCHFLAGS)

 

This flag is documented here.



#14 Paul.L.

Paul.L.
  • Members
  • 22 posts

Posted 27 March 2015 - 04:11 PM

I removed prior edits to PREFIX and LIBFLAGS returning these to their original state from LJ.

I fixed the -l (lower case L)  to  -I (an upper case I). The CFLAGS line reads exactly as the prior post. 

 

Result:

Pauls:PaulSan ~/.virtualenvs/labjack/liblabjackusb$ make

cc -fPIC -g -Wall -I/Users/PaulSan/.virtualenvs/labjack/include/  -c labjackusb.c

libtool -dynamic -o liblabjackusb.dylib -install_name liblabjackusb.dylib -current_version 2.5.3 -compatibility_version 2.5.3 labjackusb.o -lusb-1.0 -lc

error: libtool: can't locate file for: -lusb-1.0

error: libtool: file: -lusb-1.0 is not an object file (not allowed in a library)

make: *** [liblabjackusb.dylib] Error 1

 

I removed a dot o file prior to running make. 

 

I'm about to conclude that what I'm trying to create is doable even though this is going to cause trouble on other projects.

 

I much appreciate your help and suggestions. 

Best,



#15 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 27 March 2015 - 04:50 PM

In this case libtool can't find libusb-1.0.dylib which -lusb-1.0 links to. Use the "-L" flag to specify the lib path. For example (I assume libusb-1.0.dylib is in /Users/PaulSan/.virtualenvs/labjack/lib, otherwise correct this path):

 

LIBFLAGS = -L/Users/PaulSan/.virtualenvs/labjack/lib -lusb-1.0 -lc

 
Afterwards, you'll want liblabjackusb.dylib in the same directory as libusb-1.0.dylib.


#16 Paul.L.

Paul.L.
  • Members
  • 22 posts

Posted 30 March 2015 - 11:02 AM

It works!!!

I think some of the issue was not 'activating' and 'deactivating' the virtual environments before then after installing libraries. Now I have these files:

 

-rwxr-xr-x   1 PaulSan  staff   26952 Mar 27 18:13 liblabjackusb.dylib

-rwxr-xr-x   1 PaulSan  staff  109024 Mar 26 11:47 libusb-1.0.0.dylib

-rw-r--r--   1 PaulSan  staff  372632 Mar 26 11:47 libusb-1.0.a

lrwxr-xr-x   1 PaulSan  staff      18 Mar 26 11:47 libusb-1.0.dylib -> libusb-1.0.0.dylib

-rwxr-xr-x   1 PaulSan  staff     960 Mar 26 11:47 libusb-1.0.la

 
in two locations:
(labjack)Pauls:PaulSan ~/.virtualenvs/labjack/lib$ l
and
Pauls:PaulSan /usr/local/lib$ l
 
I'm not sure which location is being used, but it works, so I'll come back later to figure it out. 
I'm launching the script from within the activated virtual environment '(labjack)'. 
 
(labjack)Pauls:PaulSan ~/.virtualenvs/labjack/labjack_scripts$ with 
 
Thanks for your help!
Paul.L.




Also tagged with one or more of these keywords: unix, U3, Mac

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users