Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 3 support, ctypes error? #9

Open
tobeycarman opened this issue Jul 25, 2017 · 3 comments
Open

python 3 support, ctypes error? #9

tobeycarman opened this issue Jul 25, 2017 · 3 comments

Comments

@tobeycarman
Copy link

tobeycarman commented Jul 25, 2017

I am trying to build aravis and python-aravis in a python3 environment and I am getting a ctypes.cast error.

I am on Ubuntu 16.04, and I installed python3.6 under conda. I was able to build aravis, and python-aravis with no errors (although I did have to monkey-patch aravis.py to import pgi instead of import gi). I then run my test script which is this:

#!/usr/bin/env python

import pgi
pgi.require_version('Aravis', '0.6')

import aravis
import time
import sys

FRAMES=4

available_cameras = aravis.get_device_ids()
if len(available_cameras) > 0:
  cam = aravis.Camera(available_cameras[0])
else:
  print("No camera is on. Quitting.")
  sys.exit(-1)  

cam.start_acquisition()
for i in range(0, FRAMES):
  print("Sleeping while capturing images...")
  time.sleep(1)
print("Stopping acq...")
cam.stop_acquisition()

print("Gonna show you some images here...")
for i in range(0, 2):
  print("Popping a frame...")
  try:
    d = cam.pop_frame()
    print("Frame {} is:".format(i))
    print(d)
  except Exception as e:
    print("UH OH, there was a problem!: ", e)
    raise e

for i in range(0, FRAMES):
  try:
    print("Saving {} of 5 frames...".format(i))
    aravis.sfn(cam, app.config['IMAGES_INCOMING'])
  except Exception as e:
    print("UH OH, there was a problem!: ", e)
    raise e

When I run my test script I get this:

$ ./test.py 
Sleeping while capturing images...
Sleeping while capturing images...
Sleeping while capturing images...
Sleeping while capturing images...
Stopping acq...
Gonna show you some images here...
Popping a frame...
UH OH, there was a problem!:  argument 1: <class 'TypeError'>: wrong type
Traceback (most recent call last):
  File "./test.py", line 35, in <module>
    raise e
  File "./test.py", line 30, in <module>
    d = cam.pop_frame()
  File "/home/vagrant/anaconda3/envs/py3/lib/python3.6/site-packages/aravis-0.5-py3.6.egg/aravis.py", line 153, in pop_frame
  File "/home/vagrant/anaconda3/envs/py3/lib/python3.6/site-packages/aravis-0.5-py3.6.egg/aravis.py", line 169, in try_pop_frame
  File "/home/vagrant/anaconda3/envs/py3/lib/python3.6/site-packages/aravis-0.5-py3.6.egg/aravis.py", line 191, in _array_from_buffer_address
  File "/home/vagrant/anaconda3/envs/py3/lib/python3.6/ctypes/__init__.py", line 485, in cast
    return _cast(obj, obj, typ)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
@tobeycarman
Copy link
Author

tobeycarman commented Jul 25, 2017

Partially figured this out - pip installed package pgi does not seem to work, but if I install the gi package using apt-get, it works (sudo apt-get install python-gi)

So this dosen't really have to do with python3 at all. I suspect it is some small different in implementation between the python-gi implementation of introspection vs the pgi implementation of introspection.

@IamSierraCharlie
Copy link

IamSierraCharlie commented Jul 25, 2017

For python 3, I thought you needed pip3 rather than pip
on ubuntu
sudo apt-get install python3-pip
then do
pip3 install pgi

The above works for me on Ubuntu
##############################
pip3 install pgi
Collecting pgi
Downloading pgi-0.0.11.1.tar.gz (235kB)
100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 245kB 2.4MB/s
Building wheels for collected packages: pgi
Running setup.py bdist_wheel for pgi ... done
Stored in directory: /home/s/.cache/pip/wheels/cc/9e/e2/a9c5dda8bc0bd98379827b52a97c0f593034d1094a55f689e7
Successfully built pgi
Installing collected packages: pgi
Successfully installed pgi-0.0.11.1
####################################
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial

I'm no expert in python, but in my own experience I've found using pip / pip3 to be a better way to manage python packages over using apt.
Someone with more experience may suggest otherwise.
Steve

@tobeycarman
Copy link
Author

@IamSierraCharlie, I agree re: pip vs apt-get. I always start with pip, but occasionally there is something I can't find with pip that is available with apt-get.

In my first post, I was actually trying to use the conda package manager (https://www.continuum.io/downloads) but I got really confused.

I now have it working, and like I said, I think the problem before was that the pgi that I installed with pip was giving that error out of ctypes.cast(...), where as if I install gi (which I can't find in pip, but I did find with apt-get), then everything works perfectly...

At this point I've reduced myself to only needing python-virtualenv, python-gi, and python-dev from the apt-get repos, and everything else I can get with pip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants