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

[package] cpython/3.10.0: Imported target includes non-existent path. #10808

Closed
hwhsu1231 opened this issue May 16, 2022 · 6 comments · Fixed by #21387
Closed

[package] cpython/3.10.0: Imported target includes non-existent path. #10808

hwhsu1231 opened this issue May 16, 2022 · 6 comments · Fixed by #21387
Labels
bug Something isn't working

Comments

@hwhsu1231
Copy link

hwhsu1231 commented May 16, 2022

Package and Environment Details

  • Package Name/Version: cpython/3.10.0
  • Operating System+version: Windows 11
  • Compiler+version: MSVC 2019
  • Docker image: None
  • Conan version: conan 1.45.0
  • Python version: Python 3.9.2

Conan profile (output of conan profile show default)

[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
build_type=Release
[options]
[conf]
[build_requires]
[env]

CMakeLists.txt and main.cpp

I use CMake-Conan to install package.

  • Click to expand the CMakeLists.txt
    cmake_minimum_required(VERSION 3.15)
    get_filename_component(folder_name "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
    project(${folder_name} LANGUAGES C CXX)
    message("========== ${folder_name} ==========")
    
    
    get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
    if(is_multi_config)     # Multi-Config Generator
      set(output_dir "${CMAKE_BINARY_DIR}/$<CONFIG>")
    else(is_multi_config)   # Single-Config Generator
      set(output_dir "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
    endif(is_multi_config)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${output_dir}/bin")
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${output_dir}/lib")
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${output_dir}/lib")
    
    
    if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
      add_compile_options("/source-charset:utf-8")
    elseif(CMAKE_CXX_COMPILER_DIR MATCHES GNU)
      add_compile_options("-finput-charset=utf-8")
    endif()
    
    
    if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
      message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan ...")
      file(DOWNLOAD 
        "https://raw.githubusercontent.com/conan-io/cmake-conan/develop/conan.cmake"
        "${CMAKE_BINARY_DIR}/conan.cmake")
    endif()
    include("${CMAKE_BINARY_DIR}/conan.cmake")
    
    
    set(conan_config_generators "CMakeDeps")
    set(conan_config_requires   "cpython/3.10.0")
    set(conan_config_options    "cpython:shared=True")
    
    
    if(is_multi_config)     # Multi-Config Generator
      foreach(type Debug;Release)
        conan_cmake_configure(
          GENERATORS  ${conan_config_generators}
          REQUIRES    ${conan_config_requires}
          OPTIONS     ${conan_config_options}
          IMPORTS     "bin, *.dll -> ../${type}/bin")
        conan_cmake_autodetect(settings BUILD_TYPE ${type})
        conan_cmake_install(
          PATH_OR_REFERENCE "."
          INSTALL_FOLDER    "./conan"
          BUILD             missing
          REMOTE            conancenter
          SETTINGS          ${settings})
      endforeach()
    else(is_multi_config)   # Single-Config Generator
      set(type ${CMAKE_BUILD_TYPE})
      conan_cmake_configure(
        GENERATORS  ${conan_config_generators}
        REQUIRES    ${conan_config_requires}
        OPTIONS     ${conan_config_options}
        IMPORTS     "bin, *.dll -> ../${type}/bin")
      conan_cmake_autodetect(settings)
      conan_cmake_install(
        PATH_OR_REFERENCE "."
        INSTALL_FOLDER    "./conan"
        BUILD             missing
        REMOTE            conancenter
        SETTINGS          ${settings})
    endif(is_multi_config)
    
    
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}/conan")
    list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/conan")
    
    find_package(cpython CONFIG REQUIRED)
    
    add_executable(main "./main.cpp")
    target_link_libraries(main PRIVATE cpython::cpython)
  • Click to expand the main.cpp
    #include <iostream>
    using namespace std;
    int main()
    {
        cout << "Hello world" << endl;
        return 0;
    }

Steps to reproduce

  1. Use VSCode to open an empty folder.
  2. Download CMake-Tools plugin from Extension.
  3. Create an empty CMakeLists.txt file, and then paste the above example on it.
  4. Create an empty main.cpp file, and then paste the above example on it.
  5. Press Ctrl+Shift+P, and then type CMake: Configure.
  6. Press Ctrl+Shift+P, and then type CMake: Build.

Logs

[cmake] CMake Error in CMakeLists.txt:
[cmake]   Imported target "cpython::cpython" includes non-existent path
[cmake] 
[cmake]     "C:/.conan/19e585/1/include"
[cmake] 
[cmake]   in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:
[cmake] 
[cmake]   * The path was deleted, renamed, or moved to another location.
[cmake] 
[cmake]   * An install or uninstall procedure did not complete successfully.
[cmake] 
[cmake]   * The installation package was faulty and references files it does not
[cmake]   provide.
@hwhsu1231 hwhsu1231 added the bug Something isn't working label May 16, 2022
@hwhsu1231
Copy link
Author

hwhsu1231 commented May 16, 2022

@madebr
Copy link
Contributor

madebr commented May 17, 2022

Can you try adding:

self.cpp_info.components["_python_copy"].includedirs = []
self.cpp_info.components["embed"].includedirs = []
self.cpp_info.components["_embed_copy"].includedirs = []
self.cpp_info.components["_hidden"].includedirs = []

to the bottom of the package_info method of the cpython recipe and report back your findings?

@hwhsu1231
Copy link
Author

hwhsu1231 commented May 17, 2022

@madebr Excuse me.

Do you mean to modify the conanfile.py of CPython downloaded from ConanCenter? Which means this file:

C:\Users\hwhsu1231\.conan\data\cpython\3.10.0\_\_\export\conanfile.py

If so, after I added those 4 lines of codes to the bottom of package_info method and then reconfigured the CMake project, the error message disappeared.

Logs

Click to expand logs
[cmake] Not searching for unused variables given on the command line.
[cmake] ========== CMakeDeps-cpython ==========
[cmake] -- Conan: Detected VS runtime: MDd
[cmake] -- Conan: checking conan executable
[cmake] -- Conan: Found program C:/Program Files/Conan/conan/conan.exe
[cmake] -- Conan: Version found Conan version 1.45.0
[cmake] -- Conan executing: C:/Program Files/Conan/conan/conan.exe install . --remote conancenter --install-folder ./conan --build missing --settings arch=x86_64 --settings build_type=Debug --settings compiler=Visual Studio --settings compiler.version=16 --settings compiler.runtime=MDd
[cmake] Configuration:
[cmake] [settings]
[cmake] arch=x86_64
[cmake] arch_build=x86_64
[cmake] build_type=Debug
[cmake] compiler=Visual Studio
[cmake] compiler.runtime=MDd
[cmake] compiler.version=16
[cmake] os=Windows
[cmake] os_build=Windows
[cmake] [options]
[cmake] [build_requires]
[cmake] [env]
[cmake] 
[cmake] conanfile.txt: Installing package
[cmake] Requirements
[cmake]     bzip2/1.0.8 from 'conancenter' - Cache
[cmake]     cpython/3.10.0 from 'conancenter' - Cache
[cmake]     expat/2.4.1 from 'conancenter' - Cache
[cmake]     libffi/3.2.1 from 'conancenter' - Cache
[cmake]     mpdecimal/2.5.0 from 'conancenter' - Cache
[cmake]     openssl/1.1.1l from 'conancenter' - Cache
[cmake]     sqlite3/3.36.0 from 'conancenter' - Cache
[cmake]     tcl/8.6.10 from 'conancenter' - Cache
[cmake]     tk/8.6.10 from 'conancenter' - Cache
[cmake]     xz_utils/5.2.5 from 'conancenter' - Cache
[cmake]     zlib/1.2.11 from 'conancenter' - Cache
[cmake] Packages
[cmake]     bzip2/1.0.8:589a23dff5fdb23a7fb851223eb766480ead0a9a - Cache
[cmake]     cpython/3.10.0:3026f51f36d0fcdff1e3d757f74d6bcf34bb2873 - Cache
[cmake]     expat/2.4.1:b49a4f13d5f917b326e0b0b876c9af8b30b9bf47 - Cache
[cmake]     libffi/3.2.1:d057732059ea44a47760900cb5e4855d2bea8714 - Cache
[cmake]     mpdecimal/2.5.0:0ac929b7629df69c781a5d655b2a72ebb4d552bb - Cache
[cmake]     openssl/1.1.1l:d057732059ea44a47760900cb5e4855d2bea8714 - Cache
[cmake]     sqlite3/3.36.0:5e2ee2bbbf247701a335de1962053720f3cbabf1 - Cache
[cmake]     tcl/8.6.10:6acf24cd4adf2df742e006cc0e5f0329e3b6e60b - Cache
[cmake]     tk/8.6.10:ff8c0a2099858c4ac702118803bbca24e3ffac72 - Cache
[cmake]     xz_utils/5.2.5:d057732059ea44a47760900cb5e4855d2bea8714 - Cache
[cmake]     zlib/1.2.11:d057732059ea44a47760900cb5e4855d2bea8714 - Cache
[cmake] 
[cmake] Installing (downloading, building) binaries...
[cmake] bzip2/1.0.8: Already installed!
[cmake] bzip2/1.0.8: Appending PATH environment variable: C:\.conan\a06b72\1\bin
[cmake] expat/2.4.1: Already installed!
[cmake] libffi/3.2.1: Already installed!
[cmake] mpdecimal/2.5.0: Already installed!
[cmake] openssl/1.1.1l: Already installed!
[cmake] sqlite3/3.36.0: Already installed!
[cmake] sqlite3/3.36.0: Appending PATH env var with : C:\.conan\090ca6\1\bin
[cmake] xz_utils/5.2.5: Already installed!
[cmake] zlib/1.2.11: Already installed!
[cmake] tcl/8.6.10: Already installed!
[cmake] tcl/8.6.10: Setting TCL_LIBRARY environment variable to C:\.conan\e52825\1\lib\tcl8.6
[cmake] tcl/8.6.10: Setting TCL_ROOT environment variable to C:\.conan\e52825\1
[cmake] tcl/8.6.10: Setting TCLSH environment variable to C:\.conan\e52825\1\bin\tclsh86tsgx.exe
[cmake] tcl/8.6.10: Adding PATH environment variable: C:\.conan\e52825\1\bin
[cmake] tk/8.6.10: Already installed!
[cmake] tk/8.6.10: Setting TK_LIBRARY environment variable: C:/.conan/229b6d/1/lib/tk8.6
[cmake] tk/8.6.10: Setting TCL_ROOT environment variable: C:/.conan/229b6d/1
[cmake] cpython/3.10.0: Already installed!
[cmake] cpython/3.10.0: Appending PATH environment variable: C:\.conan\19e585\1\bin
[cmake] cpython/3.10.0: Setting PYTHON environment variable: C:\.conan\19e585\1\bin\python_d.exe
[cmake] cpython/3.10.0: Setting PYTHONHOME environment variable: C:\.conan\19e585\1\bin
[cmake] cpython/3.10.0: Setting PYTHON_ROOT environment variable: C:\.conan\19e585\1
[cmake] conanfile.txt: Generator 'CMakeDeps' calling 'generate()'
[cmake] conanfile.txt: Generator 'VirtualRunEnv' calling 'generate()'
[cmake] conanfile.txt: Generator txt created conanbuildinfo.txt
[cmake] conanfile.txt: Aggregating env generators
[cmake] conanfile.txt: Generated conaninfo.txt
[cmake] conanfile.txt: Generated graphinfo
[cmake] conanfile.txt imports(): Copied 2 '.dll' files: pyshellext_d.dll, python310_d.dll
[cmake] WARN: tcl/8.6.10: requirement zlib/1.2.12 overridden by tk/8.6.10 to zlib/1.2.11 
[cmake] conanfile.txt: WARN: Using the new toolchains and generators without specifying a build profile (e.g: -pr:b=default) is discouraged and might cause failures and unexpected behavior
[cmake] -- Conan: Component target declared 'cpython::python'
[cmake] -- Conan: Component target declared 'cpython::_python_copy'
[cmake] -- Conan: Component target declared 'cpython::embed'
[cmake] -- Conan: Component target declared 'cpython::_embed_copy'
[cmake] -- Conan: Component target declared 'cpython::_hidden'
[cmake] -- Conan: Target declared 'cpython::cpython'
[cmake] -- Conan: Target declared 'ZLIB::ZLIB'
[cmake] -- Conan: Component target declared 'OpenSSL::Crypto'
[cmake] -- Conan: Component target declared 'OpenSSL::SSL'
[cmake] -- Conan: Target declared 'openssl::openssl'
[cmake] -- Conan: Including build module from 'C:/.conan/344d1b/1/lib/cmake/conan-official-openssl-variables.cmake'
[cmake] -- Conan: Target declared 'expat::expat'
[cmake] -- Conan: Component target declared 'mpdecimal::libmpdecimal'
[cmake] -- Conan: Component target declared 'mpdecimal::libmpdecimal++'
[cmake] -- Conan: Target declared 'mpdecimal::mpdecimal'
[cmake] -- Conan: Target declared 'libffi::libffi'
[cmake] -- Conan: Target declared 'BZip2::BZip2'
[cmake] -- Conan: Including build module from 'C:/.conan/a06b72/1/lib/cmake/conan-official-bzip2-variables.cmake'
[cmake] -- Conan: Component target declared 'SQLite::SQLite3'
[cmake] -- Conan: Target declared 'LibLZMA::LibLZMA'
[cmake] -- Conan: Including build module from 'C:/.conan/f7a23a/1/lib/cmake/conan-official-xz_utils-variables.cmake'
[cmake] -- Conan: Target declared 'tk::tk'
[cmake] -- Conan: Target declared 'tcl::tcl'
[cmake] ==== TARGET: main01
[cmake] ==== TARGET: main02
[cmake] ==== PYTHON: sayhello.py
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: D:/Code-Cpp-MyFavorite/Code-Research-PkgMgr-Conan/CMakeDeps-cpython/build/win32-MSVC-x64-Debug

Screenshots

image
image

@hwhsu1231
Copy link
Author

hwhsu1231 commented May 17, 2022

@madebr I'm not sure whether it has been fixed by your method. Here is another problem I met.

I change the main.cpp into the following code:

#include <Python.h>

int main(int argc, char *argv[])
{
    Py_Initialize();
    PyRun_SimpleString("print('hello world')\n");
    Py_Finalize();
    return 0;
}

However, the result of output is not printing hello world. Instead, it exits on the line of Py_Initialize() with the following output:

Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = 'D:\\Code-Cpp-MyFavorite\\Code-Research-PkgMgr-Conan\\CMakeDeps-cpython\\build\\win32-MSVC-x64-Debug\\Debug\\bin\\main.exe'
  sys.base_prefix = ''
  sys.base_exec_prefix = ''
  sys.platlibdir = 'lib'
  sys.executable = 'D:\\Code-Cpp-MyFavorite\\Code-Research-PkgMgr-Conan\\CMakeDeps-cpython\\build\\win32-MSVC-x64-Debug\\Debug\\bin\\main.exe'
  sys.prefix = ''
  sys.exec_prefix = ''
  sys.path = [
    'D:\\Code-Cpp-MyFavorite\\Code-Research-PkgMgr-Conan\\CMakeDeps-cpython\\build\\win32-MSVC-x64-Debug\\Debug\\bin\\python310_d.zip',
    '.\\DLLs',
    '.\\lib',
    'D:\\Code-Cpp-MyFavorite\\Code-Research-PkgMgr-Conan\\CMakeDeps-cpython\\build\\win32-MSVC-x64-Debug\\Debug\\bin',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000a8c (most recent call first):
  <no Python frame>

@hwhsu1231
Copy link
Author

@madebr How is it going?

@madebr
Copy link
Contributor

madebr commented Jun 7, 2022

I"m fine! Thanks for caring! I hope you are fine too?!
But that's probably not what you were asking 😄

I think the error in your previous comment is python complaining it cannot find the standard library.
As you know, the python experience == interpreter + library

The cpython recipe fixes this by setting environment variables in package_info: PYTHONHOME and PYTHON_ROOT.
I haven't tested with copying the python libraries to the build directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants