Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Python Programming/Getting Python

From Wikibooks, open books for an open world
<Python Programming
Previous: OverviewIndexNext: Setting it up


To program in Python, you need a Python interpreter to run your code—we will discuss interpreters later. If it's not already installed, or if the version you are using is obsolete, you will need to obtain and install Python using the methods below. The current Python versions are 3.x; versions 2.x are discontinued and no longer maintained.

Installing Python in Windows

[edit |edit source]

Go to thePython Homepage and get the proper version for your platform. Download it, read the instructions and get it installed.

To run Python from the command line, you will need to have the python directory in your PATH. You can instruct the Python installer to add Python to the path, but if you do not do that, you can add it manually. The PATH variable can be modified from the Window's System control panel. To expand the PATH in Windows 7:

  1. Go to Start.
  2. Right click on computer.
  3. Click on properties.
  4. Click on 'Advanced System Settings'
  5. Click on 'Environmental Variables'.
  6. In the system variables select Path and edit it, by appending a ';' (without quote) and adding 'C:\python27'(without quote).

If you prefer having a temporary environment, you can create a new command prompt short-cut that automatically executes the following statement:

PATH %PATH%;c:\python27

If you downloaded a different version (such as Python 3.1), change the "27" for the version of Python you have (27 is 2.7.x, the current version of Python 2.)

Cygwin

[edit |edit source]

By default, the Cygwin installer for Windows does not include Python in the downloads. However, it can be selected from the list of packages.

Installing Python on Mac

[edit |edit source]

Users on Mac OS X will find that it already ships with Python 2.3 (OS X 10.4 Tiger) or Python 2.6.1 (OS X Snow Leopard), but if you want the more recent version head toPython Download Page follow the instruction on the page and in the installers. As a bonus you will also install the Python IDE.

Installing Python on Unix environments

[edit |edit source]

Python is available as a package for most Linux distributions. In some cases, the distribution CD will contain the python package for installation, while other distributions require downloading the source code and using the compilation scripts.

Gentoo Linux

[edit |edit source]

Gentoo includes Python by default—the package management systemPortage depends on Python.

Ubuntu Linux

[edit |edit source]

Users of Ubuntu will notice that Python comes installed by default, only it sometimes is not the latest version. To check which version of Python is installed, type

python-V

into the terminal.

Arch Linux

[edit |edit source]

Arch Linux does not come with Python pre-installed by default, but it is easily available for installation through the package manager to pacman. As root (or using sudo if you've installed and configured it), type:

pacman-Spython

This will be update package databases and install Python 3. Python 2 can be installed with:

pacman-Spython2

Other versions can be built from source from the Arch User Repository.

Source code installations

[edit |edit source]

Some platforms do not have a version of Python installed, and do not have pre-compiled binaries. In these cases, you will need to download the source code from theofficial site. Once the download is complete, you will need to unpack the compressed archive into a folder.

To build Python, simply run the configure script (requires the Bash shell) and compile using make.

Other Distributions

[edit |edit source]

Python, also referred to as CPython to avoid confusion, is written in theC programming language, and is the official reference implementation. CPython can run on various platforms due to its portability.

Apart from CPython there are also other implementations that run on top of a virtual machine. For example, on Java's JRE (Java Runtime Environment) or Microsoft's .NET CLR (Common Language Runtime). Both can access and use the libraries available on their platform. Specifically, they make use ofreflection that allows complete inspection and use of all classes and objects for their very technology.

Python Implementations (Platforms)

EnvironmentDescriptionGet From
JythonJava Version of PythonJython
IronPythonC# Version of PythonIronPython

Integrated Development Environments (IDE)

[edit |edit source]

It's common to use a simple text editor for writing Python code, but you may feel the need to upgrade to a more advancedIDE. CPython ships with IDLE; however, IDLE is not considered user-friendly.[1] For Linux, KDevelop and Spyder are popular. For Windows, PyScripter is free, quick to install, and comes included withPortablePython.

Some Integrated Development Environments (IDEs) for Python

EnvironmentDescriptionGet From
ActivePythonHighly flexible, Pythonwin IDEActivePython
AnjutaIDE Linux/UnixAnjuta
Eclipse (PyDev plugin)Open-source IDEEclipse
EricOpen-source Linux/Windows IDE.Eric
KDevelopCross-language IDE for KDEKDevelop
Ninja-IDECross-platform open-source IDE.Nina-IDE
PyScripterFree Windows IDE (portable)PyScripter
PythonwinWindows-oriented environmentPythonwin
SpyderFree cross-platform IDE (math-oriented)Spyder
VisualWxFree GUI BuilderVisualWx

The Python official wiki has acomplete list of IDEs.

There are several commercial IDEs such as Komodo, BlackAdder, Code Crusader, Code Forge, and PyCharm. However, for beginners learning to program, purchasing a commercial IDE is unnecessary.

Trying Python online

[edit |edit source]

You can try Python online, thereby avoiding the need to install. The onlinePython shell at Python's official site provides a web Python REPL (read–eval–print loop).

Keeping Up to Date

[edit |edit source]

Python has a very active community and the language itself is evolving continuously. Make sure to checkpython.org for recent releases and relevant tools. The website is an invaluable asset.

Public Python-related mailing lists are hosted atmail.python.org. Two examples of such mailing lists are thePython-announce-list to keep up with newly released third party-modules or software for Python and the general discussion listPython-list. These lists are mirrored to the Usenet newsgroupscomp.lang.python.announce &comp.lang.python.

Notes

[edit |edit source]
  1. The Things I Hate About IDLE That I Wish Someone Would Fix.
Previous: OverviewIndexNext: Setting it up
Retrieved from "https://en.wikibooks.org/w/index.php?title=Python_Programming/Getting_Python&oldid=4395374"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp