def install_blender_reqs(gui=True): # http://stackoverflow.com/questions/9956741/how-to-install-multiple-python-packages-at-once-using-pip try: blender_fol = utils.get_link_dir(utils.get_links_dir(), 'blender') resource_fol = utils.get_resources_fol() blender_parent_fol = utils.get_parent_fol(blender_fol) # Get pip bin_template = op.join(utils.get_parent_fol(blender_fol), 'Resources', '2.7?', 'python') if utils.is_osx() else \ op.join(blender_fol, '2.7?', 'python') blender_bin_folders = sorted(glob.glob(bin_template)) if len(blender_bin_folders) == 0: print("Couldn't find Blender's bin folder! ({})".format( bin_template)) blender_bin_fol = '' choose_folder = mmvt_input( 'Please choose the Blender bin folder where python file exists', gui) == 'Ok' if choose_folder: fol = utils.choose_folder_gui( blender_parent_fol, 'Blender bin folder') if gui else input() if fol != '': blender_bin_fol = glob.glob(op.join(fol, '2.7?', 'python'))[-1] if blender_bin_fol == '': return else: # todo: let the use select the folder if more than one blender_bin_fol = blender_bin_folders[-1] python_exe = 'python.exe' if utils.is_windows() else 'python3.5m' current_dir = os.getcwd() os.chdir(blender_bin_fol) # if utils.is_osx(): # install blender reqs: pip_cmd = '{} {}'.format(op.join('bin', python_exe), op.join(resource_fol, 'get-pip.py')) reqs = 'matplotlib zmq pizco scipy mne joblib tqdm nibabel pdfkit decorator scikit-learn' if not utils.is_windows(): utils.run_script(pip_cmd) install_cmd = '{} install {}'.format(op.join('bin', 'pip'), reqs) utils.run_script(install_cmd) else: # https://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script install_cmd = '{} install '.format(op.join('Scripts', 'pip'), reqs) print( 'Sorry, automatically installing external python libs in python will be implemented in the future.\n' + 'Meanwhile, you can do the following:\n' + '1) Open a terminal window as administrator: ' + 'Right click on the "Command Prompt" shortcut from the star menu and choose "Run as administrator"\n' + '2) Change the directory to "{}".\n'.format(blender_bin_fol) + '3) Run "{}"\n'.format(pip_cmd) + '4) Run "{}"\nGood luck!'.format(install_cmd)) # from src.mmvt_addon.scripts import install_blender_reqs # install_blender_reqs.wrap_blender_call(args.only_verbose) os.chdir(current_dir) except: print(traceback.format_exc()) print("*** Can't install pizco ***")
def install_blender_reqs(): # http://stackoverflow.com/questions/9956741/how-to-install-multiple-python-packages-at-once-using-pip try: blender_fol = utils.get_link_dir(utils.get_links_dir(), 'blender') resource_fol = utils.get_resources_fol() # Get pip blender_bin_fol = op.join(utils.get_parent_fol(blender_fol), 'Resources', '2.78', 'python', 'bin') if utils.is_osx() else \ glob.glob(op.join(blender_fol, '2.7?', 'python'))[0] python_exe = 'python.exe' if utils.is_windows() else 'python3.5m' current_dir = os.getcwd() os.chdir(blender_bin_fol) # if utils.is_osx(): cmd = '{} {}'.format(op.join('bin', python_exe), op.join(resource_fol, 'get-pip.py')) # elif utils.is_linux(): # cmd = '{} {}'.format(op.join(blender_bin_fol, 'python3.5m'), op.join(resource_fol, 'get-pip.py')) # else: # print('No pizco for windows yet...') # return utils.run_script(cmd) # install blender reqs: if not utils.is_windows(): cmd = '{} install zmq pizco scipy mne joblib tqdm nibabel matplotlib'.format( op.join('bin', 'pip')) utils.run_script(cmd) else: print( 'Sorry, installing external python libs in python will be implemented in the future' ) # from src.mmvt_addon.scripts import install_blender_reqs # install_blender_reqs.wrap_blender_call(args.only_verbose) os.chdir(current_dir) except: print(traceback.format_exc()) print("*** Can't install pizco ***")
def install_blender_reqs(blender_fol='', gui=True): # http://stackoverflow.com/questions/9956741/how-to-install-multiple-python-packages-at-once-using-pip try: if blender_fol == '': blender_fol = utils.get_link_dir(utils.get_links_dir(), 'blender') resource_fol = utils.get_resources_fol() blender_bin_fol, python_exe = get_blender_python_exe(blender_fol, gui) current_dir = os.getcwd() os.chdir(blender_bin_fol) # install blender reqs: pip_cmd = '{} {}'.format(op.join('bin', python_exe), op.join(resource_fol, 'get-pip.py')) reqs = 'matplotlib zmq pizco scipy mne joblib tqdm nibabel pdfkit decorator scikit-learn' if not utils.is_windows(): utils.run_script(pip_cmd) install_cmd = '{} install {}'.format(op.join('bin', 'pip'), reqs) utils.run_script(install_cmd) else: # https://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script install_cmd = '{} install '.format(op.join('Scripts', 'pip'), reqs) print( 'Sorry, automatically installing external python libs in python will be implemented in the future.\n' + 'Meanwhile, you can do the following:\n' + '1) Open a terminal window as administrator: ' + 'Right click on the "Command Prompt" shortcut from the star menu and choose "Run as administrator"\n' + '2) Change the directory to "{}".\n'.format(blender_bin_fol) + '3) Run "{}"\n'.format(pip_cmd) + '4) Run "{}"\nGood luck!'.format(install_cmd)) # from src.mmvt_addon.scripts import install_blender_reqs # install_blender_reqs.wrap_blender_call(args.only_verbose) os.chdir(current_dir) except: print(traceback.format_exc()) print("*** Can't install pizco ***")
def create_real_folder(real_fol): try: if real_fol == '': real_fol = utils.get_resources_fol() utils.make_dir(real_fol) except: print('Error with creating the folder "{}"'.format(real_fol)) print(traceback.format_exc())
def copy_resources_files(mmvt_root_dir, overwrite=True, only_verbose=False): resource_dir = utils.get_resources_fol() utils.make_dir(op.join(op.join(mmvt_root_dir, 'color_maps'))) files = [ 'aparc.DKTatlas40_groups.csv', 'atlas.csv', 'sub_cortical_codes.txt', 'FreeSurferColorLUT.txt', 'empty_subject.blend', 'high_level_atlas.csv' ] cm_files = glob.glob(op.join(resource_dir, 'color_maps', '*.npy')) all_files_exist = utils.all( [op.isfile(op.join(mmvt_root_dir, file_name)) for file_name in files]) all_cm_files_exist = utils.all([ op.isfile( op.join(mmvt_root_dir, 'color_maps', '{}.npy'.format(utils.namebase(fname)))) for fname in cm_files ]) if all_files_exist and all_cm_files_exist and not overwrite: if only_verbose: print('All files exist!') return True if not all_cm_files_exist or overwrite: for color_map_file in glob.glob( op.join(resource_dir, 'color_maps', '*.npy')): new_file_name = op.join(mmvt_root_dir, 'color_maps', color_map_file.split(op.sep)[-1]) # print('Copy {} to {}'.format(color_map_file, new_file_name)) print('Coping {} to {}'.format(color_map_file, new_file_name)) if not only_verbose: try: shutil.copy(color_map_file, new_file_name) except: print('Can\'t copy {} to {}!'.format( color_map_file, new_file_name)) if not all_files_exist or overwrite: for file_name in files: print('Copying {} to {}'.format(op.join(resource_dir, file_name), op.join(mmvt_root_dir, file_name))) if not only_verbose: local_fname = op.join(resource_dir, file_name) if op.isfile(op.join(resource_dir, file_name)): try: shutil.copy(local_fname, op.join(mmvt_root_dir, file_name)) except: print('Can\'t copy {}'.format(file_name)) else: print( '{} is missing, please update your code from github (git pull)' .format(op.join(resource_dir, file_name))) return utils.all( [op.isfile(op.join(mmvt_root_dir, file_name)) for file_name in files])
def copy_resources_files(mmvt_root_dir, only_verbose=False): resource_dir = utils.get_resources_fol() utils.make_dir(op.join(op.join(mmvt_root_dir, 'color_maps'))) files = [ 'aparc.DKTatlas40_groups.csv', 'atlas.csv', 'sub_cortical_codes.txt', 'FreeSurferColorLUT.txt', 'empty_subject.blend', 'high_level_atlas.csv' ] cm_files = glob.glob(op.join(resource_dir, 'color_maps', '*.npy')) all_files_exist = utils.all( [op.isfile(op.join(mmvt_root_dir, file_name)) for file_name in files]) all_cm_files_exist = utils.all([ op.isfile( op.join(mmvt_root_dir, 'color_maps', '{}.npy'.format(utils.namebase(fname)))) for fname in cm_files ]) if all_files_exist and all_cm_files_exist: if only_verbose: print('All files exist!') return True if not all_cm_files_exist: for color_map_file in glob.glob( op.join(resource_dir, 'color_maps', '*.npy')): new_file_name = op.join(mmvt_root_dir, 'color_maps', color_map_file.split(op.sep)[-1]) # print('Copy {} to {}'.format(color_map_file, new_file_name)) if only_verbose: print('Coping {} to {}'.format(color_map_file, new_file_name)) else: shutil.copy(color_map_file, new_file_name) if not all_files_exist: for file_name in files: if only_verbose: print('Copying {} to {}'.format( op.join(resource_dir, file_name), op.join(mmvt_root_dir, file_name))) else: shutil.copy(op.join(resource_dir, file_name), op.join(mmvt_root_dir, file_name)) return utils.all( [op.isfile(op.join(mmvt_root_dir, file_name)) for file_name in files])