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

Install python wrapper on MacOS #6402

Closed
ysiegel29 opened this issue May 16, 2020 · 30 comments
Closed

Install python wrapper on MacOS #6402

ysiegel29 opened this issue May 16, 2020 · 30 comments

Comments

@ysiegel29
Copy link

Hello,
I am a beginner and would like to test the D435 on my mac using python wrapper.
I have literally spent 3 full hours on trying I think all possible options, following previous post suggestions etc.
I need help if possible...

Where I am is that pyrealsense2 cannot install with pip install pyrealsense2
I get this error:
ERROR: Could not find a version that satisfies the requirement pyrealsense2 (from versions: none)
ERROR: No matching distribution found for pyrealsense2
I am using python 3.7

Can someone help me?
Thank you!

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented May 16, 2020

@dorodnic the RealSense SDK Manager said in April 2020 that installing pyrealsense2 on MacOS with pip install pyrealsense2 should now be possible with Python 3.7.

#6246 (comment)

Did you obtain the PyPi package for Pyrealsense2 before running the pip install pyrealsense2 instruction to install the package, please?

https://pypi.org/project/pyrealsense2/

It is also possible to build the wrapper from source, which I believe Python 3.8 users should do for now.

https://github.com/IntelRealSense/librealsense/tree/master/wrappers/python#building-from-source

@ysiegel29
Copy link
Author

thanks a lot for your answer.
Actually I thought a build existed reading some post but there are no file for Mac in https://pypi.org/project/pyrealsense2/ unless I am mistaken.

fyi since then I have it seems been able to build the wrapper with make following those steps #5275

but I still can't import pyrealsense2, even if the .so files are in the project folder... not sure why
Any idea?
Thanks,

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented May 16, 2020

I admit that it can be a slightly awkward process for someone who is new to PyPi. I have never used Python installation myself yet or done a Pyrealsense2 installation (this is something I still need to learn), and as far as I knew, using the instruction pip install pyrealsense2 should have been sufficient to launch the installation process.

So as a Pyrealsense2 installation newbie myself (I apologise in advance for any mistakes borne from gaps in my knowledge), the instructions preceding pip install pyrealsense2 can be a bit confusing, as it implies that there are preceding commands to input and files to manually download before you enter the pip instruction.

image

The PyPi package installation instructions at the official Python website also give the impression that the finding and downloading of the files is automated once a pip instruction for a recognised program package is received.

If a suitable wheel file (.whl) cannot be found then it automatically builds one locally (on the user's computer?) and caches it for future use. So that is perhaps how Mac wheels are generated for Pyrealsense2 if one is not present on the Pyrealsense2 PyPi file download page (this is just my speculation though rather than certain knowledge).

Once Pyrealsense2 is installed by some means (whether PyPi or compilation from source) then some kind of simple test script can be run to test that Pyrealsense2 can be imported into an application.

When Pyrealsense2 was first launched, a simple test script was provided:

image

Sorry again for any further confusion that my explanation above may create! I literally have a learn Python reference book that I was due to start reading today :)

@ysiegel29
Copy link
Author

thanks!

but what does "We provide a PyPI distribution which is created from this folder by running python setup.py bdist_wheel." mean? I need to clone the repository to do that? or can I run it from terminal?

Thanks again!

@MartyG-RealSense
Copy link
Collaborator

This is again speculation, but at the base of the file list on the front page of the Python wrapper there is a file called setup.py. It sounds to me that it is just a technical explanation of how the wheel package files on the Pyrealsense2 PyPi download page are generated, rather than a step that the user has to carry out themselves.

image

@ysiegel29
Copy link
Author

Thanks again. The setup.py (I managed to execute it) import the pyrealsense2... so it failed. Must be something else. Really painful to loose so much time with these steps...

@MartyG-RealSense
Copy link
Collaborator

The references that I checked suggested that simply inputting import pyrealsense2 as rs should be enough to check if the installation is okay, and that if there are not errors then assume that the installation is fine.

@ysiegel29
Copy link
Author

I think there something wrong with where the built library are located

@MartyG-RealSense
Copy link
Collaborator

You used this guide to install with CMake, yes?

#5275 (comment)

@ysiegel29
Copy link
Author

Yes

@MartyG-RealSense
Copy link
Collaborator

  1. After having done sudo make install in the build directory, did you change directory:

