Create either sitecustomize.py
or usercustomize.py
and append to site.PREFIXES
import site
SITEPKGS = '/usr/local/lib/python2.7/site-packages'
site.addsitedir(SITEPKGS)
site.PREFIXES += ['/usr/local']
set PYTHONUSERBASE
to /usr/local
which will switch the location of the user's base Python directory from ~/.local
to whatever you set it to. Note: This would disable your packages installed into ~/.local/lib/python2.7/site-packages
.
export PYTHONUSERBASE = /usr/local
set PYTHONPATH
to prepend /usr/local/lib/python2.7/site-packages
which would add it to sys.path
.
export PYTHONPATH = /usr/local / lib / python2 .7 / site - packages: $PYTHONPATH
set PYTHONUSERBASE
to /usr/local
which will switch the location of the user's base Python directory from ~/.local
to whatever you set it to. Note: This would disable your packages installed into ~/.local/lib/python2.7/site-packages
.
export PYTHONUSERBASE = /usr/local
set PYTHONPATH
to prepend /usr/local/lib/python2.7/site-packages
which would add it to sys.path
.
export PYTHONPATH = /usr/local / lib / python2 .7 / site - packages: $PYTHONPATH
© 2022 Tech Notes Help
Create either sitecustomize.py
or usercustomize.py
and append to site.PREFIXES
import site
SITEPKGS = /usr/local / lib / python2 .7 / site - packages
site.addsitedir(SITEPKGS)
site.PREFIXES += [/usr/local]
set PYTHONUSERBASE
to /usr/local
which will switch the location of the users base Python directory from ~/.local
to whatever you set it to. Note: This would disable your packages installed into ~/.local/lib/python2.7/site-packages
.
export PYTHONUSERBASE = /usr/local
set PYTHONPATH
to prepend /usr/local/lib/python2.7/site-packages
which would add it to sys.path
.
export PYTHONPATH = /usr/local / lib / python2 .7 / site - packages: $PYTHONPATH
set PYTHONUSERBASE
to /usr/local
which will switch the location of the users base Python directory from ~/.local
to whatever you set it to. Note: This would disable your packages installed into ~/.local/lib/python2.7/site-packages
.
export PYTHONUSERBASE = /usr/local
set PYTHONPATH
to prepend /usr/local/lib/python2.7/site-packages
which would add it to sys.path
.
export PYTHONPATH = /usr/local / lib / python2 .7 / site - packages: $PYTHONPATH
For example, suppose sys.prefix and sys.exec_prefix are set to /usr/local. The Python X.Y library is then installed in /usr/local/lib/pythonX.Y. Suppose this has a subdirectory /usr/local/lib/pythonX.Y/site-packages with three subsubdirectories, foo, bar and spam, and two path configuration files, foo.pth and bar.pth. Assume foo.pth contains the following:,Note that for some non-Unix systems, sys.prefix and sys.exec_prefix are empty, and the path manipulations are skipped; however the import of sitecustomize and usercustomize is still attempted.,Adds all the standard site-specific directories to the module search path. This function is called automatically when this module is imported, unless the Python interpreter was started with the -S flag.,Add a directory to sys.path and process its .pth files. Typically used in sitecustomize or usercustomize (see above).
# foo package configuration foo bar bletch
# bar package configuration bar
/usr/local / lib / pythonX.Y / site - packages / bar / usr / local / lib / pythonX.Y / site - packages / foo
$ python3 - m site--user - site / home / user / .local / lib / python3 .3 / site - packages
The easiest way to change it is to add a file /usr/local/lib/python2.6/dist-packages/site-packages.pth containing ../site-packages., 1 thanks, works perfectly :) (I ended up adding a .pth file to /usr/local/python2.6/dist-packages, containing "../site-packages") – Latanius Feb 18, 2011 at 21:40 ,On a Ubuntu (10.10) system, I have a Python package that installs itself into /usr/local/lib/python2.6/site-packages/. This isn't contained in the default path (sys.path). How do I add this directory to the path?,/usr/lib/python2.6/dist-packages/site.py (Change 2.6 to your version of Python.)
You might create a new file called /etc/profile.d/local_python.sh
with the contents
PYTHONPATH = "/usr/local/lib/python2.6/site-packages/": "${PYTHONPATH}"
export PYTHONPATH
For example, if you want to import the suds
module which is available as an .egg
file:
egg_path = '/home/shahid/suds_2.4.egg' sys.path.append(egg_path) import suds #...rest of code
The sysconfig Python module from the standard library defines several installation schemes. By default, the installation scheme used on Fedora 36 when installing Python packages using root privileges (for example via sudo) is {prefix}/local/lib(64)/python3.10/site-packages/ (where {prefix} is defined as /usr by default). When Python itself runs from a Python virtual environment or when building RPM packages, the installation scheme is {prefix}/lib(64)/python3.10/site-packages/ (it does not include /local/).,The only supported way to explicitly install a Python package directly to /usr/lib(64)/python3.10/site-packages/ is to build an RPM package with it and install it. Python checks the $RPM_BUILD_ROOT environment variable and selects the rpm_prefix installation scheme when it is set.,To install it to ~/myroot/usr/lib/python3.10/site-packages/, the simulated RPM environment can be used:,If your Python code uses installation schemes to determine paths to be used in created virtual environments, and the Python interpreter executing that code does not run from a Python virtual environment itself, the paths will not match.
>>>
import sysconfig
>>>
for key in sysconfig.get_path_names():
...print(f '{key} = {sysconfig.get_path(key)}')
...
stdlib = /usr/lib64 / python3 .10
platstdlib = /usr/lib64 / python3 .10
purelib = /usr/lib / python3 .10 / site - packages
platlib = /usr/lib64 / python3 .10 / site - packages
include = /usr/include / python3 .10
scripts = /usr/bin
data = /usr
>>>
import sysconfig
>>>
for key in sysconfig.get_path_names():
...print(f '{key} = {sysconfig.get_path(key)}')
...
stdlib = /usr/lib64 / python3 .10
platstdlib = /usr/lib64 / python3 .10
purelib = /usr/local / lib / python3 .10 / site - packages
platlib = /usr/local / lib64 / python3 .10 / site - packages
include = /usr/include / python3 .10
scripts = /usr/local / bin
data = /usr/local
>>>
for key in sysconfig.get_path_names():
...print(f '{key} = {sysconfig.get_path(key, scheme="rpm_prefix")}')
...
stdlib = /usr/lib64 / python3 .10
platstdlib = /usr/lib64 / python3 .10
purelib = /usr/lib / python3 .10 / site - packages
platlib = /usr/lib64 / python3 .10 / site - packages
include = /usr/include / python3 .10
scripts = /usr/bin
data = /usr
$ sudo pip install--prefix / usr Pello
$ sudo pip install--prefix / usr / local Pello
$ sudo env RPM_BUILD_ROOT = / pip install Pello