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

Cannot import from conan.tools.layout #10260

Closed
LokiNinja opened this issue Jan 3, 2022 · 19 comments
Closed

Cannot import from conan.tools.layout #10260

LokiNinja opened this issue Jan 3, 2022 · 19 comments
Assignees

Comments

@LokiNinja
Copy link

LokiNinja commented Jan 3, 2022

I was going through this tutorial in the documentation: https://docs.conan.io/en/latest/creating_packages/getting_started.html
Upon trying to run 'conan create . demo/testing' it fails with the following error:

ERROR: Error loading conanfile at 'hellopkg\conanfile.py': Unable to load conanfile in hellopkg\conanfile.py
File , line 684, in _load
File , line 665, in _load_unlocked
File , line 678, in exec_module
File , line 219, in _call_with_frames_removed
File "hellopkg\conanfile.py", line 3, in
from conan.tools.layout import cmake_layout
ModuleNotFoundError: No module named 'conan.tools.layout'

The versions I am running are:
Python 3.10.0
Conan version 1.44.0

I have verified that the function does exist in \site-packages\conan\tools\layout but it is not found for some reason

@memsharded
Copy link
Member

Hi @LokiNinja,

this is really unexpected, I have no idea what could be happening.

I would try a couple of things:

  • How did you install Conan? Regular pip install? Which OS? In a Python virtualenv?
  • Maybe try with an older Python version? We haven't added 3.10 to our testing in CI yet, I don't think this would be related, but just in case.
  • Is it only the cmake_layout that fails, but everything else from conan.tools works ok?

@crucio55
Copy link

crucio55 commented Jan 3, 2022

I'm having a similar issue - the latest Manjaro update updated python to 3.10.1, plus I installed conan from AUR.
The result is this:

❯ conan --version
Traceback (most recent call last):
  File "/usr/bin/conan", line 33, in <module>
    sys.exit(load_entry_point('conan==1.44.0', 'console_scripts', 'conan')())
  File "/usr/bin/conan", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 919, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 518, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for conan

@memsharded
Copy link
Member

@LokiNinja using AUR too? The AUR package maintainer is @tivek

Also @crucio55, is this something that only happens with latest Conan 1.44, or also previous versions? Did those previous versions used to work in Manjaro, and they broke with the Manjaro update?

@crucio55
Copy link

crucio55 commented Jan 3, 2022

I suspect I updated python and conan around the same time, but before that, as of a few days ago, python 3.9 + previous conan versions worked perfectly

@memsharded
Copy link
Member

Just for reference: I have checked locally Python 3.10 here in Windows, everything looking good. Could be something specific to the AUR package

@LokiNinja
Copy link
Author

LokiNinja commented Jan 3, 2022

Hi @memsharded,
I am not using AUR, I installed with pip and all tutorials up to this point worked fine. It is only the cmake_layout that fails to import, everything else seems to import okay. Ill try switching python to an earlier version and try again and let you know. I am running on a windows machine. I have also tried in a virtualenv and it fails with same error.

@memsharded
Copy link
Member

I am not using AUR, I installed with pip and all tutorials up to this point worked fine. It is only the cmake_layout that fails to import, everything else seems to import okay. Ill try switching python to an earlier version and try again and let you know. I am running on a windows machine. I have also tried in a virtualenv and it fails with same error.

Thanks for telling. Indeed super weird issue, please let me know your findings when you test with an earlier Python version (but apparently Python 3.10 was not an issue in my Windows 10 machin)

@LokiNinja
Copy link
Author

One other weird thing is in visual studio code I can ctrl click on the cmake_layout function and it navigates just fine to the actual file, so vscode at least knows where its at. Ill keep investigating and let you know my findings.

@LokiNinja
Copy link
Author

Switched python to 3.9.1 but seeing same error. Even tried switching to python 3.9.1-32 for 32 bit but no luck. Very odd issue as this definitely exists and conan imports resolve fine. When I have time later I will try installing and running in VM.

@memsharded
Copy link
Member

One idea to check: some weird interaction with AV software. This is very unlikely, to affect only this file, but it wouldn't be the first time an AV in Windows mess with my files causing hours of debugging. Checking the AV logs might be worth.

I would also try playing a bit directly with the package:

  • try to do a raw from ... cmake_layout directly in the Python interpreter, no Conan loading
  • try to add some broken thing in the site_packages cmake_layout.py file, to check if it is being actually loaded at some point and then the imports fail, or it is like the file it is not there at all.

@uilianries
Copy link
Member

uilianries commented Jan 4, 2022

I'm a Manjaro user, I also have python 3.10.1 and Conan 1.44 installed, but everything works fine for me.

I use only pip to install Conan, which is the recommended way.

My guess is that you environment mixed the installed packaged x python versions available, so I suggest enforcing only the current python version on your commands (just for testing):

/usr/bin/python3.10 -m pip install -U conan
/usr/bin/python3.10 -m conans.conan new hello/0.1 --template=cmake_lib
/usr/bin/python3.10 -m conans.conan create . user/testing

Use only absolute path and with version as suffix, also enforce the module name.
If it works, your Python environment is broken.

Also, you can show where Conan is installed on your system:

/usr/bin/python3.10 -m pip show conan

And check where Python is installing their packages:

/usr/bin/python3.10 -m site

Conan must be listed for both commands.

As Manjaro always try to run the latest version of every package, sometimes, we get something bugged, including python.
I use pyenv, not the Python from the system, so I can lock which python version I want by default, I strongly recommend you do the same. Here you can obtain more information about PyEnv Installer: https://github.com/pyenv/pyenv-installer

@crucio55
Copy link

crucio55 commented Jan 4, 2022

Removing the AUR version and installing from pip indeed made conan work again!

@tivek
Copy link
Contributor

tivek commented Jan 8, 2022

Sorry for the late reply. When upgrading Arch Linux system Python package from one major version to another, one needs to rebuild and reinstall all local or AUR-sourced Python-dependent packages. So, after going between Python 3.9 and 3.10 Conan and its dependencies from AUR need to be reinstalled. Hope this helps.

@memsharded
Copy link
Member

Great, thanks @tivek

Then, it seems the Manjaro/AUR issue is addressed, and only the Windows failure by @LokiNinja is pending to resolve.

@memsharded
Copy link
Member

@GrantMoyer reported https://github.com/conan-io/conan/pulls/10320 is fixing this. (released 1.44.1).
Can you please try and report? Otherwise this will be closed. Thanks!

@LokiNinja
Copy link
Author

LokiNinja commented Jan 30, 2022 via email

@memsharded
Copy link
Member

@LokiNinja oh, I see that probably not related to your case, and it might keep failing. The #10320 was fixing issues with the pyinstaller bundle distribution caused by some python (virtualenv) recent upgrades. But yes, checking 1.44.1 won't harm...

@memsharded
Copy link
Member

No activity from a while, no more reports from other users either, so closing it atm, please let us know if this is still an issue.

@lizzyd710
Copy link

Same here, but with conan.tools.system. The CI checks on the repo I'm working on is failing on the Linux systems saying it can't find that module, but it finds conan.tools.gnu just fine. The system call was added to xorg in this PR. Since it's a CI check running as a GitHub action, I'm fairly sure everything is built/installed when the action runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants