Openpose: Python API error: Cannot import name pyopenpose

Created on 17 Jan 2019  ·  35Comments  ·  Source: CMU-Perceptual-Computing-Lab/openpose

When I execute the python API sample code in build folder ( 1_body_from_image.py ), the terminal return back the following errors. I also noticed that the python API have been changed during the past month. I am using ubuntu 16.04. cuda 8.0 with cudnn 5.1. The openpose is current version. Any suggestions?

Thanks!

from openpose import pyopenpose
Traceback (most recent call last):
File "", line 1, in
File "/home/jack/Documents/computervision/openpose/build/python/openpose/__init__.py", line 1, in
from . import pyopenpose as pyopenpose
ImportError: cannot import name pyopenpose

Python read posting rules...

Most helpful comment

My environment - UBUNTU 18.04, CUDA 9.2, CUDNN 7.2.1
Openpose current version 1.4 (Jan 2019)

I did the following to get it to work

a. After a successful build, go look for the file - build/python/openpose/pyopenpose.cpython-36m-x86_64-linux-gnu.so and copy to /usr/local/lib/python3.6/dist-packages

b. in /usr/local/lib/python3.6/dist-packages I create a symbolic link - sudo ln -s pyopenpose.cpython-36m-x86_64-linux-gnu.so pyopenpose

c. Verify that your LD_LIBRARY_PATH from env has the entry /usr/local/lib/python3.6/dist-packages

d. Now, go to build/examples/tutorial_api_python and do some modification to 1_body_from_image.py

i) look for the line from openpose import pyopenpose as op and change to import pyopenpose as op

ii) Under custom parameters, I modify the following to reduce net_resolution (otherwise I hit a CUDA out of memory error ) and modify the model_folder to where I store the models

params = dict()
params["model_folder"] = "/home/XXXXX/openpose/models/"
params["net_resolution"] = "160x80"

go to your examples/tutorial_api_python and execute ./1_body_from_image.py

h1

This version of Python Wrapper is indeed faster !

All 35 comments

My environment - UBUNTU 18.04, CUDA 9.2, CUDNN 7.2.1
Openpose current version 1.4 (Jan 2019)

I did the following to get it to work

a. After a successful build, go look for the file - build/python/openpose/pyopenpose.cpython-36m-x86_64-linux-gnu.so and copy to /usr/local/lib/python3.6/dist-packages

b. in /usr/local/lib/python3.6/dist-packages I create a symbolic link - sudo ln -s pyopenpose.cpython-36m-x86_64-linux-gnu.so pyopenpose

c. Verify that your LD_LIBRARY_PATH from env has the entry /usr/local/lib/python3.6/dist-packages

d. Now, go to build/examples/tutorial_api_python and do some modification to 1_body_from_image.py

i) look for the line from openpose import pyopenpose as op and change to import pyopenpose as op

ii) Under custom parameters, I modify the following to reduce net_resolution (otherwise I hit a CUDA out of memory error ) and modify the model_folder to where I store the models

params = dict()
params["model_folder"] = "/home/XXXXX/openpose/models/"
params["net_resolution"] = "160x80"

go to your examples/tutorial_api_python and execute ./1_body_from_image.py

h1

This version of Python Wrapper is indeed faster !

I met the same issuse as you in Windows10!!! After configure in CMake with PYTHON_BUILD flag , I found diffculty in Python . When try to run the demo , i got as follows:
ImportError: No module named 'pyopenpose'

Make sure you are building with the correct python version or using the python version you built for. For me the problem was that python %example_file.py% was calling python 2.7 when I had built for python 3.5 (Which is only executed if I run python3 %example_file.py%)

@StrongRay Could you tell me which openpose version you are using? I trace back and found out that the python API was ok before 01/10/2019( commit fc6d35998da5d2153fc0705f9ee74dd6fd4931cd). I can run 1_body_from_image.py. But for the current repository ( 01/16/2019 ), it seems that they changed several things. Not sure this is the reason to get broken. Could you check your tutorial_api_python folder under build foder and see whether you have the below two python code?
(2_whole_body_from_image, 3_heatmaps_from_image ). If you only have 1_body_from_image.py, then this is older python API version which can run well. If not, let me know which commit you use and I am gonna try it.

