Hi,
I am already using a python virtualenv for my current project. We recently decided to add Conan package management as well. One of the things I package with Conan is a slightly modified CMake package. I would like to be able to start a virtualenv and have this new CMake package available in a variable that I can use in python scripts. I read the virtualenv generator section so I understand how to do that. The problem is that I don't understand how I could use both my current virtualenv and the one generated by Conan as one single virtualenv. Is there a way to add to a virtualenv instead of generating a new one? My existing virtualenv gets Conan and wheel.
If this is not possible, I'd like to have a way to generate a python variable to points to my CMake package downloaded from Conan so that other python scripts can find my CMake package,
To further explain my use case to see if maybe there is an other way to do this, here's my issue: We use a virtualenv to get Conan. Then, we have a python script that installs all Conan packages that we need and uses a CMake generator to set some variables. However, we are also getting CMake from Conan. In order to be able to read this generated CMake file by Conan, we need to be able to tell our python script where is the CMake installation. The only python generator seems to be the virtualenv one. We already have a virtualenv activated, so we can't just activate a new one. We basically need a way to have a python variable generated to tell us where the CMake has been isntalled to.
Hi @JigsawCorp,
You could generate the activate scripts of the virtualenv generator in your python virtual environment folder and then call that script from the regular python one. As long as the route of cmake in the Conan cache doesn't check it should work.
@danimtb Thanks for the reply!
From my understanding, if I already activated a python virtualenv I cannot activate an other one? Are you saying that I can actually two virtualenv at the same time?
Are you saying that I could have my initial virtualenv activated, and then from a python script I could activate the new generate virtualenv without any issues?
Yes, I think you can call the Conan activate script when you have already activated the python environment.
What I was saying is that you can actually call the Conan activate directly from the python one, and that way you will avoid activating manually twice.
Please give it a go and let me know if that works
@danimtb
There appears to be a bug.
Here's my conanfile.txt:
[requires]
CMake/3.11.0@ourRemote/dev
[generators]
virtualenv
I do conan install conanfile.txt --install-folder=ven. Output is:
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=Visual Studio
compiler.runtime=MDd
compiler.version=14
os=Windows
os_build=Windows
[options]
[build_requires]
[env]
conanfileVenv.txt: Installing package
Requirements
CMake/3.11.0@ourRemote/dev from 'ourRemote' - Cache
Packages
CMake/3.11.0@ourRemote/dev:0af024203a0b6387e10932d07612bcd065ea249d - Cache
CMake/3.11.0@ourRemote/dev: Already installed!
conanfiletxt: Generator virtualenv created activate.bat
conanfile.txt: Generator virtualenv created deactivate.bat
conanfile.txt: Generator virtualenv created activate.ps1
conanfile.txt: Generator virtualenv created deactivate.ps1
conanfile.txt: Generator virtualenv created activate.sh
conanfile.txt: Generator virtualenv created deactivate.sh
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Generated conaninfo.txt
conanfile.txt: Generated graphinfo
My activate.bat looks like:
@echo off
SET PROMPT=(conanenv) %PROMPT%
It seems it's just not adding my CMake package to the activate script.
Does your CMake recipe sets the binary directory to the path?
something similar to this:
def package_info(self):
self.env.PATH.append(os.path.join(self.package_folder, "CMake", "bin"))
https://docs.conan.io/en/latest/devtools/running_packages.html#running-from-packages
@danimtb Apologies, I forgot that step.
Anyways, I can confirm that I can indeed activate the newly generated activate.bat and also keep my existing venv running at the same time. Thanks for the help!
Cool! 馃槃
Thanks a lot for the quick response.
Closing the issue as solved :)