Skip to content

Commit 57efa02

Browse files
committed
pyinstaller support added to PipEnv
1 parent 8c69fc3 commit 57efa02

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

conan/tools/system/pip_manager.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import venv
21
import platform
32
import os
3+
import shutil
4+
import sys
45

56
from conan.tools.build import cmd_args_to_string
67
from conan.tools.env.environment import Environment
8+
from conan.errors import ConanException
79

810

911
class PipEnv:
@@ -23,6 +25,39 @@ def generate(self):
2325
env.prepend_path("PATH", self.bin_dir)
2426
env.vars(self._conanfile).save_script(self.env_name)
2527

28+
def _create_venv(self):
29+
print("=" * 20)
30+
python_executable = None
31+
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
32+
if platform.system() == "Windows":
33+
candidate_names = ['python.exe', 'pythonw.exe']
34+
else:
35+
candidate_names = ['python', 'python3']
36+
37+
for name in candidate_names:
38+
expected_path = os.path.join(sys._MEIPASS, name)
39+
print(expected_path)
40+
if os.path.exists(expected_path):
41+
python_executable = expected_path
42+
break
43+
if not python_executable:
44+
if platform.system() == "Windows":
45+
system_py = shutil.which('python')
46+
else:
47+
system_py = shutil.which('python3') or shutil.which('python')
48+
if system_py:
49+
python_executable = system_py
50+
else:
51+
python_executable = sys.executable
52+
print("=" * 20)
53+
print(python_executable)
54+
print(getattr(sys, 'frozen', False))
55+
print(getattr(sys, '_MEIPASS', False))
56+
print("=" * 20)
57+
if not python_executable:
58+
raise ConanException("PipEnv could not find a Python executable path.")
59+
self._conanfile.run(cmd_args_to_string([python_executable, '-m', 'venv', self._env_dir]))
60+
2661
def install(self, packages, pip_args=None):
2762
"""
2863
Will try to install the list of pip packages passed as a parameter.
@@ -34,7 +69,7 @@ def install(self, packages, pip_args=None):
3469
:return: the return code of the executed pip command.
3570
"""
3671

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

0 commit comments

Comments
 (0)