Python is 32-bit, chosen compiler is 64-bit [duplicate] - python

I'm trying to compile pybind11 on a Windows machine that has VisualStudio 2015 installed. I also have python 3.5.3 64bit installed, and cmake 2.8.12. I get the error:
CMake Error at tools/FindPythonLibsNew.cmake:122 (message):
Python config failure: Python is 64-bit, chosen compiler is 32-bit
Call Stack (most recent call first):
tools/pybind11Tools.cmake:16 (find_package)
CMakeLists.txt:28 (include)
I did not "choose" the compiler to be 32-bit, and looking at the CMakeLists.txt, I did not find any place to specify which compiler to run.
So how to I tell pybind11/cmake to compile for 64 bit?

You should specify the 64-bit VS compiler like so:
cmake "/path/to/src/" -G"Visual Studio 14 2015 Win64"
Otherwise it selects the 32-bit by default.

If you are using the Ninja generator and you have this error make sure you run the VS Dev command prompt in 64-bit mode:
VsDevCmd.bat arch=amd64 && cmake <options> ...

You can either do :
cmake .. -G"Visual Studio 14 2015 Win64"
cmake --build . --config Release --target check
or based on this quote from the Compiling the test cases for windows section here:
If all tests fail, make sure that the Python binary and the testcases
are compiled for the same processor type and bitness (i.e. either i386
or x86_64). You can specify x86_64 as the target architecture for the
generated Visual Studio project using cmake -A x64 ..
You can do :
cmake -A x64 ..
cmake --build . --config Release --target check

Related

CMake finds suitable Python version, but cannot use interpreter

I am trying to upgrade QGIS from 3.10 to 3.20 and this requires upgrading CMake to >=3.15 and Python >= 3.7. I am using an EOL Linux distribution (Fedora 28, upgrading the OS is the obvious easy fix but this has to be done on 28, no questions asked). I've installed both CMake (3.19.4) and Python (3.7.9) to my local directories, set them to path, and have added the following CMake options:
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_SERVER=ON \
-DPYTHON_EXECUTABLE=/usr/local/bin/python3.7 -D......
yet I receive the following error:
CMake Error at /usr/local/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find Python (missing: Python_EXECUTABLE Interpreter) (found
suitable version "3.7.9", minimum required is "3.7")
Reason given by package:
Interpreter: Cannot use the interpreter "/usr/local/bin/python3.7"
Call Stack (most recent call first):
/usr/local/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
/usr/local/share/cmake-3.19/Modules/FindPython/Support.cmake:3148 (find_package_handle_standard_args)
/usr/local/share/cmake-3.19/Modules/FindPython.cmake:428 (include)
CMakeLists.txt:946 (find_package)
Any suggestions on how to proceed? I've added the flags "-DCMAKE_PYTHON_INCLUDE_DIR" and "-DCMAKE_PYTHON_LIBRARY", made sure I configured the local Python to have shared libraries enabled and this either changes nothing or reverts to finding the older Python on my path (3.6.8).

Cython setup.py can't find installed Visual C++ Build Tools

I am attempting to build my cython code using this setup.py file:
from distutils.core import setup
from Cython.Build import cythonize
import numpy as np
setup(
name="My Cython Project",
ext_modules=cythonize("*.pyx", include_path=[np.get_include()], language="c++")
)
and
python setup.py build_ext --inplace
But am getting the error:
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
But I installed the build tools and I know they work because I can manually build my project using these commands in the Developer Command Prompt for VS 2019:
cython -a -3 --cplus Myfile.pyx
cl /LD /O2 /EHsc [ include files ] Myfile.cpp [ python 3.8 lib ]
Why does cython think the build tools are not installed? Do I need to add something to PATH?
(I run the same project on my macOS machine with gcc installed and it works perfectly.)
Screenshot of my Visual Studio Installer Screen
The problem is that setup.py shows you incorrect version of MSVC. It's not the 14.0 that you need. I just did solved the very same issue myself, also for Python 3.8, so here are the steps.
When you compile something for Python, you should use the same compiler version. So let's see what compiler was used for you Python:
python -c "import sys; print(sys.version)"
Mine prints:
3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]
So I need MSVC version 1916.
You can check which version it is here: https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B . For me 1916 is Visual Studio 2017 version 15.9 - likely that's what you really need.
You to M$ downloads https://my.visualstudio.com/Downloads?q=Visual%20Studio%202015&pgroup= , search, for example, for "Visual Studio Community 2017 (version 15.9)" and install it (or just the compiler) and enjoy.
P.S. It is likely that you will need exactly that compiler for all your python 3.8 extensions (unless you use direct dll calls) and you will need to recompile the code you did in Studio 2019.

