CMU-Perceptual-Computing-Lab / openpose

OpenPose: Real-time multi-person keypoint detection library for body, face, hands, and foot estimation
https://cmu-perceptual-computing-lab.github.io/openpose
Other
31.28k stars 7.87k forks source link

OpenPose python example script not working on Ubuntu 18.04 LTS dual booted on Mac #685

Closed moon05 closed 6 years ago

moon05 commented 6 years ago

Issue Summary

Either "_openpose.so" not found or if that is fixed then there's an undefined symbol error. As a result can't even run the example python script.

In openpose.py (location: openpose/python/openpose/openpose.py) I had to change line 16 to the following for it to work:

_libop= np.ctypeslib.load_library('libopenpose','/usr/local/lib/libopenpose.so')

Also I just wanted to include what my PYTHONPATH looks like:

echo $PYTHONPATH /home/abdullah/caffe/python/:/home/abdullah/Desktop/openpose/python/

Executed Command (if any)

python 1_extract_pose.py --logging_level 0 --disable_multi_thread

OpenPose Output (if any)

Traceback (most recent call last): File "1_extract_pose.py", line 6, in from openpose import File "/home/abdullah/Desktop/openpose/python/openpose/init.py", line 1, in from openpose import File "/home/abdullah/Desktop/openpose/python/openpose/openpose.py", line 12, in class OpenPose(object): File "/home/abdullah/Desktop/openpose/python/openpose/openpose.py", line 20, in OpenPose ct.c_int, ct.c_char_p, ct.c_char_p, ct.c_char_p, ct.c_float, ct.c_float, ct.c_int, ct.c_float, ct.c_int, ct.c_bool, ct.c_char_p] File "/usr/lib/python2.7/ctypes/init.py", line 379, in getattr func = self.getitem(name) File "/usr/lib/python2.7/ctypes/init.py", line 384, in getitem func = self._FuncPtr((name_or_ordinal, self)) AttributeError: /usr/local/lib/libopenpose.so: undefined symbol: newOP

Type of Issue

You might select multiple topics, delete the rest:

Your System Configuration

  1. OpenPose version: Latest Github Code

  2. General configuration:

    • Installation mode: CMake (Ubuntu)
    • Operating system (lsb_release -a in Ubuntu): Ubuntu 18.04 LTS
    • Release or Debug mode? (by defualt: release): Release
    • Compiler (gcc --version in Ubuntu or VS version in Windows): 7.3.0 (Ubuntu)
  3. Non-default settings:

    • 3-D Reconstruction module added? (by default: no): No
    • Any other custom CMake configuration with respect to the default version? (by default: no): No
  4. 3rd-party software:

    • Caffe version: 1.0.0 (compiled from source)
    • CMake version (cmake --version in Ubuntu): 3.10.2
    • OpenCV version: 3.4.1 (compiled from source)
  5. If CPU-only mode issue:

    • CPU brand & model: Intel® Core™ i5-5257U CPU @ 2.70GHz × 4
    • Total RAM memory available: 7.7 GiB
soulslicer commented 6 years ago

I think you may have misread our instructions. If you simply wish to test OpenPose Python, you must navigate to the python directory in the Python Build Folder as seen in the instructions (https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/modules/python_module.md)

# From command line
cd build/examples/tutorial_python
python 1_extract_pose.py

If you wish to access the library from another location, you need to add the python folder to your PYTHONPATH. This can be done with adding it to your system path or appending the environmental variable directly. This can be seen in the example code as well

else: sys.path.append('../../python');
# Option b
# If you run `make install` (default path is `/usr/local/python` for Ubuntu), you can also access the OpenPose/python module from there. This will install OpenPose and the python library at your desired installation path. Ensure that this is in your python path in order to use it.
# sys.path.append('/usr/local/python')

In your case, you have installed openpose already to /usr/local/ so you need to add sys.path.append('/usr/local/python') instead of hacking the path of openpose.so directly into the python library. You have linked to the wrong .so library anyway so it can't find the symbol. Your python path is also pointing to the source directory openpose/python instead of openpose/build/python. If this folder is missing, it means you did not enabled BUILD_PYTHON. Please try to take a look at the examples and read the instructions to see how its done.

