8 examples of 'add python to path ubuntu' in Python

Every line of 'add python to path ubuntu' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
6def _add_to_python_path(p):
7 if p not in sys.path: sys.path.append(p)
42def addSysPythonPath():
43 import appinfo
44 import os
45
46 def addpath(p):
47 try:
48 p = os.path.normpath(p)
49 p = os.path.abspath(p)
50 except OSError: return
51 if not os.path.exists(p): return
52 if p not in sys.path: sys.path += [p]
53
54 paths = os.environ.get("PYTHONPATH", "").split(":")
55 for p in paths:
56 addpath(p.strip())
57
58 versionStr = ".".join(map(str, sys.version_info[0:2]))
59
60 if sys.platform == "darwin":
61 addpath("/usr/local/Frameworks/Python.framework/Versions/%s/lib/python%s/lib-dynload/" % (versionStr, versionStr))
62 addpath("/System/Frameworks/Python.framework/Versions/%s/lib/python%s/lib-dynload/" % (versionStr, versionStr))
63
64 # This will add other custom paths, e.g. for eggs.
65 import site
66 site.main()
67
68 def addsitedir(d):
69 try:
70 d = os.path.normpath(d)
71 d = os.path.abspath(d)
72 except OSError: return
73 if os.path.exists(d):
74 site.addsitedir(d)
75
76 # We still might miss some site-dirs.
77 addsitedir("/usr/local/lib/python%s/site-packages" % versionStr)
78 addsitedir("/usr/lib/python%s/site-packages" % versionStr)
79 if sys.platform == "darwin":
80 addsitedir("/Library/Python/%s/site-packages" % versionStr)
81
82 if not appinfo.args.forkExecProc:
83 print("Python paths after: %r" % sys.path)
206def add_path_to_sys_path(path):
207 """
208 @type path: str
209 """
210 _logger.debug('Adding path to sys.path: %s' % path)
211 if path in sys.path:
212 return
213 sys.path.append(path)
31def addLibraryPath(path):
32 """
33 Append the past string or list of strings to the python library path.
34 Passed strings can either be relative: ../path/to/library
35 or absolute: /path/to/library
36 """
37 base = os.path.dirname(sys.argv[0])
38
39 # If script was not started with ./
40 if base == '': base = '.'
41
42 # Allow either a single string or list to be passed
43 if not isinstance(path,list):
44 path = [path]
45
46 for p in path:
47
48 # Full path
49 if p[0] == '/':
50 np = p
51
52 # Relative path
53 else:
54 np = base + '/' + p
55
56 # Verify directory or archive exists and is readable
57 if '.zip/' in np:
58 tst = np[:np.find('.zip/')+4]
59 else:
60 tst = np
61
62 if not os.access(tst,os.R_OK):
63 raise Exception("Library path {} does not exist or is not readable".format(tst))
64 sys.path.append(np)
9@utils.memoized
10def getNeededPythonPath():
11 testDir = os.path.dirname(__file__)
12 base = os.path.dirname(testDir)
13 vdsmModPath = os.path.join(base, 'lib')
14 vdsmPath = os.path.join(base, 'vdsm')
15 cliPath = os.path.join(base, 'client')
16 pyPath = "PYTHONPATH=" + ':'.join([base, vdsmPath, cliPath, vdsmModPath])
17 return pyPath
27def addpath(path):
28 """
29 Add a directory to the python path environment, and to the PYTHONPATH
30 environment variable for subprocesses.
31 """
32 path = abspath(path)
33 if 'PYTHONPATH' in os.environ:
34 PYTHONPATH = path + os.pathsep + os.environ['PYTHONPATH']
35 else:
36 PYTHONPATH = path
37 os.environ['PYTHONPATH'] = PYTHONPATH
38 sys.path.insert(0, path)
18def add_path(p):
19 if p in sys.path:
20 sys.path.remove(p)
21 sys.path.insert(0, p)
24def addpath():
25 try:
26 import dynts
27 except ImportError:
28 p = lambda x : os.path.split(x)[0]
29 path = p(p(os.path.abspath(__file__)))
30 sys.path.insert(0, path)

Related snippets