question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[bug] Conan does not import packages from virtual environment

See original GitHub issue

When 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)

  1. Install conan system-wide, e.g. pip3 install conan
  2. Create a new virtual environment: virtualenv venv
  3. Activate the virtual environment: source venv/bin/activate
  4. Install package cowsay inside the virtual environment: pip install cowsay
  5. 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")
    
  6. 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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
chausner-audeeringcommented, Oct 4, 2021

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.

Good point, will keep it in mind. I’ll close this issue as resolved then.

0reactions
memshardedcommented, Oct 4, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[bug] compatibility for recipes using v2 python imports not ...
If Conan is installed with pip (e.g. inside a virtual environment), this should work as expected even with the current release.
Read more >
Running and deploying packages - Conan Docs
Use a Conan server remote to store all your applications and runtimes for all Operating Systems, platforms and targets. There are different approaches:...
Read more >
can't import installed packages in the virtualenv - Stack Overflow
It seems that you are running your Python code on global environment, instead of virtual environment which is my_first_venv .
Read more >
Add support for Conan package manager - Qt Bug Tracker
Conan has the concept of virtual environments, which can be used to launch a command prompt or shell with appropriate runtime dlls in...
Read more >
conan Changelog - pyup.io
Feature: Do not add architecture to system packages by default, ... Feature: Adding new ``tools.env.virtualenv:powershell`` conf to opt-in to generate and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found