Lastly, the Python example currently does not allow command line inputs. It was more to serve as an example of what variables can be changed. But we can see how this can be confusing as the C++ code can do this, so we could add this in the future

moon05 commented 6 years ago

Well regardless of the path problem, which probably is my misunderstanding the "undefined symbol" error remains. I simply added the command line inputs just because that was the format to post an issue. Without the command line args I still get the same error. Any solution?

soulslicer commented 6 years ago

Can you navigate to the example python code and run it does it work? We don't officially test it on 18.04 so there may be some unknown errors.

moon05 commented 6 years ago

It doesn't. I was going to start another issue for the Jetson TX2 I am using to do the same, with Tegra-Ubuntu version 16.04.4. But in that installation even after building everything properly and adding the PATH properly, I can't even find the openpose lib (openpose.so) anywhere. In the Jetson installation I am still stuck at the following error:

Traceback (most recent call last): File "test.py", line 18, in from openpose import File "/home/nvidia/openpose/python/openpose/init.py", line 1, in from openpose import File "/home/nvidia/openpose/python/openpose/openpose.py", line 16, in class OpenPose(object): File "/home/nvidia/openpose/python/openpose/openpose.py", line 21, in OpenPose _libop= np.ctypeslib.load_library('_openpose', dir_path+'/_openpose.so') File "/usr/local/lib/python2.7/dist-packages/numpy/ctypeslib.py", line 155, in load_library raise OSError("no file with expected extension") OSError: no file with expected extension

soulslicer commented 6 years ago

It looks like youre navigating to the wrong path. Youre suppose to navigate to the build directory.

Generally alot of libraries do copy the .so file back to the source directory, but we did not want to do this as it would mean making it confusing if you have multiple builds for different versions of compiled openpose.

moon05 commented 6 years ago

Did you mean I would have to go the build directory and execute the example from there? Because I just tried that and I still got the same error. Just to make sure I am following what you are saying here's the error, and see the location I am at:

abdullah@abdullah-MacBookPro:~/Desktop/openpose/build/examples/tutorial_python$ python 1_extract_pose.py Traceback (most recent call last): File "1_extract_pose.py", line 6, in from openpose import File "/home/abdullah/Desktop/openpose/python/openpose/init.py", line 1, in from openpose import File "/home/abdullah/Desktop/openpose/python/openpose/openpose.py", line 12, in class OpenPose(object): File "/home/abdullah/Desktop/openpose/python/openpose/openpose.py", line 20, in OpenPose ct.c_int, ct.c_char_p, ct.c_char_p, ct.c_char_p, ct.c_float, ct.c_float, ct.c_int, ct.c_float, ct.c_int, ct.c_bool, ct.c_char_p] File "/usr/lib/python2.7/ctypes/init.py", line 379, in getattr func = self.getitem(name) File "/usr/lib/python2.7/ctypes/init.py", line 384, in getitem func = self._FuncPtr((name_or_ordinal, self)) AttributeError: /usr/local/lib/libopenpose.so: undefined symbol: newOP

soulslicer commented 6 years ago

Can you navigate to build/python/openpose and tell me if you see a file called _openpose.so

moon05 commented 6 years ago

This is where I can see python dir which is in the src dir inside build. Like the following

~/Desktop/openpose/build/src/openpose$ ls
3d           cmake_install.cmake  filestream  hand                  Makefile  producer  utilities
calibration  core                 gpu         libopenpose.so        net       thread    wrapper
CMakeFiles   face                 gui         libopenpose.so.1.3.0  pose      tracking
abdullah@abdullah-MacBookPro:~/Desktop/openpose/build/src/openpose$ pwd
/home/abdullah/Desktop/openpose/build/src/openpose
abdullah@abdullah-MacBookPro:~/Desktop/openpose/build/src/openpose$ 
moon05 commented 6 years ago

Believe it or not there is no python directory inside build.

