Crash on Nite initialisation in python program written using primesense2.2.0.30-5 - openni

I am using Ubunut 14.04 and have installed OpenNI 2.2, NITE 2.2 and primesense2.2.0.30-5 (https://pypi.python.org/pypi/primesense/2.2.0.30-5)
The sample program mentioned at the above site works quite well however when I am trying to use initialize nite2 the program crashes.
Here is the code:
from primesense import openni2, nite2
openni2.initialize() # can also accept the path of the OpenNI redistribution
nite2.initialize()
if (nite2.is_initialized()):
print "nite2 initialized"
else:
print "nite2 not initialized"
dev = openni2.Device.open_any()
print dev.get_sensor_info(openni2.SENSOR_DEPTH)
depth_stream = dev.create_depth_stream()
depth_stream.start()
frame = depth_stream.read_frame()
frame_data = frame.get_buffer_as_uint16()
depth_stream.stop()
openni2.unload()
Error Report :
Traceback (most recent call last):
File "test.py", line 4, in <module>
nite2.initialize()
File "/usr/local/lib/python2.7/dist-packages/primesense/nite2.py", line 81, in initialize
("\n ".join("%s: %s" % (dir, ex) for dir, ex in exceptions)),)
primesense.utils.InitializationError: NiTE2 could not be loaded:
/home/user/project/kinect/NiTE-Linux-x64-2.2/Samples/Bin/libNiTE2.so: /home/user/project/kinect/NiTE-Linux-x64-2.2/Samples/Bin/libNiTE2.so: undefined symbol: niteDumpUserTrackerCalibrationDataToFile
OpenNI2-FreenectDriver: Closing device freenect://0
I want nite python bindings for user tracking and hand tracking . Did anyone done it before successfully

A workaround is to comment the following lines in file _openni2.py from the primesense python bindings:
global _niteDumpUserTrackerCalibrationDataToFile
_niteDumpUserTrackerCalibrationDataToFile = dll.niteDumpUserTrackerCalibrationDataToFile
_niteDumpUserTrackerCalibrationDataToFile.restype = NiteStatus
_niteDumpUserTrackerCalibrationDataToFile.argtypes = [NiteUserTrackerHandle, NiteUserId, ctypes.c_char_p]
Also, make sure you have a copy/symlink of both the NiTE2 library and folder (Redist/NiTE2 in the archive) in the same directory as your python script.

Related

cx_Freeze: 'The system cannot find the file specified' error during build [win10] [PyQt4] [python2.7]

