2. Utilizando Python em plataformas Unix

2.1. Obtendo e instalando a versão mais recente do Python

2.1.1. No Linux

O Python vem pré-instalado na maioria das distribuições Linux e está disponível como um pacote em todos as outras. No entanto, existem certos recursos que podemos querer utilizar e que não estão disponíveis no pacote da sua distro. Poderás compilar facilmente a versão mais recente do Python desde a origem.

Nas situações em que o Python não vier pré-instalado e também não estiver nos repositórios, poderás facilmente gerar os pacotes para a sua distro. Veja os seguintes links:

2.1.2. On FreeBSD e OpenBSD

  • usuários do FreeBSD, para adicionar a utilização do pacote utilize:

    pkg install python3
    
  • Usuários do OpenBSD, para adicionar pacotes use:

    pkg_add -r python
    
    pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz
    

    Por exemplo, usuários i386 podem pegar a versão 2.5.1 do Python usando o comando:

    pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/python-2.5.1p2.tgz
    

2.1.3. No OpenSolaris

Podes baixar o Python desde OpenCSW. Várias versões do Python estão disponíveis e poderás instala-las, por exemplo pkgutil -i python27.

2.2. Compilando o Python

If you want to compile CPython yourself, first thing you should do is get the source. You can download either the latest release’s source or just grab a fresh clone. (If you want to contribute patches, you will need a clone.)

The build process consists in the usual

./configure
make
make install

invocations. Configuration options and caveats for specific Unix platforms are extensively documented in the README file in the root of the Python source tree.

Aviso

make install can overwrite or masquerade the python binary. make altinstall is therefore recommended instead of make install since it only installs exec_prefix/bin/pythonversion.

2.4. Diversos

To easily use Python scripts on Unix, you need to make them executable, e.g. with

$ chmod +x script

e colocar uma linha Shebang apropriada no topo do script. Uma boa escolha normalmente é

#!/usr/bin/env python

which searches for the Python interpreter in the whole PATH. However, some Unices may not have the env command, so you may need to hardcode /usr/bin/python as the interpreter path.

Para usar comandos Shell em seus scripts Python, veja o módulo subprocess.

2.5. Editors and IDEs

There are a number of IDEs that support Python programming language. Many editors and IDEs provide syntax highlighting, debugging tools, and PEP 8 checks.

Please go to Python Editors and Integrated Development Environments for a comprehensive list.