Python configuration

From wikinotes
Revision as of 15:05, 13 February 2021 by Will (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Introspection

Version Info

import sys
print(sys.version_info)


Project Configuration

There are a few formats available to consolidate project dotfiles.
See helpful https://snarky.ca/what-the-heck-is-pyproject-toml/

python pyproject.toml ${PROJECT}/pyproject.toml PEP-518
python setup.cfg ${PROJECT}/setup.cfg PEP-390


Interpreter

Environment Variables

$PYTHONPATH Where python looks for modules
$PYTHONSTARTUP similar to .profile or .bashrc. Sets up interpreter environment
$PYTHONHOME points to the root python directory. typically either /usr/lib/pythonX.X or C:/pythonX.X

See Also: https://docs.python.org/2/using/cmdline.html

Startup

~/.local/lib/python2.7/site-packages/sitecustomize.py modify startup

You can customize the python startup sequence (both interactive and noninteractive) by creating a custom sitecustomize.py file in your user_site directory. (which can be obtained with import site;print(site.USER_SITE) )

site-packages

You can add user-specific site-packages to a python install with the site module (with the advantage that *.pth files will be evaluated).

import site
site.add_sitedir('/tmp/my-site-dir')

Default Interpreter

Change the following registry-key in Windows. Alternatively, change the order that python appears on your $PATH variable.

HKLM\SOFTWARE\Python\PythonCore\2.7\InstallPath
  type: REG_SZ
  data: C:\Python2.7.3_x64\

Python Extensions

Python modules that require compiling must be compiled with the same compiler that python itself was built with. Microsoft distributes a minimalist compiler environment specifically for use with python/pip.

http://aka.ms/vcpython27