<jupyter_start><jupyter_text>Python Installation  Contents1. [System-wide installation](System).2. [Project-wide/user-wide installation (virtual environments)](Virtual).3. [`pip`: intalling Python modules](pip).  A. System-wide Python installation  MS Windows Download Python from [https://www.python.org/downloads/](https://www.python.org/downloads/) ... and remember to select the option "`Add Python to PATH`".  Mac OS X Install [Homebrew](http://brew.sh/) and run "`brew install python3`".  GNU Debian Run "`sudo apt-get update && sudo apt-get install python3`".  Arch Linux Run "`sudo pacman -Sy && sudo pacman -S python`".  B. Install Python in a virtual environment[Python virtual environments](https://docs.python.org/3/tutorial/venv.html) allow to have a set of different Python configurations in the same host. This can be useful in the following situations:1. When two or more Python projects, that run in the same host, requires different configurations of the used packages.2. If you don't have administrative privilegies to install packages.3. To keep organized the Python stuff in the file system.2. Using a different environment for each different Python's working context. In this case, we also will need [`virtualenvwrapper`](https://virtualenvwrapper.readthedocs.io/en/latest/).Both tools can be provided by [`pip`](https://pypi.python.org/pypi/pip), the recomended Python packages installer.  1. [`virtualenv`](https://pypi.python.org/pypi/virtualenv)Useful if we want to use a different environment for each [Python project](http://docs.python-guide.org/en/latest/writing/structure/).  1.1 Installation of `virtualenv````sudo pip install virtualenv```  1.2 Use of `virtualenv`  1.2.1 Creation of the environment```$ mkdir myproject$ cd myproject``` If we want to use the default Python interpreter:```$ virtualenv env  "env" is the name of the directory containing the environment``` If we want to use a specific Python interpreter:```$ virtualenv -p path/to/the/interpreter env```  1.2.2 Activation of the environment```$ cd myproject$ . env/bin/activate``` And your [prompt](http://www.webopedia.com/TERM/P/prompt.html) becomes (something similar to):```(env) $```  1.2.3 Deactivation of the environment```deactivate``` And your prompt becomes (something similar to):```$```  1.2.4 Deletion of the environment```$ ls env/bin			libinclude			pip-selfcheck.json$ rm -rf env```  2. [`virtualenvwrapper`](https://virtualenvwrapper.readthedocs.io/en/latest/)When we prefer to use a different environment for each different Python's working-context.  2.1 Installation of `virtualenvwrapper````sudo pip install virtualenvwrapper  requires "virtualenv"```  2.2 Use of `virtualenvwrapper`  2.2.1 Configuration of the environments directory```$ export VIRTUALENVWRAPPER_PYTHON=`which python3`$ export WORKON_HOME=$HOME/.python_environments$ source `which virtualenvwrapper.sh````It's a good idea to store these commands in a file that is read by the shell when this is executed (in the case of Bash, `.bashrc` which is run by "non-login shells" or `.bash_profile` that is run by "login shells"). To use this right now, include that information in the corresponding file and "source" it. Example:```$ source ~/.bashrc```  2.2.2 Creation of a environment```$ mkvirtualenv -p  $  Example: mkvirtualenv -p python3 YAPT```  2.2.3 Determination of the virtual environment The Python environment must be activated before using it. After running `mkvirtualenv`, the environment should be active and this is reflected in the command line prompt. This can also checked by:```$ echo $VIRTUAL_ENV```  2.2.4 Activation of a environment```$ workon $  Example: workon yapt(yapt) $```  2.2.5 Deactivation of a environment```(yapt) $ deactivate```  2.2.6 Deletion of a environment```$ rmvirtualenv $  Example: rmvirtualenv old-env```  2.2.7 List the environments```$ lsvirtualenv```  2.2.8 Navigate into the directory of the currently activated virtual environment```$ cdvirtualenv```  3. [Simple Python Version Management: `pyenv`](https://github.com/pyenv/pyenv)Useful to install and use different versions of Python which are independent of the system's installed Python.  3.1 Install  All Unixes (included OSX)Replace .bashrc by .bash_profile in OSX.```git clone https://github.com/pyenv/pyenv.git ~/.pyenvecho 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrcecho 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrcecho -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bashrc```  3.2 Source configuration files```exec "$SHELL"```  3.3 List available python versions```pyenv install --list```  3.4 Compile Python Prerequisites DebiansSee [Common build problems](https://github.com/pyenv/pyenv/wiki/Common-build-problems) if you are unable to install an environment.Moreover, in order to have `tkinter` graphical interface avaiable, the `tk-dev` Linux package should have been installed.```sudo apt-get install tk-dev``` OSXTODO Arch Linux```pacman -S gcc make``` Download and compile```pyenv install 3.6.4```  3.5 UninstallSimply, remove the lines added to the configuration file and run:```rm -fr ~/.pyenv```  3.6 Lists all Python versions known to pyenv```pyenv versions```  3.7 Activate/Select a installed version of Python`pyenv` [local](https://github.com/pyenv/pyenv/blob/master/COMMANDS.mdpyenv-local)/[global](https://github.com/pyenv/pyenv/blob/master/COMMANDS.mdpyenv-global)/[shell](https://github.com/pyenv/pyenv/blob/master/COMMANDS.mdpyenv-shell) `3.6.1`  3.8 Deactivate```pyenv local/global/shell system```  3.9 Displays the currently active Python version```pyenv version```  4. Copy virtual environments  4.1 Get (through the `stdout`) the current "state" of the environmen```(yapt) $ pip freezeappnope==0.1.0cycler==0.10.0decorator==4.0.11ffmpy==0.2.2ipdb==0.10.2ipython==5.2.0ipython-genutils==0.1.0matplotlib==2.0.0mcdwt==1.0numpy==1.12.0pexpect==4.2.1pickleshare==0.7.4prompt-toolkit==1.0.9ptyprocess==0.5.1Pygments==2.2.0pyparsing==2.1.10pypng==0.0.18python-dateutil==2.6.0pytz==2016.10PyWavelets==0.5.1scipy==0.18.1simplegeneric==0.8.1six==1.10.0traitlets==4.3.1wcwidth==0.1.7``` You can redirect the list of Python packages currently installed in the virtual environment to a file to remember a "state". Example:```$ pip freeze > environment_state.txt```  4.2 Copy environments 4.2.1 Using `virtualenvwrapper````(old-env) $ pip freeze > /tmp/environment_state.txt(old-env) $ deactivate$ mkvirtualenv -p python3 new-env(new-env) $ pip install -r /tmp/environment_state.txt``` 4.2.2 Using `pyenv````$ pip freeze > /tmp/environment_state.txt$ pyenv local 3.6.3  For example$ pip install -r /tmp/environment_state.txt```  [`pip`](https://docs.python.org/3/installing/index.html): installing Python packages¶`pip` is a command-line tool for accesing to [PyPI - the standard Python's packages repository](https://pypi.python.org/pypi).<jupyter_code>!pip search games | grep free
!pip install freegames
!pip install ipython<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1339808598771604, 'fraction_numerical': 0.026710469932866732, 'mean_word_length': 5.078125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, 'https://': 15, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '326279', 'license': 'CC0-1.0', 'n_tokens_mistral': 2264, 'n_tokens_neox': 2089, 'n_words': 717, 'path': '02-installation.ipynb', 'repo_name': 'leowindwave/YAPT', 'size': '7001'}