Script to copy files to Anaconda paths so can import and use scripts


In [69]:
module_name = 'bradlib'

find main path for install


In [70]:
from distutils.sysconfig import get_python_lib #; print(get_python_lib())

In [71]:
path_main = get_python_lib()

In [72]:
path_main


Out[72]:
'C:\\Anaconda3\\Lib\\site-packages'

In [73]:
path_main.split('Anaconda3')


Out[73]:
['C:\\', '\\Lib\\site-packages']

make list of paths need to copy files to & add main path


In [ ]:


In [74]:
dest_paths_list = []

In [75]:
dest_paths_list.append(path_main + '\\' + module_name)

In [76]:
dest_paths_list


Out[76]:
['C:\\Anaconda3\\Lib\\site-packages\\bradlib']

add paths to list for conda environments currently available

MAKE SURE HAS 'module name' AT END OF PATH!!


In [77]:
x = !conda env list

In [78]:
#x[2:-2]

In [79]:
print('------------------------------------------------')
print('Conda envrionments found which will install to:')
for i in x[2:-2]:
    y = i.split(' ')
    print(y[0])
    new_path = path_main.split('Anaconda3')[0] +'Anaconda3\\envs\\'+y[0]+'\\Lib\\site-packages\\' + module_name
    #print(new_path)
    dest_paths_list.append(new_path)


------------------------------------------------
Conda envrionments found which will install to:
flow
flowm
ml
ngcm
ngcm17
ngcm2
stable
stable2
udac

In [80]:
#dest_paths_list

function to copy files to list of paths


In [81]:
import os

In [82]:
def copy_to_paths(source,dest):
    """
    Function takes source and destination folders and copies files.
    #Source and dest needed in fomrat below: 
    #source = ".\\bradlib"
    #dest = "C:\\Users\\bjk1y13\\dev\\garbage\\bradlib"
    """
    #### Remove __pycache__ folder as is not required
    pycache_loc = source + "\\__pycache__"
    if os.path.isdir(pycache_loc) == True:
        print("__pycache__ found in source and being deleted...")
        !rmdir $pycache_loc /S /Q
                
    #### Copy files to new destination
    
    print('------------------------')
    print('Destination: ', dest)
    print('---------')
    folder_exists = os.path.isdir(dest)
    if folder_exists == True:
        print('Folder exists')
        ### delete older version folder
        print('Deleting old folder...')
        !rmdir $dest /S /Q
        print('Copying new folder...')
        !xcopy $source $dest /E /I
        
    elif folder_exists == False:
        print('Folder does not exist')
        print('Copying new folder...')
        !xcopy $source $dest /E /I
    else:
        print('Something has gone wrong!!')
    
    print('COMPLETE')
    print('------------------------')
    return

In [83]:
source = ".\\" + module_name

In [ ]:

Run code for each location


In [84]:
for destination in dest_paths_list:
    print(destination)
    copy_to_paths(source, destination)