@wardenjohn I believe "ImportError: No module name 'pyopenpose' " is the path setting issues while 'ImportError: cannot import name pyopenpose' is due to other issues. One way you can do is hard coding like this "sys.path.append('/home/(your openpose folder)/openpose/build/python')" in you python script to help the python interpreter find out the pyopenpose.

@ccjack Please, use the latest version as we have fixed several Python bugs in these last few commits, and also re-copy all Python scripts from the current OpenPose github.

OpenPose v1.5 should be release within 1 month adding this Python version (including the Windows binaries) after it is error-proved.

@gineshidalgo99 Thanks for prompt response!! I still met the issue regarding the import error ( raise e ImportError: cannot import name pyopenpose.) in the newest version ( commit ce6338f8a6694396990f77c19bbc3d003b12f9b9 ). Then, I will wait a month for v1.4 to be launched and use it for further python application purposes. Thanks!

Can you do a clean removal of openpose and clone again? This seems typical of that kind of error.

@ccjack I have cloned the latest version yesterday so it has the latest codes and so the tutorial_api_python directory has 2_ and 3_ python examples.

@StrongRay Thanks for your info. I think I knew what's going on in my setting. I am using python2 as my application cannot run python3. I am trying to enable "PYTHON_EXECUTABLE" and "PYTHON_LIBRAR" in cmake files, but I don't know where will be the right place to set these flags. I am modifying CMakeLists.txt file in openpose/3rdparty/pybind11, but no lucks. I also tried cmake -DPYTHON_EXECUTABLE=/usr/bin/python2.7 -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so ../ in build folder and it returns

Manually-specified variables were not used by the project:
PYTHON_EXECUTABLE
PYTHON_LIBRARY

New update. Finally, I am able to compile the python API for python2. After hitting " cmake -DPYTHON_EXECUTABLE=/usr/bin/python2.7 -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so ../ " twice or three times until no warning saying "Manually-specified variables were not used by the project:" , then I compiled the code. After that, I can import openpose library and run the sample python scripts without problems. Thanks for everyone's help and time!

Sorry, we updated the instructions so things can be made clearer. Thanks for your help

Please, follow the updated doc for the PyOpenPose wrapper (that has been updated today) and post a new GitHub with any new issue that could appear (but adding all the hardware configuration as the GitHub issue template states...).

System configuration: Windows 10, CPU only

I also have the error 'no module named 'pyopenpose'', when I attempt to run the file 1_body_from_image.py from the build/examples/tutorial_api_python/ folder. (I have upated to the latest version of the OpenPose library.)

I have enabled BUILD_PYTHON in CMake and compiled the library in Visual Studio. However, I do not have the the folder build/python/openpose/release nor the files pyopenpose.cp36-win_amd64.pyd or pyopenpose.pyd. Is there a specific project file/solution that I need to compile in release mode in Visual Studio that will build Python for Openpose?

Additionally, does Windows require python-dev to be installed, to use the Python API?

Thank you

Please follow all the steps under the Common Issues section for Windows:

https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/modules/python_module.md#exporting-python-openpose

Did you explicitly select Release in Visual Studio, you probably missed that

Anyway hopefully soon we will release some binaries for Python so you need not compile it

Hi, thanks for the quick reply.

I have compiled the the Visual Studio solution file OpenPose.sln in release mode. But, this does not produce the file location build/python/openpose/release nor pyopenpose.cp36-win_amd64.pyd nor pyopenpose.pyd.

The instructions say 'Python for Openpose needs to be compiled in Release mode'. What file do I need to open and compile in VS to follow this step?

Can you tell me the contents you have in

build/python/openpose

The contents of buildpythonopenpose is:

buildpythonopenposeCMakeFiles
buildpythonopenposecmake_install.cmake
buildpythonopenposepyopenpose.vcxproj
buildpythonopenposepyopenpose.vcxproj.filters
buildpythonopenpose__init__.py
buildpythonopenposeCMakeFilesgenerate.stamp
buildpythonopenposeCMakeFilesgenerate.stamp.depend

