def get_package_name(filepath):
 pkg_name = []
 while (('site-packages' in filepath) or ('dist-packages' in filepath)):
  (filepath, p2) = os.path.split(filepath)
  if (p2 in ('site-packages', 'dist-packages')):
   break
  pkg_name.append(p2)
 if (not pkg_name):
  return 'pandas'
 pkg_name.reverse()
 if pkg_name[0].endswith('.egg'):
  pkg_name.pop(0)
 return '.'.join(pkg_name)

def get_package_name ( filepath ) : pkg_name = [ ] while ( ( 'site-packages' in filepath ) or ( 'dist-packages' in filepath ) ) : ( filepath , p2 ) = os . path . split ( filepath ) if ( p2 in ( 'site-packages' , 'dist-packages' ) ) : break pkg_name . append ( p2 ) if ( not pkg_name ) : return 'pandas' pkg_name . reverse ( ) if pkg_name [ 0 ] . endswith ( '.egg' ) : pkg_name . pop ( 0 ) return '.' . join ( pkg_name )
get "name" from a package with a workaround when its not defined .