I'm trying to create a .exe file from a python script (which use PyQt4 GUI and matplotlib). I'm using cx_Freeze version 5.1.1 for 64-bit windows with the following setup.py:
import cx_Freeze
import sys
import matplotlib
base = "Win32GUI"
includes = ["atexit"]
buildOptions = dict(
#create_shared_zip=False,
#append_script_to_exe=True,
includes=includes
)
executables = [cx_Freeze.Executable(script = "main.py", base = base)] # icon = "chart32.jpg")]
cx_Freeze.setup(
name= "1ChPlotGUI",
options = dict(build_exe=buildOptions), # {"build_exe": {"packages": ["matplotlib"], "include_files":["chart32.jpg"]}},
version = "0.01",
description = "1 Channel Plotting app with GUI",
executables = executables
)
after running
python setup.py build
in the cmd from the position of
C:\Users\Us.Er\Pyth-examples\Qt\UI-examples\ChannelplotGUI-to-exe
I have something like this:
running build
running build_exe
copying c:\users\Us.Er\appdata\local\enthought\canopy\user\lib\site-
packages\cx_Freeze\bases\Win32GUI.exe -> build\exe.win-amd64-2.7\main.exe
copying
c:\users\Us.Er\appdata\local\enthought\canopy\user\scripts\python27.dll ->
build\exe.win-amd64-2.7\python27.dll
Traceback (most recent call last):
File "setup.py", line 23, in <module>
executables = executables
File "c:\users\Us.Er\appdata\local\enthought\canopy\user\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
distutils.core.setup(**attrs)
File "C:\Users\Us.Er\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.7.4.3348.win-x86_64\lib\distutils\core.py", line 151, in setup
dist.run_commands()
File "C:\Users\Us.Er\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.7.4.3348.win-x86_64\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "C:\Users\Us.Er\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.7.4.3348.win-x86_64\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Users\Us.Er\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.7.4.3348.win-x86_64\lib\distutils\command\build.py", line 127, in run
self.run_command(cmd_name)
File "C:\Users\Us.Er\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.7.4.3348.win-x86_64\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "C:\Users\Us.Er\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.7.4.3348.win-x86_64\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "c:\users\Us.Er\appdata\local\enthought\canopy\user\lib\site-packages\cx_Freeze\dist.py", line 219, in run
freezer.Freeze()
File "c:\users\Us.Er\appdata\local\enthought\canopy\user\lib\site-packages\cx_Freeze\freezer.py", line 626, in Freeze
self._FreezeExecutable(executable)
File "c:\users\Us.Er\appdata\local\enthought\canopy\user\lib\site-packages\cx_Freeze\freezer.py", line 232, in _FreezeExecutable
self._AddVersionResource(exe)
File "c:\users\Us.Er\appdata\local\enthought\canopy\user\lib\site-packages\cx_Freeze\freezer.py", line 172, in _AddVersionResource
stamp(fileName, versionInfo)
File "c:\users\Us.Er\appdata\local\enthought\canopy\user\lib\site-packages\win32\lib\win32verstamp.py", line 159, in stamp
h = BeginUpdateResource(pathname, 0)
pywintypes.error: (2, 'BeginUpdateResource', 'The system cannot find the file specified.')
What is the possible solution for above problem?
EDIT
To be clear: I don't want to add any icon for now. I am happy with just a simple, working .exe
I have added the target in this way:
executables = [cx_Freeze.Executable(script = "main.py", base = base, targetName="main.exe")]
I have tried to add
targetDir = "C:\Users\Us.Er\Pyth-examples\Qt\UI-examples\ChannelplotGUI-to-exe"
anyway, the return is:
TypeError: __init__() got an unexpected keyword argument 'targetDir'
The main problem is as before - the error with last lines as:
h = BeginUpdateResource(pathname, 0)
pywintypes.error: (2, 'BeginUpdateResource', 'The system cannot find the file specified.')
In my case the issue was solved by changing
'build_exe': 'build_folder'
to
'build_exe': './/build_folder'
This is because open(pathname) would work on the pathname='build_folder\\executable.exe', allowing the code to advance during the check at the begginning of the stamp method, but BeginUpdateResource(pathname, 0) would only work on './/build_folder\\executable.exe'
Solution
options = {
'build_exe': {
'build_exe': './/build'
}
}
Note: .//build here, build is the folder name where you want to build your project.
Thanks to help of user jpeg I managed to successfully freeze the script.
To eliminate the problem with path I have added a line print(pathname) in win32verstamp.py before line 159.
The print statement worked fine showing the relative path to the newly made .exe file.
Despite showing the correct path, the error was still present. I went to the stamp() definition in win32verstamp.py and found a try - except block, and have inserted print(pathname) over there.
The part is:
def stamp(pathname, options):
# For some reason, the API functions report success if the file is open
# but doesnt work! Try and open the file for writing, just to see if it is
# likely the stamp will work!
#print("Current path is " + pathname)
try:
f = open(pathname, "a+b")
f.close()
print("Possible to open" + pathname) #<---line added
except IOError, why:
print "WARNING: File %s could not be opened - %s" % (pathname, why)r code here
....
Since that the freeze was possible. (Not sure why tho, I'm happy to add some info if explanation is known)
I had the same issue tying to freeze my PyQt5 app (using python 3.7 under windows 10) with the following message :
h = BeginUpdateResource(pathname, 0)
pywintypes.error: (2, 'BeginUpdateResource', 'Le fichier spécifié est introuvable.')
So I choose to use cx_freeze Sample provided as a first step.
(This samples are availables after cx_freeze installation under MyVENVpath\Lib\site-packages\cx_Freeze\samples)
The very basic PyQt5 exemple was working, but my case was way more complex as I used several sub Python class I have developed.
I honestly don't really understand why but I was able to make it work So here is all modifications I have performed :
In setup.py identify sub python files
add my personnal packages and class like this :
include = ["PyQt5", "PySerial", "myclass1", "myclass2", "myclass3", "PandasModel"]
packages = ["PySerial", "myclass1", "myclass2", "myclass3", "PandasModel", "pandas","math"]
Use relative path in setup.py
executables = [cx_Freeze.Executable(os.getcwd() + r'\..\..\MyFileName.py', base=base)]
include_files = [(os.getcwd() + r'\..\..\CalibrationTool.ui', r'Inputs\GUI\CalibrationTool.ui')
The reason for "...." is to jump two directories higher level, as my python.exe is in sub folders VENV\Script\
Add python Files containing "Myclass1" at same level as setup.py.
Even if in my application, class files are in a subfolder Input\Packages\Myclass1File.py, I had to copy-paste it at the same level as setup.py. This way the include and package line of setup.py work and was able to generate the executable.
Last but not least,the terminal command
I have no idea why but the only command who did suceed was:
to use full path to the python.exe and full path to the setup.py with the "build" at the end.
cmd:>C:\Folder1\Folder2\MyVENV\Scripts\python.exe D:\Folder1\Folder2\setup.py build
This finaly created the executable in a build folder under C:\Folder1\Folder2\MyVENV\Scripts\

maya python subprocess error

in python 2.7 i try this code to get data from Deadline software. Its return some data from server...
import subprocess
path = 'C:/Program Files/Thinkbox/Deadline7/bin/'
p1 = subprocess.Popen([path + 'deadlinecommand.exe', 'pools'], stdout=subprocess.PIPE)
p1.communicate()
and see result:
('none\r\npool_01\r\npool_02\r\npool_03\r\npool_04\r\npool_05\r\npoolhalf\r\n', None)
but when i copy that code to python in maya 2014 i get error:
p1 = subprocess.Popen(['path + 'deadlinecommand.exe', 'pools'], stdout=subprocess.PIPE)
# Error: WindowsError: file C:\PROGRA~1\Autodesk\maya2014\bin\python27.zip\subprocess.py line 826: 6 #
run this exe file - is the only option dedline communication. but it pays to stdout data and how it is necessary to pull out. subprocess options except I have not found, but if there are other options will be glad to try them
anyone else encountered this problem? strange that in pure Python 2.7 running in windows all works, and there is no Maya 2014
i use:
Windows 7 + Python 2.7.9
Maya 2014 (Python 2.7.3)
I was just trying something similar couple of days back, connecting to Deadline via the command line submitter and getting
# File "C:\Program Files\Autodesk\Maya2013\bin\python26.zip\subprocess.py", line 786, in _make_inheritable
# WindowsError: [Error 6] The handle is invalid
error in Maya 2013.5. One workaround found here which does fix this issue is to pipe all the handles
p1 = subprocess.Popen([path + 'deadlinecommand.exe', 'pools'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
Hope it helps.

Creating a single executable .exe from Python script that uses PuLP

I have been struggling with this for a while. I have used py2exe and cx_freeze to package everything. I am using a 32 bit machine and Everything works fine and the interface opens up and everything just that I know the entire puLP package is not being copied correctly into the package. I know this because the solver does not work. Inside both library zips in the packages created by py2exe and cx_freeze, there are only .pyc files included where PuLP has cbc.exe and other file types that make the solver work.
Is there any work around this? I have tried copying the actual PuLP package into the library.zip as well as into the dist folder and that didn't work.
Here is the setup I used for py2exe:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["pulp"],
"icon": "icon.ico",
"include_files": ["icon.ico","cbc.exe","cbc-32","cbc-64","cbc-osx-64","CoinMP.dll"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "my_app",
version = "0.1",
options = {"build_exe": build_exe_options},
executables = [Executable("my_app.py", base=base)])
I received the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "Tkinter.pyc", line 1470, in __call__
File "my_app.py", line 796, in <lambda>
File "my_app.py", line 467, in branchAndBound
File "pulp\pulp.pyc", line 1619, in solve
AttributeError: 'NoneType' object has no attribute 'actualSolve'
EDIT
I tried to change the paths to cbc.exe and CoinMP.dll but that didn't really work either. I am probably missing something.
I changed the following inside solvers.py in the PuLP package:
try:
coinMP_path = config.get("locations", "CoinMPPath").split(', ')
except configparser.Error:
coinMP_path = ['/Users/al/Desktop/my_app/build/exe.win32-2.7']
try:
cbc_path = config.get("locations", "CbcPath")
except configparser.Error:
cbc_path = '/Users/al/Desktop/my_app/build/exe.win32-2.7'
try:
pulp_cbc_path = config.get("locations", "PulpCbcPath")
except configparser.Error:
pulp_cbc_path = '/Users/al/Desktop/my_app/build/exe.win32-2.7'
What am I missing or doing wrong?

Installing NodeboxOpenGL on windows

Hello I am trying to install and make use of NodeboxOpenGL, the python library so I can create my own graphs with nodes and edges. But I am running into some trouble,
starting off at NodeBox OpenGL site. I downloaded NodeBox for OpenGL and then pyglet, I then did easy_install nodebox-opengl.
Note I did not do pip install
I installed pyglet from pyglet. So now I am thinking its all ready to go. I did a quick check of my c:\python27\Lib\site-packages\ location just be sure the nodebox folder was there, all seems good.
I tried the sample program that's on the site
from nodebox.graphics import *
from nodebox.graphics.physics import Flock
flock = Flock(40, 0, 0, 500, 500)
flock.sight = 300
def draw(canvas):
background(1)
fill(0, 0.75)
flock.update(cohesion=0.15)
for boid in flock:
push()
translate(boid.x, boid.y)
scale(0.5 + 1.5 * boid.depth)
rotate(boid.heading)
arrow(0, 0, 15)
pop()
canvas.fps = 30
canvas.size = 600, 400
canvas.run(draw)
tried to run it, but i keep getting this error
Traceback (most recent call last):
File "E:\Workspace\ElasticNodes\graph1.py", line 5, in <module>
from nodebox.graphics import *
File "E:\Workspace\ElasticNodes\nodebox\graphics\__init__.py", line 1, in <module>
import bezier
File "E:\Workspace\ElasticNodes\nodebox\graphics\bezier.py", line 10, in <module>
from context import BezierPath, PathElement, PathError, Point, MOVETO, LINETO, CURVETO, CLOSE
File "E:\Workspace\ElasticNodes\nodebox\graphics\context.py", line 29, in <module>
import geometry
File "E:\Workspace\ElasticNodes\nodebox\graphics\geometry.py", line 454, in <module>
from pyglet.gl import \
ImportError: cannot import name pointer
I tried modifying the python script i.e
In your script, add the location of NodeBox to sys.path, before importing it: >>> MODULE = '/users/tom/python/nodebox' >>> import sys; if MODULE not in sys.path: sys.path.append(MODULE) >>> import nodebox
But still the same error.
I am using Python2.7, running on windows. I am not sure what I am doing wrong. Has anyone got any experience with running this library on windows. What am I doing wrong
Maybe this helps you:
In geometry.py del "pointer" import. Replace pointer(data) to POINTER(data)
I also had another error, so maybe you need add import to "shaders.py": from ctypes import c_uint
I am having a similar problem with Linux. The Nodebox-opengl site ( http://www.cityinabottle.org/nodebox/ ) says that python 2.5 or 2.6 must be used, so it is possible that the problem is that you are using 2.7.
EDIT:
Ok, I installed pyglet first, with pip (and or apt-get, I did both) and I don't get a problem with pyglet. But I still do get other problems.

Call python-nmap PortScanner(), nmap not found

In my virtualenv I installed python-nmap and nmap is installed (OS X).
But if I call mmap like (virtualenv activated...):
import sys
sys.path.append('/usr/local/bin')
import nmap
nm = nmap.PortScanner()
I get the following error:
Raise PortScannerError('nmap program was not found in path')
nmap.nmap.PortScannerError: 'nmap program was not found in path'
Is there still another way to enter the path to nmap?
Portet the project to Python 3 and update nmap to 0.3.3 now it works.
Thanks a lot!
install nmap with homebrew
brew install nmap
Then your install will work correctly.
sys.path governs where the Python interpreter looks for importing modules. The "path" in your error is the OS's PATH environment variable, which tells the OS where to look for Nmap. You can either set this directly with os.putenv or you can pass the full path to the nmap binary in the nmap.PortScanner constructor:
nm = nmap.PortScanner('/usr/local/bin/nmap')
I have tried these methods but not worked then I further looked into it.
Error:
>>> import nmap
>>> nm = nmap.PortScanner()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nmap/nmap.py", line 137, in __init__
raise PortScannerError('nmap program was not found in path')
nmap.nmap.PortScannerError: 'nmap program was not found in path'
so I looked into file "/usr/local/lib/python2.7/dist-packages/nmap/nmap.py". The code where they are checking for nmap is not working for some reason.
code:
# regex used to detect nmap
regex = re.compile('Nmap version [0-9]*\.[0-9]*[^ ]* \( http://nmap\.org \)')
# launch 'nmap -V', we wait after 'Nmap version 5.0 ( http://nmap.org )'
p = subprocess.Popen(['nmap', '-V'], bufsize=10000, stdout=subprocess.PIPE)
self._nmap_last_output = p.communicate()[0] # store stdout
for line in self._nmap_last_output.split('\n'):
if regex.match(line) is not None:
is_nmap_found = True
# Search for version number
regex_version = re.compile('[0-9]+')
regex_subversion = re.compile('\.[0-9]+')
rv = regex_version.search(line)
rsv = regex_subversion.search(line)
if rv is not None and rsv is not None:
# extract version/subversion
self._nmap_version_number = int(line[rv.start():rv.end()])
self._nmap_subversion_number = int(line[rsv.start()+1:rsv.end()])
break
if is_nmap_found == False:
raise PortScannerError('nmap program was not found in path')
I found out that first regex is not working so I changed this:
from :
regex = re.compile('Nmap version [0-9]*\.[0-9]*[^ ]* \( http://nmap\.org \)')
to:
regex = re.compile('Nmap version [0-9]*\.[0-9]*)
Now it is working just like it suppose to work!