it seems it was not compiled. you might have had compile errors, can you check that pyopenpose was actually compiled successfully? You can copy your build log to pastebin and I can take a look

These are only the Cmake logs, I need the build logs from within Visual studio as well

Thank you so much for the help, I really appreciate it!

I have now managed to successfully run the Python API tutorials. Even though I had built the solution, I also needed to separately build pyopenpose in Visual Studio. This option is located under the Build tab in the VS menu bar.

If you click Build Solution, it should build everything

It is very strange that I can run the 1_body_from_image.py , but when I run 6_face_from_image.py or other python file , it raised such error:
Error: OpenPose library could not be found. Did you enable BUILD_PYTHON in CMake and have this Python script in the right folder?
import pyopenpose as op
ImportError: No module named 'pyopenpose'

But I do can run 1_body_from_image and got the output picture!

It is very strange that I can run the 1_body_from_image.py , but when I run 6_face_from_image.py or other python file , it raised such error:
Error: OpenPose library could not be found. Did you enable BUILD_PYTHON in CMake and have this Python script in the right folder?
import pyopenpose as op
ImportError: No module named 'pyopenpose'

But I do can run 1_body_from_image and got the output picture!

I also have this question, and I can not solve it. Do you solve it now?

My environment - UBUNTU 18.04, CUDA 9.2, CUDNN 7.2.1
Openpose current version 1.4 (Jan 2019)

I did the following to get it to work

a. After a successful build, go look for the file - build/python/openpose/pyopenpose.cpython-36m-x86_64-linux-gnu.so and copy to /usr/local/lib/python3.6/dist-packages

b. in /usr/local/lib/python3.6/dist-packages I create a symbolic link - sudo ln -s pyopenpose.cpython-36m-x86_64-linux-gnu.so pyopenpose

c. Verify that your LD_LIBRARY_PATH from env has the entry /usr/local/lib/python3.6/dist-packages

d. Now, go to build/examples/tutorial_api_python and do some modification to 1_body_from_image.py

i) look for the line from openpose import pyopenpose as op and change to import pyopenpose as op

ii) Under custom parameters, I modify the following to reduce net_resolution (otherwise I hit a CUDA out of memory error ) and modify the model_folder to where I store the models

params = dict()
params["model_folder"] = "/home/XXXXX/openpose/models/"
params["net_resolution"] = "160x80"

go to your examples/tutorial_api_python and execute ./1_body_from_image.py

h1

This version of Python Wrapper is indeed faster !

In case someone else faces the same problem, I had to link to pyopenpose.so instead of just pyopenpose. Like this:

ln -s ./openpose/build/python/openpose/pyopenpose.cpython-36m-x86_64-linux-gnu.so ./openpose/build/python/openpose/pyopenpose.so

It seems everyone is having problems because Ubuntu by default uses Python 2, but Python 3 is what we recommend

JUST run make install in /openpose/build/python/openpose.

It seems everyone is having problems because Ubuntu by default uses Python 2, but Python 3 is what we recommend

For me the issue was incompatabile opencv and openpose python versions.
The compiled openpose version was for python 3.7 and my opencv was 3.5

Only figured that out by looking at the cpython naming scheme. 37m is the python version nr. pyopenpose.cpython-37m-x86_64-linux-gnu.so
Cmake compilation flag PYBIND11_PYTHON_VERSION seems to ignore minor versions as I set it to 3.5.

When I launched with the alias python3.7 it could import openpose but not opencv.
Fixed it by creating a virtualenvironment in which I installed a 3.7 opencv version through pip.

The raised exception is a bit dubious
except ImportError as e: print('Error: OpenPose library could not be found. Did you enable BUILD_PYTHON in CMake and have this Python script in the right folder?')

JUST run make install in /openpose/build/python/openpose.

This worked for me. Thank you.

It seems everyone is having problems because Ubuntu by default uses Python 2, but Python 3 is what we recommend

For me the issue was incompatabile opencv and openpose python versions.
The compiled openpose version was for python 3.7 and my opencv was 3.5

