1- import venv
21import platform
32import os
3+ import sys
44
55from conan .tools .build import cmd_args_to_string
66from conan .tools .env .environment import Environment
7+ from conan .errors import ConanException
78
89
910class PipEnv :
@@ -23,6 +24,24 @@ def generate(self):
2324 env .prepend_path ("PATH" , self .bin_dir )
2425 env .vars (self ._conanfile ).save_script (self .env_name )
2526
27+ def _create_venv (self ):
28+ python_executable = sys .executable
29+ if getattr (sys , 'frozen' , False ) and hasattr (sys , '_MEIPASS' ):
30+ if platform .system () == "Windows" :
31+ candidate_names = ['python.exe' , 'pythonw.exe' ]
32+ else :
33+ candidate_names = ['python' , 'python3' ]
34+
35+ for name in candidate_names :
36+ expected_path = os .path .join (sys ._MEIPASS , name )
37+ if os .path .exists (expected_path ):
38+ python_executable = expected_path
39+ break
40+ if not python_executable :
41+ raise ConanException ("PipEnv could not determine the Python executable path." )
42+
43+ self ._conanfile .run (cmd_args_to_string ([python_executable , '-m' , 'venv' , self ._env_dir ]))
44+
2645 def install (self , packages , pip_args = None ):
2746 """
2847 Will try to install the list of pip packages passed as a parameter.
@@ -34,7 +53,7 @@ def install(self, packages, pip_args=None):
3453 :return: the return code of the executed pip command.
3554 """
3655
37- venv . EnvBuilder ( clear = True , with_pip = True ). create ( self ._env_dir )
56+ self ._create_venv ( )
3857 args = [self ._python_exe , "-m" , "pip" , "install" , "--disable-pip-version-check" ]
3958 if pip_args :
4059 args += list (pip_args )
0 commit comments