Changes the current Python.
What is it?
It's a way to seamlessly switch between multiple Python installations. It's mostly designed for setting a "default" Python interpreter for running scripts or providing an interactive shell, rather than setting a Python interpreter for a specific project (virtualenv and friends is a better tool for per-project Python installations).
What is it not?
chpython is not a tool to:
- Replace virtualenv. chpython is not designed to switch between Pythons on a per-project basis.
- Install Python. I do not plan to add support for downloading and compiling Python to chpython. It is expressly for managing installations.
What does it do?
chpython lets you switch easily between different versions of Python that
you have installed in
~/.pythons. It switches between them by:
*3bins to their basename (e.g.,
python3can be called using
python) (not implemented yet).
hash -rto update the command-lookup hashtable.
You can return to the default (system) Python by calling:
$ chpython system
chpython system will completely restore the environment you had
You can also execute a command using any installed version of Python, without
$PATH or any other environment variables, by calling:
$ chpython exec VERSION args...
For example, you can call
python -V on an ancient version of Python you have
installed for some reason:
$ chpython exec 2.5 python -V
chpython supports fuzzy matching of Python versions, so
will execute the latest version of Python 2.7 it can find. You can also
specify a full version:
What does it not do?
chpython does not:
- Hook into
- Install executable shims (like pyenv).
- Does not muck with your prompt or anything but the
What does it require?
- bash (it may work with zsh, but I haven't tested it)
How do I install it?
- Clone the repository (
git clone https://github.com/mdippery/chpython.git).
- Copy or symlink
/usr/local/share/chpython, or anywhere else you feel like putting it. Or keep it where it is after cloning the repo, I don't care.
source /where/you/put/share/chpython/chpython.shsomewhere in
- Optionally, set a Python version by adding
chpython VERSIONto your
~/.bashrcfile. If you don't do this, your system's Python will be used by default, but you can use a different Python on a per-shell basis by calling
Why not use...
Virtualenv is a great solution for setting up a specific Python version to use
on a per-project basis, but I have never liked using it to set a default
python to use for "everyday" scripts in my shell, since it involves setting up
a "global" virtualenv anyway. I also don't like how the default virtualenv
activate scripts mucks with things in my environment, such as
$PS1 is ugly). Generally speaking, pointing your
shell to a "new" Python is as simple as adding its
bin directory to your
$PATH; nothing else is needed if you installed it normally.
I compile versions of Python to use by default in my shell to
wanted a quick way to switch between different versions, and was inspired by
chruby to write a bash script to handle that switching seamlessly for me.
...Conda (Anaconda, Miniconda)?
Conda and its various incarnations could be used for a similar purpose, but personally I find them to be far too heavyweight for the relatively simple tasking of providing and managing default Python installations.