Conan offer three special conan generators to create virtual environments:
virtualenv: Declares the self.env_info variables of the requirements.
virtualbuildenv: Special build environment variables for autotools/visual studio.
virtualrunenv: Special environment variables to locate executables and shared libraries in the requirements.
These virtual environment generators create two executable script files (.sh or .bat depending on the current operating system), one
activate the virtual environment (set the environment variables) and one for
You can aggregate two or more virtual environments, that means that you can activate a
virtualenv and then activate a
virtualrunenv so you will
have available the environment variables declared in the
env_info object of the requirements plus the special enviroment variables to locate executables
and shared libraries.
Conan provides a virtualenv generator, able to read from each dependency the self.env_info
variables declared in the
package_info() method and generate two scripts “activate” and “deactivate”. These scripts set/unset all env variables in the current shell.
The recipe of
cmake-installer/0.1@lasote/testing appends to the PATH variable the package folder/bin.
In the bin folder there is a cmake executable:
def package_info(self): self.env_info.path.append(os.path.join(self.package_folder, "bin"))
Let’s prepare a virtual environment to have available our cmake in the path, open
conanfile.txt and change (or add) virtualenv generator:
[requires] cmake-installer/0.1@lasote/testing [generators] virtualenv
$ conan install
And activate the virtual environment:
$ source activate.sh # Windows: activate.bat without the source
Two sets of scripts are available for Windows -
deactivate.ps1 if you are using powershell.
Now you can run
cmake --version and check that you have the installed CMake in path.
Deactivate the virtual environment (or close the console) to restore the environment variables:
$ source deactivate.sh # Windows: deactivate.bat without the source
Use the generator
virtualbuildenv to activate an environment that will set the environment variables for
Autotools and Visual Studio.
This will generate
Use the generator
virtualrunenv to activate an environment that will:
- Append to
PATHenvironment variable every
binfolder of your requirements.
- Append to
DYLD_LIBRARY_PATHenvironment variables each
libfolder of your requirements.
This generator is especially useful:
- If you are requiring packages with shared libraries and you are running some executable that needs those libraries.
- If you have a requirement with some tool (executable) and you need it in the path.
In the previous example of the
cmake_installer recipe, even if the cmake_installer package doesn’t declare the
using the virtualrunenv generator, the
bin folder of the package will be available in the PATH. So after activating the virtual environment we could just run
we will be executing the cmake of the package.
Check the section Reference/virtualrunenv to see the reference of the generator.