pythonwindowsconanconanfile

Does a Conan installation from a system installer still require an installation from pip to be able to work with a conanfile.py?


I have installed conan using a system installer (.exe) on Windows and it works perfectly when I install packages using a conanfile.txt. However I get the following error when I try to install packages from a conanfile.py file

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows

ERROR: Error loading conanfile at 'C:\Users\YawManu\source\repos\CMakeProject1\conanfile.py': Unable to load conanfile in C:\Users\YawManu\source\repos\CMakeProject1\conanfile.py
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\YawManu\source\repos\CMakeProject1\conanfile.py", line 3, in <module>
    from conan import Conanfile
ImportError: cannot import name 'Conanfile' from 'conan' (C:\Program Files\Conan\conan\_internal\conan\__init__.pyc)

Do I need to run pip install conan in addition to the system installation?

Below is the content of the conanfile.py

import os

from conan import Conanfile

class ProjectRecipe(Conanfile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "CMakeToolchain", "CMakeDeps"

    def requirements(self):
        self.requires("armadillo/12.6.4")
        self.requires("boost/1.86.0")
        self.requires("openssl/3.3.1")
        self.requires("onnxruntime/1.18.1")

Solution

  • There is a mistake in the import. The correct syntax is with ConanFile. Please try:

    import os
    
    from conan import ConanFile # Check the casing
    
    class ProjectRecipe(Conanfile):
        settings = "os", "compiler", "build_type", "arch"
        generators = "CMakeToolchain", "CMakeDeps"
    

    As a hint, you can use the conan new templates, like conan new cmake_lib to create working starting projects that should work.