1111import sh
1212import subprocess
1313
14- from pythonforandroid .util import (ensure_dir , current_directory , BuildInterruptingException )
14+ from pythonforandroid .util import (
15+ current_directory , ensure_dir , get_virtualenv_executable ,
16+ BuildInterruptingException
17+ )
1518from pythonforandroid .logger import (info , warning , info_notify , info_main , shprint )
1619from pythonforandroid .archs import ArchARM , ArchARMv7_a , ArchAarch_64 , Archx86 , Archx86_64
1720from pythonforandroid .recipe import CythonRecipe , Recipe
@@ -305,13 +308,7 @@ def prepare_build_environment(self,
305308
306309 check_ndk_api (ndk_api , self .android_api )
307310
308- virtualenv = None
309- if virtualenv is None :
310- virtualenv = sh .which ('virtualenv2' )
311- if virtualenv is None :
312- virtualenv = sh .which ('virtualenv-2.7' )
313- if virtualenv is None :
314- virtualenv = sh .which ('virtualenv' )
311+ virtualenv = get_virtualenv_executable ()
315312 if virtualenv is None :
316313 raise IOError ('Couldn\' t find a virtualenv executable, '
317314 'you must install this to use p4a.' )
@@ -509,7 +506,7 @@ def has_package(self, name, arch=None):
509506 # Try to look up recipe by name:
510507 try :
511508 recipe = Recipe .get_recipe (name , self )
512- except IOError :
509+ except ValueError :
513510 pass
514511 else :
515512 name = getattr (recipe , 'site_packages_name' , None ) or name
@@ -618,14 +615,15 @@ def run_pymodules_install(ctx, modules):
618615 line = '{}\n ' .format (module )
619616 fileh .write (line )
620617
618+ # Prepare base environment and upgrade pip:
621619 base_env = copy .copy (os .environ )
622620 base_env ["PYTHONPATH" ] = ctx .get_site_packages_dir ()
623-
624621 info ('Upgrade pip to latest version' )
625622 shprint (sh .bash , '-c' , (
626623 "source venv/bin/activate && pip install -U pip"
627624 ), _env = copy .copy (base_env ))
628625
626+ # Install Cython in case modules need it to build:
629627 info ('Install Cython in case one of the modules needs it to build' )
630628 shprint (sh .bash , '-c' , (
631629 "venv/bin/pip install Cython"
@@ -648,15 +646,17 @@ def run_pymodules_install(ctx, modules):
648646 'changes / workarounds.' )
649647
650648 # Make sure our build package dir is available, and the virtualenv
651- # site packages come FIRST (for the proper pip version):
649+ # site packages come FIRST (so the proper pip version is used ):
652650 env ["PYTHONPATH" ] += ":" + ctx .get_site_packages_dir ()
653651 env ["PYTHONPATH" ] = os .path .abspath (join (
654652 ctx .build_dir , "venv" , "lib" ,
655653 "python" + ctx .python_recipe .major_minor_version_string ,
656654 "site-packages" )) + ":" + env ["PYTHONPATH" ]
655+
656+ # Do actual install:
657657 shprint (sh .bash , '-c' , (
658- "source venv/bin/activate && " +
659- "pip install -v --target '{0}' --no-deps -r requirements.txt"
658+ "venv/bin/pip " +
659+ "install -v --target '{0}' --no-deps -r requirements.txt"
660660 ).format (ctx .get_site_packages_dir ().replace ("'" , "'\" '\" '" )),
661661 _env = copy .copy (env ))
662662
0 commit comments