C:\Anaconda3\Lib\site-packages\bradlib
------------------------
Destination:  C:\Anaconda3\Lib\site-packages\bradlib
---------
Folder exists
Deleting old folder...
Copying new folder...
.\bradlib\__init__.py
.\bradlib\dftools\encode_columns.py
.\bradlib\dftools\explore_lin_reg.py
.\bradlib\dftools\pd_tidy_column_heads.py
.\bradlib\dftools\__init__.py
.\bradlib\dftools\__pycache__\pd_tidy_column_heads.cpython-35.pyc
.\bradlib\dftools\__pycache__\__init__.cpython-35.pyc
.\bradlib\misc_test\hello.py
.\bradlib\misc_test\sqrt_value.py
.\bradlib\misc_test\square_value.py
.\bradlib\misc_test\__init__.py
.\bradlib\misc_test\__pycache__\hello.cpython-34.pyc
.\bradlib\misc_test\__pycache__\hello.cpython-35.pyc
.\bradlib\misc_test\__pycache__\sqrt_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\square_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-34.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-35.pyc
17 File(s) copied
COMPLETE
------------------------
C:\Anaconda3\envs\flow\Lib\site-packages\bradlib
------------------------
Destination:  C:\Anaconda3\envs\flow\Lib\site-packages\bradlib
---------
Folder exists
Deleting old folder...
Copying new folder...
.\bradlib\__init__.py
.\bradlib\dftools\encode_columns.py
.\bradlib\dftools\explore_lin_reg.py
.\bradlib\dftools\pd_tidy_column_heads.py
.\bradlib\dftools\__init__.py
.\bradlib\dftools\__pycache__\pd_tidy_column_heads.cpython-35.pyc
.\bradlib\dftools\__pycache__\__init__.cpython-35.pyc
.\bradlib\misc_test\hello.py
.\bradlib\misc_test\sqrt_value.py
.\bradlib\misc_test\square_value.py
.\bradlib\misc_test\__init__.py
.\bradlib\misc_test\__pycache__\hello.cpython-34.pyc
.\bradlib\misc_test\__pycache__\hello.cpython-35.pyc
.\bradlib\misc_test\__pycache__\sqrt_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\square_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-34.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-35.pyc
17 File(s) copied
COMPLETE
------------------------
C:\Anaconda3\envs\flowm\Lib\site-packages\bradlib
------------------------
Destination:  C:\Anaconda3\envs\flowm\Lib\site-packages\bradlib
---------
Folder exists
Deleting old folder...
Copying new folder...
.\bradlib\__init__.py
.\bradlib\dftools\encode_columns.py
.\bradlib\dftools\explore_lin_reg.py
.\bradlib\dftools\pd_tidy_column_heads.py
.\bradlib\dftools\__init__.py
.\bradlib\dftools\__pycache__\pd_tidy_column_heads.cpython-35.pyc
.\bradlib\dftools\__pycache__\__init__.cpython-35.pyc
.\bradlib\misc_test\hello.py
.\bradlib\misc_test\sqrt_value.py
.\bradlib\misc_test\square_value.py
.\bradlib\misc_test\__init__.py
.\bradlib\misc_test\__pycache__\hello.cpython-34.pyc
.\bradlib\misc_test\__pycache__\hello.cpython-35.pyc
.\bradlib\misc_test\__pycache__\sqrt_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\square_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-34.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-35.pyc
17 File(s) copied
COMPLETE
------------------------
C:\Anaconda3\envs\ml\Lib\site-packages\bradlib
------------------------
Destination:  C:\Anaconda3\envs\ml\Lib\site-packages\bradlib
---------
Folder exists
Deleting old folder...
Copying new folder...
.\bradlib\__init__.py
.\bradlib\dftools\encode_columns.py
.\bradlib\dftools\explore_lin_reg.py
.\bradlib\dftools\pd_tidy_column_heads.py
.\bradlib\dftools\__init__.py
.\bradlib\dftools\__pycache__\pd_tidy_column_heads.cpython-35.pyc
.\bradlib\dftools\__pycache__\__init__.cpython-35.pyc
.\bradlib\misc_test\hello.py
.\bradlib\misc_test\sqrt_value.py
.\bradlib\misc_test\square_value.py
.\bradlib\misc_test\__init__.py
.\bradlib\misc_test\__pycache__\hello.cpython-34.pyc
.\bradlib\misc_test\__pycache__\hello.cpython-35.pyc
.\bradlib\misc_test\__pycache__\sqrt_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\square_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-34.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-35.pyc
17 File(s) copied
COMPLETE
------------------------
C:\Anaconda3\envs\ngcm\Lib\site-packages\bradlib
------------------------
Destination:  C:\Anaconda3\envs\ngcm\Lib\site-packages\bradlib
---------
Folder exists
Deleting old folder...
Copying new folder...
.\bradlib\__init__.py
.\bradlib\dftools\encode_columns.py
.\bradlib\dftools\explore_lin_reg.py
.\bradlib\dftools\pd_tidy_column_heads.py
.\bradlib\dftools\__init__.py
.\bradlib\dftools\__pycache__\pd_tidy_column_heads.cpython-35.pyc
.\bradlib\dftools\__pycache__\__init__.cpython-35.pyc
.\bradlib\misc_test\hello.py
.\bradlib\misc_test\sqrt_value.py
.\bradlib\misc_test\square_value.py
.\bradlib\misc_test\__init__.py
.\bradlib\misc_test\__pycache__\hello.cpython-34.pyc
.\bradlib\misc_test\__pycache__\hello.cpython-35.pyc
.\bradlib\misc_test\__pycache__\sqrt_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\square_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-34.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-35.pyc
17 File(s) copied
COMPLETE
------------------------
C:\Anaconda3\envs\ngcm17\Lib\site-packages\bradlib
------------------------
Destination:  C:\Anaconda3\envs\ngcm17\Lib\site-packages\bradlib
---------
Folder exists
Deleting old folder...
Copying new folder...
.\bradlib\__init__.py
.\bradlib\dftools\encode_columns.py
.\bradlib\dftools\explore_lin_reg.py
.\bradlib\dftools\pd_tidy_column_heads.py
.\bradlib\dftools\__init__.py
.\bradlib\dftools\__pycache__\pd_tidy_column_heads.cpython-35.pyc
.\bradlib\dftools\__pycache__\__init__.cpython-35.pyc
.\bradlib\misc_test\hello.py
.\bradlib\misc_test\sqrt_value.py
.\bradlib\misc_test\square_value.py
.\bradlib\misc_test\__init__.py
.\bradlib\misc_test\__pycache__\hello.cpython-34.pyc
.\bradlib\misc_test\__pycache__\hello.cpython-35.pyc
.\bradlib\misc_test\__pycache__\sqrt_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\square_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-34.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-35.pyc
17 File(s) copied
COMPLETE
------------------------
C:\Anaconda3\envs\ngcm2\Lib\site-packages\bradlib
------------------------
Destination:  C:\Anaconda3\envs\ngcm2\Lib\site-packages\bradlib
---------
Folder exists
Deleting old folder...
Copying new folder...
.\bradlib\__init__.py
.\bradlib\dftools\encode_columns.py
.\bradlib\dftools\explore_lin_reg.py
.\bradlib\dftools\pd_tidy_column_heads.py
.\bradlib\dftools\__init__.py
.\bradlib\dftools\__pycache__\pd_tidy_column_heads.cpython-35.pyc
.\bradlib\dftools\__pycache__\__init__.cpython-35.pyc
.\bradlib\misc_test\hello.py
.\bradlib\misc_test\sqrt_value.py
.\bradlib\misc_test\square_value.py
.\bradlib\misc_test\__init__.py
.\bradlib\misc_test\__pycache__\hello.cpython-34.pyc
.\bradlib\misc_test\__pycache__\hello.cpython-35.pyc
.\bradlib\misc_test\__pycache__\sqrt_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\square_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-34.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-35.pyc
17 File(s) copied
COMPLETE
------------------------
C:\Anaconda3\envs\stable\Lib\site-packages\bradlib
------------------------
Destination:  C:\Anaconda3\envs\stable\Lib\site-packages\bradlib
---------
Folder exists
Deleting old folder...
Copying new folder...
.\bradlib\__init__.py
.\bradlib\dftools\encode_columns.py
.\bradlib\dftools\explore_lin_reg.py
.\bradlib\dftools\pd_tidy_column_heads.py
.\bradlib\dftools\__init__.py
.\bradlib\dftools\__pycache__\pd_tidy_column_heads.cpython-35.pyc
.\bradlib\dftools\__pycache__\__init__.cpython-35.pyc
.\bradlib\misc_test\hello.py
.\bradlib\misc_test\sqrt_value.py
.\bradlib\misc_test\square_value.py
.\bradlib\misc_test\__init__.py
.\bradlib\misc_test\__pycache__\hello.cpython-34.pyc
.\bradlib\misc_test\__pycache__\hello.cpython-35.pyc
.\bradlib\misc_test\__pycache__\sqrt_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\square_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-34.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-35.pyc
17 File(s) copied
COMPLETE
------------------------
C:\Anaconda3\envs\stable2\Lib\site-packages\bradlib
------------------------
Destination:  C:\Anaconda3\envs\stable2\Lib\site-packages\bradlib
---------
Folder exists
Deleting old folder...
Copying new folder...
.\bradlib\__init__.py
.\bradlib\dftools\encode_columns.py
.\bradlib\dftools\explore_lin_reg.py
.\bradlib\dftools\pd_tidy_column_heads.py
.\bradlib\dftools\__init__.py
.\bradlib\dftools\__pycache__\pd_tidy_column_heads.cpython-35.pyc
.\bradlib\dftools\__pycache__\__init__.cpython-35.pyc
.\bradlib\misc_test\hello.py
.\bradlib\misc_test\sqrt_value.py
.\bradlib\misc_test\square_value.py
.\bradlib\misc_test\__init__.py
.\bradlib\misc_test\__pycache__\hello.cpython-34.pyc
.\bradlib\misc_test\__pycache__\hello.cpython-35.pyc
.\bradlib\misc_test\__pycache__\sqrt_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\square_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-34.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-35.pyc
17 File(s) copied
COMPLETE
------------------------
C:\Anaconda3\envs\udac\Lib\site-packages\bradlib
------------------------
Destination:  C:\Anaconda3\envs\udac\Lib\site-packages\bradlib
---------
Folder exists
Deleting old folder...
Copying new folder...
.\bradlib\__init__.py
.\bradlib\dftools\encode_columns.py
.\bradlib\dftools\explore_lin_reg.py
.\bradlib\dftools\pd_tidy_column_heads.py
.\bradlib\dftools\__init__.py
.\bradlib\dftools\__pycache__\pd_tidy_column_heads.cpython-35.pyc
.\bradlib\dftools\__pycache__\__init__.cpython-35.pyc
.\bradlib\misc_test\hello.py
.\bradlib\misc_test\sqrt_value.py
.\bradlib\misc_test\square_value.py
.\bradlib\misc_test\__init__.py
.\bradlib\misc_test\__pycache__\hello.cpython-34.pyc
.\bradlib\misc_test\__pycache__\hello.cpython-35.pyc
.\bradlib\misc_test\__pycache__\sqrt_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\square_value.cpython-35.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-34.pyc
.\bradlib\misc_test\__pycache__\__init__.cpython-35.pyc
17 File(s) copied
COMPLETE
------------------------

In [85]:
print('INSTALL SUCCESSFUL')


INSTALL SUCCESSFUL

In [ ]: