Skip to content

Commit 0501a01

Browse files
committed
pyinstaller support added to PipEnv
1 parent 8c69fc3 commit 0501a01

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

conan/tools/system/pip_manager.py

Lines changed: 26 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,29 @@ 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+
print("=" * 20)
30+
print(python_executable)
31+
print(getattr(sys, 'frozen', False))
32+
print(getattr(sys, '_MEIPASS', False))
33+
print("=" * 20)
34+
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
35+
if platform.system() == "Windows":
36+
candidate_names = ['python.exe', 'pythonw.exe']
37+
else:
38+
candidate_names = ['python', 'python3']
39+
40+
for name in candidate_names:
41+
expected_path = os.path.join(sys._MEIPASS, name)
42+
if os.path.exists(expected_path):
43+
python_executable = expected_path
44+
break
45+
if not python_executable:
46+
raise ConanException("PipEnv could not determine the Python executable path.")
47+
48+
self._conanfile.run(cmd_args_to_string([python_executable, '-m', 'venv', self._env_dir]))
49+
2650
def install(self, packages, pip_args=None):
2751
"""
2852
Will try to install the list of pip packages passed as a parameter.
@@ -34,7 +58,7 @@ def install(self, packages, pip_args=None):
3458
:return: the return code of the executed pip command.
3559
"""
3660

37-
venv.EnvBuilder(clear=True, with_pip=True).create(self._env_dir)
61+
self._create_venv()
3862
args = [self._python_exe, "-m", "pip", "install", "--disable-pip-version-check"]
3963
if pip_args:
4064
args += list(pip_args)

0 commit comments

Comments
 (0)