Only figured that out by looking at the cpython naming scheme. 37m is the python version nr. pyopenpose.cpython-37m-x86_64-linux-gnu.so
Cmake compilation flag PYBIND11_PYTHON_VERSION seems to ignore minor versions as I set it to 3.5.

When I launched with the alias python3.7 it could import openpose but not opencv.
Fixed it by creating a virtualenvironment in which I installed a 3.7 opencv version through pip.

The raised exception is a bit dubious
except ImportError as e: print('Error: OpenPose library could not be found. Did you enable BUILD_PYTHON in CMake and have this Python script in the right folder?')

Same issue here. Except mine was Numpy. Fixed by creating a brand new environment with python 3.7 installed , and reinstalling numpy and opencv

JUST run make install in /openpose/build/python/openpose.

I don't have /openpose/build/python/openpose directory. What does that mean? This was not build for python?

I built openpose successfully but the build folder doesn't contain python. I am not sure what should I do now.

Thank you so much for the help, I really appreciate it!

I have now managed to successfully run the Python API tutorials. Even though I had built the solution, I also needed to separately build pyopenpose in Visual Studio. This option is located under the Build tab in the VS menu bar.
Hi there,
I met the same problem, how did you fix the problem?? I also build it with release mode but I didn't get the pyopenpose.cp36-win_amd64.pyd nor pyopenpose.pyd. Could you please help me to sort it out? thank you so much

When I 'sudo make install' I got this errors...

/usr/bin/ld: ../../src/openpose/libopenpose.a(cvMatToOpInput.cpp.o): relocation R_X86_64_PC32 against symbol `_ZTVN2op14CvMatToOpInputE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
python/openpose/CMakeFiles/pyopenpose.dir/build.make:149: recipe for target 'python/openpose/pyopenpose.cpython-36m-x86_64-linux-gnu.so' failed
make[2]: * [python/openpose/pyopenpose.cpython-36m-x86_64-linux-gnu.so] Error 1
CMakeFiles/Makefile2:1930: recipe for target 'python/openpose/CMakeFiles/pyopenpose.dir/all' failed
make[1]:
[python/openpose/CMakeFiles/pyopenpose.dir/all] Error 2
Makefile:146: recipe for target 'all' failed
make: *
* [all] Error 2

how can I get a success??

我也是類似情況,也已經解決了

我得到的訊息是:

OpenPose library could not be found. Did you enable BUILD_PYTHON in CMake and have this Python script in the right folder?

我的解決方法是:

  1. 將 OpenPose.sln 用VS開啟
  2. 點"建置(B) -> 重建pyopenpose(E)"

就能在"build / python / openpose"產生出"release"資料夾及底下的文件 如:pyopenpose.cp36-win_amd64.pyd
接著回到python的檔案並執行,即可成功

envs : win10 +annaconda + cuda 10.2

Error: OpenPose library could not be found. Did you enable BUILD_PYTHON in CMake and have this Python script in the right folder?
No module named 'pyopenpose'

The contents of buildpythonopenpose is:
2020/08/05 16:12

CMakeFiles
2020/08/05 16:12 2,273 cmake_install.cmake
2020/08/05 16:16 Debug
2020/08/05 17:19 7,425 INSTALL.vcxproj
2020/08/05 16:12 531 INSTALL.vcxproj.filters
2020/08/05 17:23 pyopenpose.dir
2020/08/06 08:33 14,927 pyopenpose.vcxproj
2020/08/05 16:12 496 pyopenpose.vcxproj.filters
2020/08/05 17:33 168 pyopenpose.vcxproj.user
2020/08/10 09:44 Release
2020/08/05 16:09 40 __init__.py
2020/08/07 09:56 __pycache__

and I'm sure I have the following files in my directory:
pythonopenposeRelease
2020/08/10 09:45 334,848 pyopenpose.cp37-win_amd64.pyd
2020/08/10 09:44 21,021 pyopenpose.exp
2020/08/10 09:44 27,520 pyopenpose.lib

../../bin/OpenPoseDemo.exe run success
how can I get a success??

Was this page helpful?
0 / 5 - 0 ratings