I am quite new to coding. so this could be a stupid mistake from my side but pls do help me.
while trying to installing the python plugin,by generating a .dll file and I got stuck at the 5th step (Generate the cmake config) on the documentation (https://github.com/tmontaigu/CloudCompare-PythonPlugin/blob/master/docs/building.rst).
I am using windows 10, CloudCompare v2.12 alpha 64 bit.
my cmake error's screenshot is here
CMake Error
my CMakeLists.txt is here
cmake_minimum_required(VERSION 3.21)
include(cmake/helpers.cmake)
include(cmake/CompilerWarnings.cmake)
option(PLUGIN_PYTHON "Install Python Plugin" OFF)
if(PLUGIN_PYTHON)
project(PythonPlugin)
addplugin(NAME ${PROJECT_NAME})
# set_project_warnings(${PROJECT_NAME})
option(PLUGIN_PYTHON_USE_EMBEDDED_MODULES
"Should the Python wrapper libs be embedded in the plugin" ON
)
mark_as_advanced(PLUGIN_PYTHON_USE_EMBEDDED_MODULES)
if(WIN32)
option(PLUGIN_PYTHON_COPY_ENV
"Should the content of the current python venv be copied on install"
ON
)
mark_as_advanced(PLUGIN_PYTHON_COPY_ENV)
if(NOT PYTHON_EXECUTABLE)
if(DEFINED ENV{CONDA_PREFIX})
list(INSERT CMAKE_PREFIX_PATH 0
"$ENV{CONDA_PREFIX}/Library/share/cmake"
)
set(PYTHON_EXECUTABLE "$ENV{CONDA_PREFIX}/python.exe")
elseif(DEFINED ENV{VIRTUAL_ENV})
set(PYTHON_EXECUTABLE "$ENV{VENV_PREFIX}/Scripts/python.exe")
endif()
endif()
endif()
if(PYTHON_EXECUTABLE)
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-m" "pybind11" "--cmake"
RESULT_VARIABLE _PYTHON_SUCCESS
OUTPUT_VARIABLE PYBIND11_CMAKE_MODULES_PATH
)
if(_PYTHON_SUCCESS MATCHES 0)
string(REGEX REPLACE "\n" "" PYBIND11_CMAKE_MODULES_PATH
${PYBIND11_CMAKE_MODULES_PATH}
)
list(INSERT CMAKE_PREFIX_PATH 0 "${PYBIND11_CMAKE_MODULES_PATH}")
endif()
endif()
find_package(pybind11 CONFIG REQUIRED)
add_subdirectory(wrapper)
add_subdirectory(src)
if(PLUGIN_PYTHON_USE_EMBEDDED_MODULES)
target_compile_definitions(PythonPlugin PRIVATE -DUSE_EMBEDDED_MODULES)
embed_cccorelib_in(${PROJECT_NAME})
embed_pycc_in(${PROJECT_NAME})
endif()
target_link_libraries(PythonPlugin pybind11::embed)
set_target_properties(PythonPlugin PROPERTIES CXX_VISIBILITY_PRESET hidden)
if(WIN32)
manage_windows_install()
elseif(UNIX AND NOT APPLE)
if(NOT PLUGIN_PYTHON_USE_EMBEDDED_MODULES)
installsharedlibrary(TARGET cccorelib)
installsharedlibrary(TARGET pycc)
endif()
endif()
endif()
after the generation of pyccvenv virtual environment, my python.exe is placed at C:\Windows\System32\pyccvenv\Scripts\python.exe
if these informations are sufficient please do help me.
and I would also like to know if it is possible to install the plugin with the .dll file that's been already generated by someone else, if yes please do share the python plugin's .dll file so that my installation will be at ease
Related
I'm trying to build QT app with python embedded by PythonQT but stuck at building PythonQT.
Here is my environment and what I did:
mac os 10.15
python 3.8.5 installed by homebrew
python-dev-tools installed by pip
QT 5.15
download PythonQT source code from https://github.com/MeVisLab/pythonqt
open PythonQT.pro file in QT Creator (I don't have qmake command available globaly)
I don't have Headers path under /System/Library/Frameworks/Python.framework/, so in python.prf file, I did the following modification:
change include path: INCLUDEPATH += /usr/local/Cellar/python#3.8/3.8.5/Frameworks/Python.framework/Headers
change Lib path: LIBS += -F/usr/local/Cellar/python#3.8/3.8.5/Frameworks -framework Python
then:
right click project root and select Run qmake
right click project root and select build
I got this error:
No rule to make target /Users/xxx/Applications/Qt/5.15.0/clang_64/lib/libQt5UiTools_debug.a', needed by `../../lib/libPythonQt_QtAll-Qt5-Python3.8_d.3.2.0.dylib'. Stop.
If I use the original python.prf file, build with error the Python.h file not found.
The default build configuration is Debug, change it to Release resolve the issue.
Build debug version requires some more twist according to the official doc: https://mevislab.github.io/pythonqt/Building.html
I am trying to compile a project using cmake. This is the relevant CMakeLists.txt code snippet.
set(PYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.6/dist-packages/numpy/core/include/)
set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} /usr/local/lib/python3.6/dist-packages/numpy/core/include)
find_package(Python COMPONENTS Interpreter Development)
find_package(PythonLibs REQUIRED)
...
include_directories( ${PYTHON_INCLUDE_DIRS} )
To ensure that it is working properly, I print the relevant info
execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print(numpy.get_include())" OUTPUT_VARIABLE NUMPY_INCLUDE OUTPUT_STRIP_TRAILING_WHITESPACE)
message (STATUS "NUMPY_INCLUDE: " ${NUMPY_INCLUDE})
This is how I compile
cmake -DPYTHON_EXECUTABLE=/usr/bin/python3 .
Here is my output of cmake, the relevant bits.
-- Found Python: /usr/bin/python3.6 (found version "3.6.9") found components: Interpreter Development
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.6m.so (found version "3.6.9")
-- NUMPY_INCLUDE: /usr/local/lib/python3.6/dist-packages/numpy/core/include
So far everything is perfect and numpy is found.
However, on running make, I get the following
fatal error: numpy/ndarrayobject.h: No such file or directory
#include <numpy/ndarrayobject.h>
From what I can see I've covered all bases, yet I'm getting this error. What do I do?
I have some project which supposed to support Win32 and x64 platform.
Some code is generated by python script.
This script uses python3 features.
In CMakeLists.txt I have something like this:
find_package(PythonInterp REQUIRED)
if (CMAKE_CL_64)
set(MY_APP_PLATFORM "x64")
else()
set(MY_APP_PLATFORM "Win32")
endif()
add_custom_command(TARGET MyApp
PRE_BUILD
COMMAND ${PYTHON_EXECUTABLE} ${MyApp_ROOT}/generator.py -p ${MY_APP_PLATFORM }
WORKING_DIRECTORY ${PATH_GENERATED_SRC}
COMMENT "Generating code..."
VERBATIM
)
Quite simple.
Now when project for x64 is used everything works like a charm, but when building for Win32 (cmake have to generate separate project) cmake finds python 2.7.2.
Changing CMakeLists.txt this way:
find_package(PythonInterp 3.7 REQUIRED)
Leads to cmake failure.
Is there way to fix it, or do I have to correct pythons script to be python2 compatible?
Or do I have to install python3 for 32 and 64 bits to cover both platforms?
The CMake Module is FindPython3.cmake in your cmake distribution.
This should work:
find_package(Python3 COMPONENTS Interpreter)
add_custom_command(TARGET MyApp
PRE_BUILD
COMMAND ${PYTHON3_EXECUTABLE} ${MyApp_ROOT}/generator.py -p ${MY_APP_PLATFORM}
WORKING_DIRECTORY ${PATH_GENERATED_SRC}
COMMENT "Generating code..."
VERBATIM
)
It is available since cmake 3.12.
Documentation
I have a C++ project that I have generated Python bindings for using SWIG. I am now trying to finish the CMake file for the project by adding an install operation. But whenever I finish the install and try to call my functions, I get an error stating foo has no attribute bar().
It has to do with the fact that Python doesn't know where the .so file that the bindings rely on is. If both foo.py and _foo.so are in the same directory I can use the bindings perfectly. I am struggling with figuring out how I am supposed to "install" both the Python bindings and the .so they depend on, all in a portable manner.
Obviously I could just export the install path of the .so to LD_LIBRARY_PATH, but this seems like a hacky work around for what must have a proper solution.
My CMakeLists.txt. I have cut out the bits related to compiling of my C++ lib RTK:
# Project
##
# TODO this actually needs 3.3+
cmake_minimum_required(VERSION 2.6)
project(RTKLIB)
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
FIND_PACKAGE(PythonLibs 3 REQUIRED)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
find_program(PYTHON "python3" REQUIRED)
include(GNUInstallDirs)
# Variable declarations
##
# Define this directory
set(RTKLIB_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
# Define the build dir
set(RTKLIB_BIN_DIR "${RTKLIB_ROOT}/build")
list(APPEND CMAKE_MODULE_PATH "${RTKLIB_ROOT}/cmake")
# Setup python vars
set(SETUP_PY_IN "${RTKLIB_ROOT}/setup.py.in") # initial version of setup.py
set(SETUP_PY "${RTKLIB_BIN_DIR}/setup.py") # cmake generated setup.py
set(OUTPUT "${RTKLIB_BIN_DIR}/python_timestamp") # Timestamp used as dep
set(RTKLIB_PY "rtk_lib") # name of the python lib
# Set the output dir for SWIG
set(CMAKE_SWIG_OUTDIR ${RTKLIB_BIN_DIR}/${RTKLIB_PY})
# Generate Python bindings
##
# SWIG Config
SET_PROPERTY(SOURCE include/rtk_lib.i PROPERTY CPLUSPLUS ON)
SWIG_ADD_MODULE(${RTKLIB_PY} python include/rtk_lib.i) # Generate C-Python bindings
SWIG_LINK_LIBRARIES(${RTKLIB_PY} RTK ${PYTHON_LIBRARIES}) # Link the bindings with python
# Generate the setup.py file
configure_file(${SETUP_PY_IN} ${SETUP_PY})
# Build command that depends on the SWIG output files and updates the timestamp
add_custom_command(OUTPUT ${OUTPUT}
COMMAND ${PYTHON} ${SETUP_PY} build
COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}
DEPENDS ${RTKLIB_BIN_DIR}\${SWIG_MODULE_${RTKLIB_PY}_REAL_NAME})
# Custom target that depends on the timestamp file generated by the custom command
add_custom_target(ALL DEPENDS ${OUTPUT})
# Install the shared library
install(TARGETS ${SWIG_MODULE_${RTKLIB_PY}_REAL_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Install to user's packages
install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install --user)")
And here is my setup.py.in if its any help:
from distutils.core import setup
setup(name='rtk_lib',
version='${PACKAGE_VERSION}',
description="""Python bindings for rtk_lib, allowing for serial and
and file interfaces with RTK messages.""",
packages=['${RTKLIB_PY}'])
Quick Summary of the code: It generates wrapper classes for the C++ that are Python compatible, then it compiles and links the wrapper classes with the Python libs and the original RTK C++ library. After that you have a directory called rtk_lib which has both your wrapper classes and the rtk_lib.py module. Outside of this rtk_lib directory is the outputted _rtk_lib.so shared library that the rtk_lib.py relies on. So in order to get the bindings to work, I copy _rtk_lib.so in to that rtk_lib directory and call python3. Then I can import the lib and everything is great.
I try to install the shared lib, but even then I still get the same rtk_lib has no attribute blablabla().
Looks like an old question, but here goes anyway.
See this example swig_examples_cpp showing simple C++ functions wrapped by SWIG, using CMake and CLion to build it. The C version is here
Here's the full Python Cmake file:
project(python_example)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(PythonLibs)
include_directories(${PYTHON_INCLUDE_PATH})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_SWIG_FLAGS "")
set_source_files_properties(../src/example.i PROPERTIES CPLUSPLUS ON)
swig_add_library(python_example
TYPE MODULE
LANGUAGE python
OUTPUT_DIR ../../py_out # move the .so to py_out
OUTFILE_DIR . # leave the .cpp in cmake-build-debug
SOURCES ../src/example.i
../src/example.cpp ../src/example.h
)
set_target_properties(python_example PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ../../py_out # must match dir in OUTPUT_DIR
)
After building it, run python test.py to see it go. Note it's all in bash/Ubuntu, so MacOs should be ok, but windows may cause you some churn.
See the README for the full details.
I've tried to resolve this prolem for about 3days, and I'd finally felt that I need to ask for help by creating my own question.
I have Windows 7x64 and Qt4.8.6 installed.
I need Python with PyQt and Qscintilla2 to be installed and working.
Now I wil describe my last actions. I did everything like included packages instructions said.
1) Installed Python2.7.9 32bit from official website.
2) Downloaded SIP from here (dev snapshot), then:
configure.py —platform win32-g++
mingw32-make
mingw32-make install
3) Downloaded PyQt from here (not the installer but dev snapshot, cause I need to build with MinGW and istaller producec MSVC version), then:
configure-ng.py -spec win32-g++
mingw32-make
mingw32-make install
Ater these steps I tested PyQt on my project - everything works fine.
Then I starded trying to install Qsnitilla2.
4) Downloaded Qsnitilla2 from here (dev snapshot), then:
a) in Qt4Qt5 folder:
qmake qscintilla.pro -spec win32-g++
mingw32-make
mingw32-make install
This had installed Qsnitilla2 in Qt4.8.6 as I saw;
b) in Python folder( F..ing Python bindngs, excuse my french):
config.py —spec win32-g++
mingw32-make
after this I got ld.exe error (linking error):
Then, afted doing some research, I manually edited my Makefile.Release (by adding -lpython27 to LIBS parameter):
LIBS = -L"c:\Qt-mingw\4.8.6\lib" -LC:\Python27\libs -LC:\Qt-mingw\4.8.6\lib -lqscintilla2 -lQtGui4 -lQtCore4 -lpython27
After this, my mingw32-make completed succesfully. So:
mingw32-make install
This had installed Qscintilla2 Python bindings.
Now I can see Qsci autocomlplete in Eclipse.
So i've tried this:
from PyQt4.Qsci import QsciScintilla
And i've got this in traceback:
from PyQt4.Qsci import QsciScintilla
ImportError: DLL load failed: Не найден указанный модуль
(Translation: The specified module could not be found)
I've tried this with both dev snapshot and src packages from Riverbank website. And also with MinGW 4.8.1 and MinGW-w64 4.8.4. I can't use MinGW-w64 over 4.8 version cause I need boost-1.55 and it only supports MinGW 4.8.
I don't know what to do now, but I really want to use Scintilla in my project. So i'll be very gratefull for any suggestions.
Have you ever tried to load the QsciScintilla right from the console? I mean you need to enter the directory where the QScintilla located( this means current folder is the default folder), then try run the command "from PyQt4.Qsci import QsciScintilla", if this load module failure still happens, this possibly means you need extra dynamic which QScintilla depends, you need to use dll dependency to find out if some other libraries were missing, then put the missing libraries into the same folder of QsciScintilla.