cd wrapper & cd python

  1. Once you had changed directory to the python folder, do you see some .so files?

  2. If you do, copy these files and paste them into the root directory of your project where you run the import instruction

  3. Run the import instruction.

import pyrealsense2

@ysiegel29
Copy link
Author

yes did that, my project folder has the following files:
image

also tried " alternative to steps 6 and 7, export PYTHONPATH=$PYTHONPATH:/usr/local/lib"

May be my build is not working so I tried again using the steps in https://github.com/IntelRealSense/librealsense/tree/master/wrappers/python, ie python setup.py bdist_wheel

but this setup script requires pyrealsense2... so I obviously get "ImportError: No module named pyrealsense2".

fyi I can access the viewer from terminal.

Can someone who managed to make it work help?

@ysiegel29
Copy link
Author

fyi also tried to redo everything using this steps:
https://github.com/GitwellAnyohub/Real_Sensible_Moseq/blob/master/bash_and_install/install_realsense_sdk_mac_os.sh

but get permission issue when doing make install msg is:

CMake Error at cmake_install.cmake:64 (file):
  file INSTALL cannot set permissions on "/usr/local/include/librealsense2":
  Operation not permitted.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented May 17, 2020

I went through the entire process again from the beginning on my Windows PC for using pip install pyrealsense2 to try to get Pyrealsense2 installed for the first time by that method and learn some lessons that I could pass onto you. I managed to fill in the gaps in the instructions through experimentation and write my own little manual for the installation process.

The first lesson was that the pip program has to be manually installed on your computer in order to be able to use pip install with Python. The most popular way to do so is to download to your computer a script file called get-pip.py. There are a range of sources for this file, such as the link below:

https://pip.pypa.io/en/stable/installation/

Find a get-pip.py link on the browser page, right-click on it and select the Save Target As, or Save Link As, or whatever menu option there is for saving a link. Save it to a location on your computer.

image

An alternative way to get the file on MacOS is apparently to use this command in the Terminal:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

At this point, the installation instructions for Windows and Mac may differ, but I will try to provide guidance.

On MacOS in the Terminal, run this command to run the get-pip.py installation script and install pip (the assumption is that Python is already installed):

python get-pip.py

For Windows the process is a bit more complicated, so if you successfully get pip installed as easily as that on MacOS then I am pleased for you :)

At this point you could try entering pip install pyrealsense2 into the Terminal to see whether it responds and installs pyrealsense.

On Windows I found that for the command to work once pip was successfully installed, I had to actually change directory to the folder where pip was installed. On my Python 3.7 setup, this was Python > Python37 > Scripts.