python3 configure script error - could not find pthreads

I am trying to compile python 3.7.7 on mac os Big Sur.
Downloaded the source code from python.org
running the configure script exits on error
configure: error: could not find pthreads on your system
cmake version 3.19.0
gcc version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Dlib installing error: Could NOT find Boost

(Please, excuse my bad English!) Got into trap while trying to install dlib library on my computer(Windows 10 Pro, 64x), but all the time get the same error: Could NOT find Boost
What I have already done:
Installed Visual Studio Community 2017 version 15.1
Installed Anaconda: Python 3.6.0
|Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32
Downloaded boost_1_64_0.7z and unpacked it
Ran bootstrap
b2 -a --with-python address-model=64 toolset=msvc runtime-link=static
got the message: The Boost C++ Libraries were successfully built!
6.Next:
set BOOST_LIBRARYDIR=C:\Users\Lelek\boost_1_64_0\stage\lib
set BOOST_INCLUDEDIR=C:\Users\Lelek\boost_1_64_0
set BOOST_ROOT=C:\Users\Lelek\boost_1_64_0
set PATH=%PATH%;%BOOST_ROOT%;%BOOST_LIBRARYDIR%
7. On this stage if I try to run python setup.py install from dlib directory I get the output (the same error appears when try to call cmake -G "Visual Studio 15 2017 Win64" -DPYTHON3=1 .\tools\python):
CMake Warning at C:/Program Files/Cmake/share/cmake-3.8/Modules/FindBoost.cmake:1521 (message):
No header defined for python-py34; skipping header check
Call Stack (most recent call first):
C:/Users/Lelek/dlib-19.4/dlib/cmake_utils/add_python_module:61(FIND_PACKAGE)
CMakeLists.txt:6 (include)
-- Could NOT find Boost
CMake Warning at C:/Program Files/Cmake/share/cmake-3.8/Modules/FindBoost.cmake:1521 (message):
No header defined for python-py35; skipping header check
Call Stack (most recent call first):
C:/Users/Lelek/dlib-19.4/dlib/cmake_utils/add_python_module:63 (FIND_PACKAGE)
CMakeLists.txt:6 (include)
-- Could NOT find Boost
CMake Warning at C:/Program Files/Cmake/share/cmake-3.8/Modules/FindBoost.cmake:1521 (message):
No header defined for python3; skipping header check
Call Stack (most recent call first):
C:/Users/Lelek/dlib-19.4/dlib/cmake_utils/add_python_module:66 (FIND_PACKAGE)
CMakeLists.txt:6 (include)
-- Could NOT find Boost
-- Could NOT find Boost
-- Found PythonLibs: C:/ProgramData/Anaconda3/libs/python36.lib (found suitable version "3.6.0", minimum required is "3.4")
-- We couldn't find the right version of boost python. If you installed boost and you are still getting this error then you might have installed a version of boost that was compiled with a different version of visual studio than the one you are using. So you have to make sure that the version of visual studio is the same version that was used to compile the copy of boost you are using.
-- Set the BOOST_ROOT and BOOST_LIBRARYDIR environment variables before running cmake.
-- E.g. Something like this:
-- set BOOST_ROOT=C:\local\boost_1_57_0
-- set BOOST_LIBRARYDIR=C:\local\boost_1_57_0\stage\lib
--
-- You will also likely need to compile boost yourself rather than using one of the precompiled
-- windows binaries. Do this by going to the folder tools\build\ within boost and running
-- bootstrap.bat. Then run the command:
-- b2 install
-- And then add the output bin folder to your PATH. Usually this is the C:\boost-build-engine\bin
-- folder. Finally, go to the boost root and run a command like this:
-- b2 -a --with-python address-model=64 toolset=msvc runtime-link=static
-- When it completes, set BOOST_LIBRARYDIR equal to wherever b2 put the compiled libraries.
-- Note that you will need to set the address-model based on if you want a 32 or 64bit python library.
--
-- Next, when you invoke cmake to compile dlib you may have to use cmake's -G option to set the
-- 64 vs. 32bit mode of visual studio. Also, if you want a Python3 library you will need to
-- add -DPYTHON3=1. You do this with a statement like:
-- cmake -G "Visual Studio 12 2013 Win64" -DPYTHON3=1 ..\..\tools\python
-- Rather than:
-- cmake ..\..\tools\python
-- Which will build a 32bit Python2 module by default on most systems.
--
--
CMake Error at C:/Users/Lelek/dlib-19.4/dlib/cmake_utils/add_python_module:116 (message):
Boost python library not found.
Call Stack (most recent call first):
CMakeLists.txt:6 (include)
-- Configuring incomplete, errors occurred!
See also "C:/Users/Lelek/dlib-19.4/tools/python/build/CMakeFiles/CMakeOutput.log".
error: cmake configuration failed!
As usual for me, I found the answer, as soon as I asked question. So, if someone will get the same issue:
To solve his problem I deleted Anaconda and installed only Python(3.5.0). Then updated dlib using PyCharm. And again, excuse my bad English, please.
If anyone still has this problem, try changing all calls to FIND_PACKAGE inside dlib\cmake_utils\add_python_module from 'Boost' to 'boost'. Worked for me.
If, after finding boost, the installation tries to open python27.lib and fails:
Remove boost.
Repeat steps 2--6 from the original question AFTER activating your py36 environment in Anaconda.
Re-run the dlib setup.
The latter was a stupid mistake of mine, but just in case.

