本文整理汇总了Python中site.getsitepackages函数的典型用法代码示例。如果您正苦于以下问题:Python getsitepackages函数的具体用法?Python getsitepackages怎么用?Python getsitepackages使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getsitepackages函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
mode = sys.argv[1]
print mode
rootdir = "/Users/kgeorge/Dropbox/cars/tentative"
if mode == "b":
rootdir = "/Users/kgeorge/Dropbox/cars/bad"
elif mode == "c":
rootdir = "/Users/kgeorge/Dropbox/cars/crossvalidate"
builddir = os.path.join(rootdir, "build")
print site.getsitepackages()
for root, dirs, files in os.walk(rootdir):
(h, t) = os.path.split(root)
if t.endswith("_delme"):
continue
for f in files:
(p, e) = os.path.splitext(f)
if ((e.lower() == ".png") or (e.lower() == ".jpg") or (e.lower() == ".jpeg")) and not p.endswith(
"canonical"
):
try:
processImage2(builddir, root, f)
except AttributeError, e:
print e
pass
示例2: test_getsitepackages
def test_getsitepackages(self):
site.PREFIXES = ['xoxo']
dirs = site.getsitepackages()
if sys.platform in ('os2emx', 'riscos'):
self.assertEqual(len(dirs), 1)
wanted = os.path.join('xoxo', 'Lib', 'site-packages')
self.assertEqual(dirs[0], wanted)
elif os.sep == '/':
self.assertEqual(len(dirs), 2)
wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
'site-packages')
self.assertEqual(dirs[0], wanted)
wanted = os.path.join('xoxo', 'lib', 'site-python')
self.assertEqual(dirs[1], wanted)
else:
self.assertEqual(len(dirs), 2)
self.assertEqual(dirs[0], 'xoxo')
wanted = os.path.join('xoxo', 'lib', 'site-packages')
self.assertEqual(dirs[1], wanted)
# let's try the specific Apple location
if (sys.platform == "darwin" and
sysconfig.get_config_var("PYTHONFRAMEWORK")):
site.PREFIXES = ['Python.framework']
dirs = site.getsitepackages()
self.assertEqual(len(dirs), 3)
wanted = os.path.join('/Library', 'Python', sys.version[:3],
'site-packages')
self.assertEqual(dirs[2], wanted)
示例3: build
def build(buildargs=['-y', '-windowed', '--onedir', '--clean', '--icon="icons/desuratools.ico"', '--noupx',
'--version-file=versioninfo.txt'], package=True):
pyinstaller = os.path.join(site.getsitepackages()[0], "Scripts", "pyinstaller-script.py")
dependencies = ['PySide', 'PIL', 'win32api', 'win32gui', 'win32ui', 'win32con', 'requests']
imageformats = os.path.join(site.getsitepackages()[1], "PySide", "plugins", "imageformats")
buildargs.insert(0, 'desuratools.py')
buildargs.insert(0, pyinstaller)
buildargs.insert(0, "python")
dist_folder = os.path.join(os.getcwd(), "dist")
output_folder = os.path.join(os.getcwd(), "dist", "desuratools")
if not os.path.exists(pyinstaller):
raise IOError("PyInstaller is required to build for windows")
print "PyInstaller check passed"
for module in dependencies:
try:
imp.find_module(module)
except ImportError:
raise ImportError("Dependency {0} is required".format(module))
print "Dependency check passed"
print "Building DesuraTools"
subprocess.call(' '.join(buildargs))
print "Copying imageformat plugins"
imageformats_dist = os.path.join(output_folder, "imageformats")
distutils.dir_util.copy_tree(imageformats, imageformats_dist, verbose=1)
print "Copying icon"
images_dist = os.path.join(output_folder, "desuratools_256.png")
shutil.copyfile("desuratools_256.png", images_dist)
if package:
package_app(dist_folder, output_folder)
示例4: find_DST
def find_DST():
"""Find where this package should be installed to.
"""
if SYS_NAME == "Windows":
return os.path.join(site.getsitepackages()[1], PKG_NAME)
elif SYS_NAME in ["Darwin", "Linux"]:
return os.path.join(site.getsitepackages()[0], PKG_NAME)
示例5: test_s_option
def test_s_option(self):
usersite = site.USER_SITE
self.assertIn(usersite, sys.path)
env = os.environ.copy()
rc = subprocess.call([sys.executable, '-c',
'import sys; sys.exit(%r in sys.path)' % usersite],
env=env)
self.assertEqual(rc, 1)
env = os.environ.copy()
rc = subprocess.call([sys.executable, '-s', '-c',
'import sys; sys.exit(%r in sys.path)' % usersite],
env=env)
if usersite == site.getsitepackages()[0]:
self.assertEqual(rc, 1)
else:
self.assertEqual(rc, 0)
env = os.environ.copy()
env["PYTHONNOUSERSITE"] = "1"
rc = subprocess.call([sys.executable, '-c',
'import sys; sys.exit(%r in sys.path)' % usersite],
env=env)
if usersite == site.getsitepackages()[0]:
self.assertEqual(rc, 1)
else:
self.assertEqual(rc, 0)
env = os.environ.copy()
env["PYTHONUSERBASE"] = "/tmp"
rc = subprocess.call([sys.executable, '-c',
'import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))'],
env=env)
self.assertEqual(rc, 1)
示例6: test_getsitepackages
def test_getsitepackages(self):
site.PREFIXES = ['xoxo']
dirs = site.getsitepackages()
if (sys.platform == "darwin" and
sysconfig.get_config_var("PYTHONFRAMEWORK")):
# OS X framework builds
site.PREFIXES = ['Python.framework']
dirs = site.getsitepackages()
self.assertEqual(len(dirs), 2)
wanted = os.path.join('/Library',
sysconfig.get_config_var("PYTHONFRAMEWORK"),
'%d.%d' % sys.version_info[:2],
'site-packages')
self.assertEqual(dirs[1], wanted)
elif os.sep == '/':
# OS X non-framwework builds, Linux, FreeBSD, etc
self.assertEqual(len(dirs), 1)
wanted = os.path.join('xoxo', 'lib',
'python%d.%d' % sys.version_info[:2],
'site-packages')
self.assertEqual(dirs[0], wanted)
else:
# other platforms
self.assertEqual(len(dirs), 2)
self.assertEqual(dirs[0], 'xoxo')
wanted = os.path.join('xoxo', 'lib', 'site-packages')
self.assertEqual(dirs[1], wanted)
示例7: test_getsitepackages
def test_getsitepackages(self):
site.PREFIXES = ["xoxo"]
dirs = site.getsitepackages()
if sys.platform in ("os2emx", "riscos"):
self.assertEqual(len(dirs), 1)
wanted = os.path.join("xoxo", "Lib", "site-packages")
self.assertEquals(dirs[0], wanted)
elif os.sep == "/":
self.assertEqual(len(dirs), 2)
wanted = os.path.join("xoxo", "lib", "python" + sys.version[:3], "site-packages")
self.assertEquals(dirs[0], wanted)
wanted = os.path.join("xoxo", "lib", "site-python")
self.assertEquals(dirs[1], wanted)
else:
self.assertEqual(len(dirs), 2)
self.assertEquals(dirs[0], "xoxo")
wanted = os.path.join("xoxo", "lib", "site-packages")
self.assertEquals(dirs[1], wanted)
# let's try the specific Apple location
if sys.platform == "darwin" and sysconfig.get_config_var("PYTHONFRAMEWORK"):
site.PREFIXES = ["Python.framework"]
dirs = site.getsitepackages()
self.assertEqual(len(dirs), 3)
wanted = os.path.join("/Library", "Python", sys.version[:3], "site-packages")
self.assertEquals(dirs[2], wanted)
示例8: plotgraph
def plotgraph(plotvar, divid, omc, resultfile):
if (resultfile is not None):
checkdygraph = os.path.join(os.getcwd(), 'dygraph-combined.js')
if not os.path.exists(checkdygraph):
if (sys.platform == 'win32'):
try:
sitepath = site.getsitepackages()[1]
dygraphfile = os.path.join(sitepath, 'openmodelica_kernel', 'dygraph-combined.js').replace('\\', '/')
shutil.copy2(dygraphfile, os.getcwd())
# print 'copied file'
except Exception as e:
print(e)
else:
try:
sitepath = site.getsitepackages()[0]
dygraphfile = os.path.join(sitepath, 'openmodelica_kernel', 'dygraph-combined.js').replace('\\', '/')
shutil.copy2(dygraphfile, os.getcwd())
# print 'copied file'
except Exception as e:
print(e)
try:
divheader = " ".join(['<div id=' + str(divid) + '>', '</div>'])
readResult = omc.sendExpression("readSimulationResult(\"" + resultfile + "\",{time," + plotvar + "})")
omc.sendExpression("closeSimulationResultFile()")
plotlabels = ['Time']
exp = '(\s?,\s?)(?=[^\[]*\])|(\s?,\s?)(?=[^\(]*\))'
# print 'inside_plot1'
subexp = re.sub(exp, '$#', plotvar)
plotvalsplit = subexp.split(',')
# print plotvalsplit
for z in range(len(plotvalsplit)):
val = plotvalsplit[z].replace('$#', ',')
plotlabels.append(val)
plotlabel1 = [str(x) for x in plotlabels]
plots = []
for i in range(len(readResult)):
x = readResult[i]
d = []
for z in range(len(x)):
tu = x[z]
d.append((tu,))
plots.append(d)
n = numpy.array(plots)
numpy.set_printoptions(threshold=numpy.inf)
dygraph_array = repr(numpy.hstack(n)).replace('array', ' ').replace('(', ' ').replace(')', ' ')
dygraphoptions = " ".join(['{', 'legend:"always",', 'labels:', str(plotlabel1), '}'])
data = "".join(['<script type="text/javascript"> g = new Dygraph(document.getElementById(' + '"' + str(divid) + '"' + '),', str(dygraph_array), ',', dygraphoptions, ')', '</script>'])
htmlhead = '''<html> <head> <script src="dygraph-combined.js"> </script> </head>'''
divcontent = "\n".join([htmlhead, divheader, str(data),'</html>'])
except BaseException:
error = omc.sendExpression("getErrorString()")
divcontent = "".join(['<p>', error, '</p>'])
else:
divcontent = "".join(['<p>', 'No result File Generated', '</p>'])
return divcontent
示例9: create_singlejar
def create_singlejar(output_path, classpath, runpy):
jars = classpath
jars.extend(find_jython_jars())
site_path = site.getsitepackages()[0]
with JarPth() as jar_pth:
for jar_path in sorted(jar_pth.itervalues()):
jars.append(os.path.join(site_path, jar_path))
with JarCopy(output_path=output_path, runpy=runpy) as singlejar:
singlejar.copy_jars(jars)
log.debug("Copying standard library")
for relpath, realpath in find_jython_lib_files():
singlejar.copy_file(relpath, realpath)
# FOR NOW: copy everything in site-packages into Lib/ in the built jar;
# this is because Jython in standalone mode has the limitation that it can
# only properly find packages under Lib/ and cannot process .pth files
# THIS SHOULD BE FIXED
sitepackage = site.getsitepackages()[0]
# copy top level packages
for item in os.listdir(sitepackage):
path = os.path.join(sitepackage, item)
if path.endswith(".egg") or path.endswith(".egg-info") or path.endswith(".pth") or path == "jars":
continue
log.debug("Copying package %s", path)
for pkg_relpath, pkg_realpath in find_package_libs(path):
log.debug("Copy package file %s %s", pkg_relpath, pkg_realpath)
singlejar.copy_file(os.path.join("Lib", item, pkg_relpath), pkg_realpath)
# copy eggs
for path in read_pth(os.path.join(sitepackage, "easy-install.pth")).itervalues():
relpath = "/".join(os.path.normpath(os.path.join("Lib", path)).split(os.sep)) # ZIP only uses /
path = os.path.realpath(os.path.normpath(os.path.join(sitepackage, path)))
if copy_zip_file(path, singlejar):
log.debug("Copying %s (zipped file)", path) # tiny lie - already copied, but keeping consistent!
continue
log.debug("Copying egg %s", path)
for pkg_relpath, pkg_realpath in find_package_libs(path):
# Filter out egg metadata
parts = pkg_relpath.split(os.sep)
head = parts[0]
if head == "EGG-INFO" or head.endswith(".egg-info"):
continue
singlejar.copy_file(os.path.join("Lib", pkg_relpath), pkg_realpath)
if runpy and os.path.exists(runpy):
singlejar.copy_file("__run__.py", runpy)
示例10: echo_server
def echo_server(address, authkey):
print "loading server"
print sys.executable
print site.getsitepackages()
serv = Listener(address, authkey=authkey)
print "started listener"
while True:
try:
client = serv.accept()
print "got something"
if echo_client(client) == False:
break
except Exception:
traceback.print_exc()
示例11: resDataSave
def resDataSave(bo_url , cmdstr ,workspace_name, passQ = False , dumptype='CSV', dump_filename='dump.csv'):
if passQ == False:
confirmStr= "=============\nSize of data exceeded display limit, dump to csv format? (yes/no)"
import fileinput
print confirmStr
while True:
choice=raw_input()
if choice=="yes" or choice=="y":
break
elif choice=="no" or choice=="n":
return False
else:
print confirmStr
#bo_host = bo_url.split(":")[1][2:]
#bo_port = bo_url.split(":")[2][:-4]
import subprocess
import os
import signal
from distutils.sysconfig import get_python_lib
boshcwd =os.getcwd()
#lib_path = get_python_lib()
import site
lib_path = site.getsitepackages()[0]
# print("lib_path " +lib_path)
if str(workspace_name) == "":
workspace_name = '\"\"'
rest = subprocess.Popen(["python", lib_path + "/dumpRes/borestful.py" , bo_url , cmdstr , str(workspace_name)], stdout=subprocess.PIPE)
tocsv = subprocess.Popen(["python", lib_path + "/dumpRes/bojson2file.py", dumptype, boshcwd + "/" + dump_filename] , stdin=rest.stdout)
print("dumping the data to " + dump_filename + " , type: " + dumptype + " ...")
rest.wait()
tocsv.wait()
return True
示例12: installMissingPackage
def installMissingPackage(packageList):
a = site.getsitepackages()
a = a[0]
a = a.split('/')
for el in a:
if 'python' in el:
b = el.replace('python', '')
b = int(float(b))
os.system('sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose')
if b == 2:
try:
os.system('sudo easy_install numpy scipy Sphinx numpydoc nose pykalman')
os.system('sudo pip install cma')
os.system('sudo easy_install cython')
os.system('sudo pip install distlib')
except:
pass
elif b == 3:
try:
os
os.system('sudo easy_install3 numpy scipy Sphinx numpydoc nose pykalman')
os.system('sudo pip3 install cma')
os.system('sudo easy_install3 cython')
os.system('sudo pip3 install distlib')
except:
pass
os.system('clear')
示例13: __init__
def __init__(self, fileName=None):
self.lexicon = {}
packageFileName = str(distutils.sysconfig.get_python_lib())+"/"+PACKAGE+"/"+LOCAL+"/brill-lexicon.dat"
localFileName = PACKAGE+"/"+LOCAL+"/brill-lexicon.dat"
# allows looking for the package in, eg, /usr/local/lib
siteFileNames = []
for dir in site.getsitepackages():
siteFileName = dir+"/"+PACKAGE+"/"+LOCAL+"/brill-lexicon.dat"
if (os.path.isfile(siteFileName)):
fileName = siteFileName
break
if fileName != None:
pass
elif os.path.isfile(packageFileName):
fileName = packageFileName
elif os.path.isfile(localFileName):
fileName = localFileName
else:
sys.stderr.write("ERROR: Could not find default Brill lexicon.")
lexiconFile = open(fileName, "r")
for line in lexiconFile.readlines():
if not line.startswith("#"):
col = line.split()
self.lexicon[col[0]] = col[1:]
示例14: fetch_Landsat8_scene_list
def fetch_Landsat8_scene_list():
"""
Simple downloads and extracts the most recent version of the scene_list
text file for reference
http://landsat-pds.s3.amazonaws.com/scene_list.gz
:return scene_list_text_data: returns a text data object with all
the data on scene inventory on amazon WS.
"""
print("Updating scene list")
# define save path for new scene list
directory = site.getsitepackages()[1]
gz_path = "{0}/dnppy/landsat/metadata/scene_list.gz".format(directory)
txt_path = "{0}/dnppy/landsat/metadata/scene_list.txt".format(directory)
# download then extract the gz file to a txt file.
download_url("http://landsat-pds.s3.amazonaws.com/scene_list.gz", gz_path)
with gzip.open(gz_path,'rb') as gz:
content = gz.read()
with open(txt_path, 'wb+') as f:
f.writelines(content)
# build a new text data object from the fresh scene list
scene_list_text_data = textio.text_data()
scene_list_text_data.read_csv(txt_path, delim = ",", has_headers = True)
return scene_list_text_data
示例15: _get_default_library_roots
def _get_default_library_roots(cls):
# Provide sensible defaults if not in env vars.
import site
roots = [sys.prefix]
if hasattr(sys, 'base_prefix'):
roots.append(sys.base_prefix)
if hasattr(sys, 'real_prefix'):
roots.append(sys.real_prefix)
if hasattr(site, 'getusersitepackages'):
site_paths = site.getusersitepackages()
if isinstance(site_paths, (list, tuple)):
for site_path in site_paths:
roots.append(site_path)
else:
roots.append(site_paths)
if hasattr(site, 'getsitepackages'):
site_paths = site.getsitepackages()
if isinstance(site_paths, (list, tuple)):
for site_path in site_paths:
roots.append(site_path)
else:
roots.append(site_paths)
for path in sys.path:
if os.path.exists(path) and os.path.basename(path) == 'site-packages':
roots.append(path)
return sorted(set(roots))