Python configuration: Difference between revisions
No edit summary |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= Documentation = | |||
<blockquote> | |||
{| class="wikitable" | |||
|- | |||
| environment variables || https://docs.python.org/release/3.10.0/using/cmdline.html#environment-variables | |||
|- | |||
| compile options || https://docs.python.org/release/3.10.0/using/configure.html | |||
|- | |||
|} | |||
</blockquote><!-- Documentation --> | |||
= Introspection = | = Introspection = | ||
Line 8: | Line 19: | ||
print(sys.version_info) | print(sys.version_info) | ||
</source> | </source> | ||
<syntaxhighlight lang="bash"> | |||
python -V | |||
</syntaxhighlight> | |||
</blockquote><!-- python information --> | </blockquote><!-- python information --> | ||
</blockquote><!-- Introspection --> | </blockquote><!-- Introspection --> | ||
= Project Configuration = | = Project Configuration = | ||
Line 30: | Line 44: | ||
== Environment Variables == | == Environment Variables == | ||
<blockquote> | <blockquote> | ||
https://docs.python.org/release/3.10.0/using/cmdline.html#environment-variables | |||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
| <code>$PYTHONPATH</code> | | <code>$PYTHONPATH</code> || Where python looks for modules | ||
|- | |||
| <code>$PYTHONSTARTUP</code> || similar to .profile or .bashrc. Sets up interpreter environment | |||
|- | |- | ||
| <code>$ | | <code>$PYTHONHOME</code> || points to the root python directory. typically either <code>/usr/lib/pythonX.X</code> or <code>C:/pythonX.X</code> | ||
|- | |- | ||
| <code>$ | | <code>$PYTHONWARNINGS=ignore</code> || disable all warnings | ||
|} | |} | ||
</blockquote><!-- environment variables --> | |||
== Completion/Readline Support == | |||
<blockquote> | |||
Simply import the bulitin <code>readline</code> library to enable command completion and other [[readline]] features like vi mode.<br> | |||
You can do this automatically by configuring a pythonrc. | |||
<syntaxhighlight lang="python"> | |||
# ~/.pythonrc | |||
try: | |||
</blockquote><!-- | import readline | ||
except: | |||
pass | |||
</syntaxhighlight> | |||
</blockquote><!-- Completion/Readline Support --> | |||
== Startup == | == Startup == |
Latest revision as of 13:41, 9 April 2022
Documentation
environment variables https://docs.python.org/release/3.10.0/using/cmdline.html#environment-variables compile options https://docs.python.org/release/3.10.0/using/configure.html
Introspection
Version Info
import sys print(sys.version_info)python -V
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
https://docs.python.org/release/3.10.0/using/cmdline.html#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
orC:/pythonX.X
$PYTHONWARNINGS=ignore
disable all warnings Completion/Readline Support
Simply import the bulitin
readline
library to enable command completion and other readline features like vi mode.
You can do this automatically by configuring a pythonrc.# ~/.pythonrc try: import readline except: passStartup
~/.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 withimport 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.