Skip to content

Commit 237122f

Browse files
committed
pyinstaller support added to PipEnv
1 parent 8c69fc3 commit 237122f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

conan/tools/system/pip_manager.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import venv
21
import platform
32
import os
3+
import sys
44

55
from conan.tools.build import cmd_args_to_string
66
from conan.tools.env.environment import Environment
7+
from conan.errors import ConanException
78

89

910
class 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

Comments
 (0)