Skip to content

Possibility to use conda environments #207

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jetson-utils is typically built as a submodule of [jetson-inference](https://git

``` bash
git clone https://github.com/dusty-nv/jetson-utils
cd jetson-utils
mkdir build
cd build
cmake ../
Expand All @@ -38,4 +39,4 @@ sudo make install
sudo ldconfig
```

If you're missing dependencies, run the [`jetson-inference/CMakePreBuild.sh`](https://github.com/dusty-nv/jetson-inference/blob/master/CMakePreBuild.sh) script.
If you're missing dependencies, run the [`jetson-inference/CMakePreBuild.sh`](https://github.com/dusty-nv/jetson-inference/blob/master/CMakePreBuild.sh) script.
30 changes: 21 additions & 9 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@
#
# If you want to support another version of Python, add it here.
#
if(LSB_RELEASE_CODENAME MATCHES "jammy")
set(PYTHON_BINDING_VERSIONS 3.10)
elseif(LSB_RELEASE_CODENAME MATCHES "focal")
set(PYTHON_BINDING_VERSIONS 3.8)
if(USE_CONDA AND DEFINED ENV{CONDA_PREFIX})
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
if(PYTHON_VERSION_STRING)
string(REGEX MATCH "^[0-9]+\\.[0-9]+" PYTHON_BINDING_VERSIONS "${PYTHON_VERSION_STRING}")
else()
set(PYTHON_BINDING_VERSIONS 3.9 3.10 3.11) # Default versions if specific version not detected
endif()
else()
set(PYTHON_BINDING_VERSIONS 2.7 3.6 3.7)
if (LSB_RELEASE_CODENAME MATCHES "noble")
set(PYTHON_BINDING_VERSIONS 3.12)
elseif(LSB_RELEASE_CODENAME MATCHES "jammy")
set(PYTHON_BINDING_VERSIONS 3.10)
elseif(LSB_RELEASE_CODENAME MATCHES "focal")
set(PYTHON_BINDING_VERSIONS 3.8)
else()
set(PYTHON_BINDING_VERSIONS 2.7 3.6 3.7)
endif()
endif()

message("-- trying to build Python bindings for Python versions: ${PYTHON_BINDING_VERSIONS}")

foreach(PYTHON_BINDING_VERSION ${PYTHON_BINDING_VERSIONS})
add_subdirectory(bindings bindings_python_${PYTHON_BINDING_VERSION})
add_subdirectory(bindings bindings_python_${PYTHON_BINDING_VERSION})
endforeach()


Expand All @@ -26,7 +38,7 @@ endforeach()
file(GLOB pyUtilExamples examples/*.py examples/*.sh)

foreach(pyExample ${pyUtilExamples})
message("-- Copying ${pyExample}")
file(COPY ${pyExample} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
install(FILES "${pyExample}" DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
message("-- Copying ${pyExample}")
file(COPY ${pyExample} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
install(FILES "${pyExample}" DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endforeach()
23 changes: 15 additions & 8 deletions python/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ unset(PYTHONLIBS_VERSION_STRING CACHE)

# locate requested python version
message("-- detecting Python ${PYTHON_BINDING_VERSION}...")

find_package(PythonInterp ${PYTHON_BINDING_VERSION} QUIET)
find_package(PythonLibs ${PYTHON_BINDING_VERSION} QUIET)

if(NOT ${PYTHONLIBS_FOUND})
message("-- Python ${PYTHON_BINDING_VERSION} wasn't found")
return()
endif()

message("-- found Python version: ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} (${PYTHONLIBS_VERSION_STRING})")
message("-- found Python include: ${PYTHON_INCLUDE_DIRS}")
message("-- found Python library: ${PYTHON_LIBRARIES}")
message(STATUS "Using Python executable: ${PYTHON_EXECUTABLE}")
message(STATUS "Using Python version: ${PYTHON_VERSION_STRING}")
message(STATUS "Using Python include dir: ${PYTHON_INCLUDE_DIRS}")
message(STATUS "Using Python library: ${PYTHON_LIBRARIES}")

include_directories(${PYTHON_INCLUDE_DIRS})

Expand Down Expand Up @@ -70,10 +69,18 @@ set_target_properties(jetson-utils-python-${PYTHON_VERSION_MAJOR}${PYTHON_VERSIO

# on x86, install under /opt/conda/lib/pythonX.X/site-packages
# otherwise, install under /usr/lib/pythonX.X/dist-packages
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
set(PYTHON_BINDING_INSTALL_DIR /opt/conda/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
if(USE_CONDA AND DEFINED ENV{CONDA_PREFIX})
# For Conda environment, always use the Conda library path
set(PYTHON_BINDING_INSTALL_DIR $ENV{CONDA_PREFIX}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
message("-- Installing Python bindings to Conda environment directory: ${PYTHON_BINDING_INSTALL_DIR}")
else()
set(PYTHON_BINDING_INSTALL_DIR /usr/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/dist-packages)
# Check system processor for default installation path
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
set(PYTHON_BINDING_INSTALL_DIR /opt/conda/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
else()
set(PYTHON_BINDING_INSTALL_DIR /usr/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/dist-packages)
endif()
message("-- Installing Python bindings to system directory: ${PYTHON_BINDING_INSTALL_DIR}")
endif()

install(TARGETS jetson-utils-python-${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR} DESTINATION ${PYTHON_BINDING_INSTALL_DIR})
Expand Down