[bug] Conan does not import packages from virtual environment
See original GitHub issueWhen a conan build is invoked while a virtual environment is activated, and conan is not installed in the virtual environment, attempts to load any modules from the virtual environment fail.
Environment Details (include every applicable attribute)
- Operating System+version: Ubuntu 20.04
- Compiler+version:
- Conan version: 1.40.3
- Python version: 3.8.10
Steps to reproduce (Include if Applicable)
- Install conan system-wide, e.g.
pip3 install conan
- Create a new virtual environment:
virtualenv venv
- Activate the virtual environment:
source venv/bin/activate
- Install package
cowsay
inside the virtual environment:pip install cowsay
- Create a dummy
conanfile.py
:from conans import ConanFile class ConantestConan(ConanFile): name = "conantest" version = "1.0.0" def build(self): import cowsay print("cowsay imported")
- Attempt to build the package:
mkdir build ; cd build ; conan install .. ; conan build ..
conan will fail to load the cowsay module:
ERROR: conanfile.py (conantest/1.0.0): Error in build() method, line 8 import cowsay ModuleNotFoundError: No module named ‘cowsay’
I already tried passing --system-site-packages
to the virtualenv
command but it does not fix the issue. The only workaround is to install conan itself in the virtual environment.
Background:
We are running conan on our CI runners and since the runners are not dockerized, we would like to invoke Conan inside virtual environments in order to ensure pip dependencies of different conanfiles do not lead to conflicts. We found that we currently need to install those dependencies system-wide on the runners, which defeats the whole point of the virtual environments.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Good point, will keep it in mind. I’ll close this issue as resolved then.
I think that such workaround could have some unexpected side effects because if Conan is installed at the system level, then the virtualenv that executes that command could potentially have incompatible dependencies. If you have that controlled and works for you, then great, but please keep an eye on your virtualenv installed dependencies and possible collisions with Conan ones.