I changed to this folder in my Windows Command Prompt (the equivalent of MacOS' Terminal) and input pip first to test that pip was working by causing it to generate a long list of help instructions. Then I input pip install pyrealsense2 whilst in the Scripts folder and pyrealsense2 installed.

I hope some of the advice above is helpful to you.

@ysiegel29
Copy link
Author

ysiegel29 commented May 17, 2020

Thanks! unfortunately the issue is not pip for me, I have it and use it regularly however the pip install pyrealsense2 does not work even when launch from the directory mentioned in the guide (different for macOS it seems).

@MartyG-RealSense
Copy link
Collaborator

If you are still experiencing the error "Could not find a version that satisfies the requirement pyrealsense2", this suggests that pip cannot find a Python version compatible with the Pyrealsense2 package on your MacOS computer when you launch the pip install pyrealsense2 from the same directory that pip is installed in.

It installs successfully with pip on Python 3.7 with Windows. I'll check with Dorodnic about the earlier statement about MacOS pip compatibility.

@dorodnic When you mentioned in #6246 (comment) that pip install pyrealsense2 should work on Python 3.7 in the discussion about pip install on Mac, can you confirm whether this includes MacOS please?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented May 30, 2020

Dorodnic provided further details that if a computer has an Arm type processor then a suitable pip package is not available and pyrealsense2 should be compiled from source code instead. Do you know what type of processor your Mac computer model has, please?

@MartyG-RealSense
Copy link
Collaborator

@ysiegel29 Do you require further assistance with this case please, or can it be closed? Thanks!

@cxbrooks
Copy link

Here's what worked for me under macOS 10.14.4 (Mojave) with /usr/bin/python 2.7.10:

git clone https://github.com/IntelRealSense/librealsense
brew install cmake libusb pkg-config
cd librealsense
mkdir build
cd build
cmake .. -DBUILD_EXAMPLES=true -DBUILD_WITH_OPENMP=false -DHWM_OVER_XU=false -DBUILD_PYTHON_BINDINGS=true -DPYTHON_EXECUTABLE=/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python -DCMAKE_MACOSX_RPATH=ON -DCMAKE_INSTALL_RPATH="/usr/local/lib" -G "Unix Makefiles"
rm -f *.dylib wrappers/python/*.so
make install
cd ../wrappers/python/
cp /usr/local/lib/*realsense* pyrealsense2/
python find_librs_version.py /usr/local/ pyrealsense2
sudo python setup.py install 

I have some notes at https://wiki.eecs.berkeley.edu/ptexternal/Main/IntelRealSense#Mac_Python_2.x

For Python3.x, I used Homebrew to install Python 3.8 and then did:

export PATH=/usr/local/opt/[email protected]/bin:$PATH
git clone https://github.com/IntelRealSense/librealsense
brew install cmake libusb pkg-config
cd librealsense
mkdir build
cd build
mkdir -p /usr/local/realsense/python/3.8.3
cmake .. -DBUILD_EXAMPLES=true -DBUILD_WITH_OPENMP=false -DHWM_OVER_XU=false -DBUILD_PYTHON_BINDINGS=true -DPYTHON_EXECUTABLE=/usr/local/Cellar/[email protected]/3.8.3/Frameworks/Python.framework/Versions/3.8/bin/python3 -DCMAKE_MACOSX_RPATH=ON -DCMAKE_INSTALL_RPATH="/usr/local/realsense/python/3.8.3" -G "Unix Makefiles"
make install
cd ../wrappers/python/
cp /usr/local/lib/*realsense* pyrealsense2/
python find_librs_version.py /usr/local/ pyrealsense2
sudo /usr/local/opt/[email protected]/bin/python setup.py install
export PYTHONPATH=$PYTHONPATH:/usr/local/lib

Note that for Python3.x I had to set PYTHONPATH, which I did not need to do for Python2.x

I'm a little unsure if it is necessary to set CMAKE_INSTALL_RPATH in the cmake command.

@MartyG-RealSense
Copy link
Collaborator

@cxbrooks Thanks very much for sharing your method!

@ysiegel29 Does the method provided by @cxbrooks solve your problem, please? Thanks!

@ysiegel29
Copy link
Author

Sorry for not replying earlier, I have managed to make it work few days ago but to be honest I can't really tell what made it work... I have tried so many things.
I should have documented this better... Thanks a lot for your help.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jun 14, 2020

@ysiegel29 Thanks so much for the update - I'm pleased you got it working!

I filed an official feature request with Intel today for creation of a PyPi wheel file for Python 3.8 to enable pip install installation of pyrealsense2 on Python 3.8.

Is it okay to close this case now if you are satisfied?

@MartyG-RealSense
Copy link
Collaborator

Case closed due to no further comments received and an official feature request for pyrealsense2 on Python 3.8 having been filed.

@whubaichuan
Copy link

@MartyG-RealSense Hi, I got the error information: 'common/fw/target.h' file not found when make. And I encounter the "No internet connection, disabling IMPORT_DEPTH_CAM_FW" when cmake. How to solve it? Thanks.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Sep 10, 2020

Hi @whubaichuan Another RealSense user who experienced the target.h error when building the Python wrapper found that the solution that worked for them was to add the CMake flag -DBUILD_WITH_TM2=false

Dorodnic the RealSense SDK Manager also advises in the same case that you might need to check network proxy settings if you get the internet connection error.

#6346

@whubaichuan
Copy link

@MartyG-RealSense Install it in MacOS is not the best choice. I use windows and make it using pip install.

@MartyG-RealSense
Copy link
Collaborator

@whubaichuan Installation via PC is indeed the ideal situation due to the ease of pip and the lack of pip packages for non-x86 / x64 processors.

@MartyG-RealSense
Copy link
Collaborator

Adding a note to keep this case open for a further time period.

1 similar comment
@MartyG-RealSense
Copy link
Collaborator

Adding a note to keep this case open for a further time period.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Mar 28, 2021

Hi everyone,

pyrealsense2 wheel files for the pip install pyrealsense2 installation method have now been added for Python 3,8 and 3.9. As this Feature Request has been completed, this case will now be closed. Thanks so much for your patience!

https://pypi.org/project/pyrealsense2/#files

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

No branches or pull requests

4 participants