abdullah@abdullah-MacBookPro:~/Desktop/openpose/build$ ls
caffe  CMakeCache.txt  cmake_install.cmake    examples              Makefile
cmake  CMakeFiles      cmake_uninstall.cmake  install_manifest.txt  src
abdullah@abdullah-MacBookPro:~/Desktop/openpose/build$ 
soulslicer commented 6 years ago

That is because you have not enabled BUILD_PYTHON perhaps. Have you tried that

moon05 commented 6 years ago

I will do another fresh build right now, to see if that works and if I forgot to enable it! I will update you as soon as I am done! Thanks for such quick replies!

soulslicer commented 6 years ago

No problem. Do consider reading through the build instructions more thoroughly next time, and also let us know if anything is confusing.

moon05 commented 6 years ago

Okay I did a new build with BUILD_PYTHON. _openpose.so exists:

abdullah@abdullah-MacBookPro:~/Desktop/openpose/build/python/openpose$ ls
CMakeFiles           __init__.py  openpose.py
cmake_install.cmake  Makefile     _openpose.so
abdullah@abdullah-MacBookPro:~/Desktop/openpose/build/python/openpose$ 

I am still getting the error:

abdullah@abdullah-MacBookPro:~/Desktop/openpose/build/examples/tutorial_python$ python 1_extract_pose.py 
Traceback (most recent call last):
  File "1_extract_pose.py", line 6, in <module>
    from openpose import *
  File "/home/abdullah/Desktop/openpose/python/openpose/__init__.py", line 1, in <module>
    from openpose import *
  File "/home/abdullah/Desktop/openpose/python/openpose/openpose.py", line 12, in <module>
    class OpenPose(object):
  File "/home/abdullah/Desktop/openpose/python/openpose/openpose.py", line 20, in OpenPose
    ct.c_int, ct.c_char_p, ct.c_char_p, ct.c_char_p, ct.c_float, ct.c_float, ct.c_int, ct.c_float, ct.c_int, ct.c_bool, ct.c_char_p]
  File "/usr/lib/python2.7/ctypes/__init__.py", line 379, in __getattr__
    func = self.__getitem__(name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 384, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /usr/local/lib/libopenpose.so: undefined symbol: newOP
moon05 commented 6 years ago

Am I missing something here? Or just clearly not understanding some plain instruction?

soulslicer commented 6 years ago

I am not sure why your code is linking to the src directory again. "python/openpose/init.py"

The Python API must link to the build directory and it does. I think you may have made some modifications to either the code or your environment variables. I would suggest a clean install with wiping of your environmental variables etc.

moon05 commented 6 years ago

Finally got it to work. @soulslicer you were probably saying this the whole time but I didn't quite get it. Anyhow this is the path I included in my $PYTHONPATH and it worked : /home/nvidia/caffe/python:/home/nvidia/openpose/build/python/:

Also, if anyone else faces this just a summary:

  1. Check BUILD_PYTHON while doing the build
  2. Make sure PYTHONPATH is similar to what it is above, if this is how you installed it
  3. Don't forget to do sudo make install after the building is done, that does the linking

Finally run it from here: ~/Desktop/openpose/build/example/tutorial_python

soulslicer commented 6 years ago

It is not required to do sudo make install. You simply need to set your PYTHONPATH accordingly as per the instruction and the examples provided.

moon05 commented 6 years ago

Oh alright! Nonetheless, hopefully I didn't create unnecessary chain of comments!

JasOlean commented 5 years ago

I followed the instructions. But I got the same error like this:

Traceback (most recent call last): File "test.py", line 8, in from openpose import openpose as op File "/usr/local/python/openpose/openpose.py", line 17, in class OpenPose(object): File "/usr/local/python/openpose/openpose.py", line 46, in OpenPose np.ctypeslib.ndpointer(dtype=np.int32), np.ctypeslib.ndpointer(dtype=np.uint8), ct.c_bool] File "/usr/lib/python2.7/ctypes/init.py", line 375, in getattr func = self.getitem(name) File "/usr/lib/python2.7/ctypes/init.py", line 380, in getitem func = self._FuncPtr((name_or_ordinal, self)) AttributeError: /usr/local/python/openpose/_openpose.so: undefined symbol: forward_hands