Cmake is not able to find Python-libraries

Getting this error:
sudo: unable to resolve host coderw#ll
-- Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108
(message):
Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315
(_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindPythonInterp.cmake:139
(FIND_PACKAGE_HANDLE_STANDARD_ARGS)
Code/cmake/Modules/FindNumPy.cmake:10 (find_package)
CMakeLists.txt:114 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/coderwall/Desktop/rdkit/build/CMakeFiles/CMakeOutput.log".
See also "/home/coderwall/Desktop/rdkit/build/CMakeFiles/CMakeError.log".
I have already installed:
sudo apt-get install python-dev
Environment variable are already set as follow:
PYTHON_INCLUDE_DIRS=/usr/include/python2.7
PYTHON_LIBRARIES=/usr/lib/python2.7/config/libpython2.7.so
Location of python.h : /usr/lib/include/python2.7/python.h
Location of python libs: /usr/lib/python2.7/
How to solve this?
You can fix the errors by appending to the cmake command the -DPYTHON_LIBRARY and -DPYTHON_INCLUDE_DIR flags filled with the respective folders.
Thus, the trick is to fill those parameters with the returned information from the python interpreter, which is the most reliable. This may work independently of your python location/version (also for Anaconda users):
$ cmake .. \
-DPYTHON_INCLUDE_DIR=$(python -c "import sysconfig; print(sysconfig.get_path('include'))") \
-DPYTHON_LIBRARY=$(python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
If the version of python that you want to link against cmake is Python3.X and the default python symlink points to Python2.X, python3 -c ... can be used instead of python -c ....
In case that the error persists, you may need to update the cmake to a higher version as stated by #pdpcosta and repeat the process again.
For me this is helpful:
# if using python2
apt-get install python-dev
# if using python3
apt-get install python3-dev
I hit the same issue,and discovered the error message gives misleading variable names. Try setting the following (singular instead of plural):
PYTHON_INCLUDE_DIR=/usr/include/python2.7
PYTHON_LIBRARY=/usr/lib/python2.7/config/libpython2.7.so
The (plural) variables you see error messages about are values that the PythonLibs sets up when it is initialised correctly.
Even after adding -DPYTHON_INCLUDE_DIR and -DPYTHON_LIBRARY as suggested above, I was still facing the error Could NOT find PythonInterp. What solved it was adding -DPYTHON_EXECUTABLE:FILEPATH= to cmake as suggested in https://github.com/pybind/pybind11/issues/99#issuecomment-182071479:
cmake .. \
-DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-DPYTHON_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") \
-DPYTHON_EXECUTABLE:FILEPATH=`which python`
I was facing this problem while trying to compile OpenCV 3 on a Xubuntu 14.04 Thrusty Tahr system.
With all the dev packages of Python installed, the configuration process was always returning the message:
Could NOT found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.6", minimum required is "2.7")
Could NOT find PythonLibs (missing: PYTHON_INCLUDE_DIRS) (found suitable exact version "2.7.6")
Found PythonInterp: /usr/bin/python3.4 (found suitable version "3.4", minimum required is "3.4")
Could NOT find PythonLibs (missing: PYTHON_LIBRARIES) (Required is exact version "3.4.0")
The CMake version available on Thrusty Tahr repositories is 2.8.
Some posts inspired me to upgrade CMake.
I've added a PPA CMake repository which installs CMake version 3.2.
After the upgrade everything ran smoothly and the compilation was successful.
Some last version of Ubuntu installs Python 3.4 by default and the CMake version from Ubuntu (2.8) only searches up to Python 3.3.
Try to add set(Python_ADDITIONAL_VERSIONS 3.4) before the find_package statement.
Remember to clean CMakeCache.txt too.
This problem can also happen in Windows. Cmake looks into the registry and sometimes python values are not set. For those with similar problem:
http://ericsilva.org/2012/10/11/restoring-your-python-registry-in-windows/
Just create a .reg file to set the necessary keys and edit accordingly to match your setup.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Python]
[HKEY_CURRENT_USER\Software\Python\Pythoncore]
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.6]
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.6\InstallPath]
#="C:\\python26"
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.6\PythonPath]
#="C:\\python26;C:\\python26\\Lib\\;C:\\python26\\DLLs\\"
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.7]
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.7\InstallPath]
#="C:\\python27"
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.7\PythonPath]
#="C:\\python27;C:\\python27\\Lib\\;C:\\python27\\DLLs\\"
Note that if you are using cMake version 3.12 or later, variable PythonInterp and PythonLibs has been changed into Python.
So we use:
find_package(Python ${PY_VERSION} REQUIRED)
instead of:
find_package(PythonInterp ${PY_VERSION} REQUIRED)
find_package(PythonLibs ${PY_VERSION} REQUIRED)
see https://cmake.org/cmake/help/v3.12/module/FindPython.html for details.
I had upgraded to python3.8 on my system and had an incomplete install. Managed to fix it by installing the rest of the 3.8 packages:
sudo apt-get install python3.8 python3.8-dev python3.8-distutils python3.8-venv
Paste this into your CMakeLists.txt:
# find python
execute_process(COMMAND python-config --prefix OUTPUT_VARIABLE PYTHON_SEARCH_PATH)
string(REGEX REPLACE "\n$" "" PYTHON_SEARCH_PATH "${PYTHON_SEARCH_PATH}")
file(GLOB_RECURSE PYTHON_DY_LIBS ${PYTHON_SEARCH_PATH}/lib/libpython*.dylib ${PYTHON_SEARCH_PATH}/lib/libpython*.so)
if (PYTHON_DY_LIBS)
list(GET PYTHON_DY_LIBS 0 PYTHON_LIBRARY)
message("-- Find shared libpython: ${PYTHON_LIBRARY}")
else()
message(WARNING "Cannot find shared libpython, try find_package")
endif()
find_package(PythonInterp)
find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT)
In case that might help, I found a workaround for a similar problem, looking at the cmake doc :
https://cmake.org/cmake/help/v3.0/module/FindPythonLibs.html
You must set two env vars for cmake to find coherent versions.
Unfortunately this is not a generic solution...
cmake -DPYTHON_LIBRARY=${HOME}/.pyenv/versions/3.8.0/lib/libpython3.8.a -DPYTHON_INCLUDE_DIR=${HOME}/.pyenv/versions/3.8.0/include/python3.8/ cern_root/
In Python 3.2 and onward distutils.sysconfig is deprecated in favor of sysconfig.
To get all the variable names in data structure and inspect the situation we can use get_paths function
import sysconfig
sysconfig.get_paths()
which will return us a dict with all the relevant variable names as keys, and corresponding paths as values.
When we know the key we can get the value dynamically,
>>> sysconfig.get_path("include")
'C:\\Program Files\\Python310\\Include'
However, the most convenient feature of sysutils for this situation is that it can list all the variables at once from the command-prompt by invoking python -m sysconfig:
$ python -m sysconfig
Platform: "macosx-10.4-i386"
Python version: "3.2"
Current installation scheme: "posix_prefix"
Paths:
data = "/usr/local"
include = "/Users/tarek/Dev/svn.python.org/py3k/Include"
platinclude = "."
platlib = "/usr/local/lib/python3.2/site-packages"
platstdlib = "/usr/local/lib/python3.2"
purelib = "/usr/local/lib/python3.2/site-packages"
scripts = "/usr/local/bin"
stdlib = "/usr/local/lib/python3.2"
Variables:
AC_APPLE_UNIVERSAL_BUILD = "0"
AIX_GENUINE_CPLUSPLUS = "0"
AR = "ar"
ARFLAGS = "rc"
...
Maybe below command line works for you if all of above methods didn't work.
sudo apt-get install cython cython3
On Ubuntu 20 at least, since Python 2.7 is deprecated, you can:
sudo apt install python2.7-dev
And then PYTHON_INCLUDE_DIR can be set to /usr/include/python2.7

Categories

Resources