conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.29k stars 982 forks source link

[bug] ImportError: cannot import name 'CMake' from 'conan' (/Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/qe-compiler/qiskit_env2/lib/python3.13/site-packages/conan/__init__.py) #17297

Closed anurag-quantum closed 2 weeks ago

anurag-quantum commented 2 weeks ago

Describe the bug

MacOS, virtual environment

Installing collected packages: conan
Successfully installed conan-2.9.2
Installing collected packages: conan
Successfully installed conan-2.9.2

[notice] A new release of pip is available: 24.2 -> 24.3.1
[notice] To update, run: pip install --upgrade pip
(qiskit_env2) anuragpateriya@anurags-MBP qe-compiler % nano conanfile.py 
(qiskit_env2) anuragpateriya@anurags-MBP qe-compiler % conan install . -s build_type=Release -o 'zlib/*:shared=True' -o 'openssl/*:shared=True'

======== Input profiles ========
Profile host:
[settings]
arch=armv8
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=15
os=Macos
[options]
openssl/*:shared=True
zlib/*:shared=True

Profile build:
[settings]
arch=armv8
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=15
os=Macos

ERROR: Error loading conanfile at '/Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/qe-compiler/conanfile.py': Unable to load conanfile in /Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/qe-compiler/conanfile.py
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 1022, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/qe-compiler/conanfile.py", line 14, in <module>
    from conan import ConanFile, CMake, tools
ImportError: cannot import name 'CMake' from 'conan' (/Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/qe-compiler/qiskit_env2/lib/python3.13/site-packages/conan/__init__.py)

How to reproduce it

No response

memsharded commented 2 weeks ago

Hi @anurag-quantum

Thanks for your feedback.

This wouldn't be a bug. You are using with Conan 2.X a legacy Conan 1.X recipe, that contains from conan import ConanFile, CMake, tools, which no longer exist in Conan 2. It seems you replaced the from conans with from conan, but that is not enough, you need to use the new imports and tools, it is not just that the import changes, but the legacy tools were replaced already in Conan 1.X many years ago with modern alternatives, that can be imported from the namespaces like from conan.tools.cmake import CMakeDeps, CMakeToolchain, CMake, cmake_layout.

Please have a look to https://docs.conan.io/1/conan_v2.html, the very first section talks about the imports.

anurag-quantum commented 2 weeks ago

@memsharded Thanks. Thats resolved my issue.

memsharded commented 2 weeks ago

Great, closing the ticket as solved then, thanks for the feedback

anurag-quantum commented 1 week ago

After making the change, I am facing this .

ERROR: Conanfile not found at /Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/conanfile.txt

while running this command.

ERROR: Error loading conanfile at '/Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/qe-compiler/conanfile.py': Unable to load conanfile in /Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/qe-compiler/conanfile.py
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 1022, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/qe-compiler/conanfile.py", line 14, in <module>
    from conans import ConanFile, CMake, tools
ImportError: cannot import name 'ConanFile' from 'conans' (/usr/local/Cellar/conan/2.9.2/libexec/lib/python3.13/site-packages/conans/__init__.py)

anuragpateriya@anurags-MBP build % cd ..
anuragpateriya@anurags-MBP qe-compiler % nano conanfile.py 
anuragpateriya@anurags-MBP qe-compiler % conan install .. --build=outdated -pr:h default -pr:b default
ERROR: Conanfile not found at /Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/conanfile.txt
memsharded commented 1 week ago

from conans import ConanFile, CMake, tools

You are still importing from conans which doesn't exist in Conan 2. You have 2 options:

anurag-quantum commented 1 week ago

apologies for posting incorrect logs. Please check these logs.

anuragpateriya@anurags-MBP qe-compiler % nano conanfile.py  <<------- here i changed the conanfile.

# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
import os

from conan.tools.cmake import CMakeDeps, CMakeToolchain, CMake, cmake_layout

anuragpateriya@anurags-MBP qe-compiler % conan install .. --build=outdated -pr:h default -pr:b default ERROR: Conanfile not found at /Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/conanfile.txt anuragpateriya@anurags-MBP qe-compiler % conan install . --output-folder=build

======== Input profiles ========
Profile host:
[settings]
arch=armv8
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=15
os=Macos

Profile build:
[settings]
arch=armv8
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=15
os=Macos

ERROR: Error loading conanfile at '/Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/qe-compiler/conanfile.py': Unable to load conanfile in /Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/qe-compiler/conanfile.py
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 1022, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/Users/anuragpateriya/Desktop/qiskit_repo/qe-compiler/qe-compiler/conanfile.py", line 25, in <module>
    class QSSCompilerConan(ConanFile):
                           ^^^^^^^^^
NameError: name 'ConanFile' is not defined
memsharded commented 1 week ago

NameError: name 'ConanFile' is not defined

You still need the from conan import ConanFile