python 数据科学_Python-数据科学环境设置

python 数据科学_Python-数据科学环境设置_第1张图片

python 数据科学

Python-数据科学环境设置 (Python - Data Science Environment Setup)

To successfully create and run the example code in this tutorial we will need an environment set up which will have both general-purpose python as well as the special packages required for Data science. We will first look as installing the general-purpose python which can be python 2 or python 3. But we will prefer python 2 for this tutorial mainly because of its maturity and wider support of external packages.

为了成功创建并运行本教程中的示例代码,我们需要一个环境设置,该环境应同时具有通用python和数据科学所需的特殊软件包。 首先,我们将看起来像安装的是python 2或python 3的通用python。但是,由于它的成熟性和对外部软件包的广泛支持,我们在本教程中更喜欢python 2。

获取Python (Getting Python)

The most up-to-date and current source code, binaries, documentation, news, etc., is available on the official website of Python https://www.python.org/

最新的源代码,二进制文件,文档,新闻等可在Python的官方网站上找到https://www.python.org/

You can download Python documentation from https://www.python.org/doc/. The documentation is available in HTML, PDF, and PostScript formats.

您可以从https://www.python.org/doc/下载Python文档。 该文档有HTML,PDF和PostScript格式。

安装Python (Installing Python)

Python distribution is available for a wide variety of platforms. You need to download only the binary code applicable for your platform and install Python.

Python发行版可用于多种平台。 您只需要下载适用于您的平台的二进制代码并安装Python。

If the binary code for your platform is not available, you need a C compiler to compile the source code manually. Compiling the source code offers more flexibility in terms of choice of features that you require in your installation.

如果平台的二进制代码不可用,则需要C编译器来手动编译源代码。 在安装所需的功能选择方面,编译源代码可提供更大的灵活性。

Here is a quick overview of installing Python on various platforms −

这是在各种平台上安装Python的快速概述-

Unix和Linux安装 (Unix and Linux Installation)

Here are the simple steps to install Python on Unix/Linux machine.

以下是在Unix / Linux机器上安装Python的简单步骤。

  • Open a Web browser and go to https://www.python.org/downloads/.

    打开Web浏览器,然后转到https://www.python.org/downloads/ 。

  • Follow the link to download zipped source code available for Unix/Linux.

    单击链接下载适用于Unix / Linux的压缩源代码。

  • Download and extract files.

    下载并解压缩文件。

  • Editing the Modules/Setup file if you want to customize some options.

    如果要自定义某些选项,请编辑“ 模块/设置”文件。

  • run ./configure script

    运行./configure脚本

  • make

    使

  • make install

    进行安装

This installs Python at standard location /usr/local/bin and its libraries at /usr/local/lib/pythonXX where XX is the version of Python.

这会将Python安装在标准位置/ usr / local / bin中,并将其库安装在/ usr / local / lib / pythonXX中 ,其中XX是Python的版本。

Windows安装 (Windows Installation)

Here are the steps to install Python on Windows machine.

以下是在Windows计算机上安装Python的步骤。

  • Open a Web browser and go to https://www.python.org/downloads/.

    打开Web浏览器,然后转到https://www.python.org/downloads/ 。

  • Follow the link for the Windows installer python-XYZ.msi file where XYZ is the version you need to install.

    单击 Windows安装程序python-XYZ.msi文件的链接,其中XYZ是您需要安装的版本。

  • To use this installer python-XYZ.msi, the Windows system must support Microsoft Installer 2.0. Save the installer file to your local machine and then run it to find out if your machine supports MSI.

    要使用此安装程序python-XYZ.msi ,Windows系统必须支持Microsoft Installer 2.0。 将安装程序文件保存到本地计算机,然后运行它以查找您的计算机是否支持MSI。

  • Run the downloaded file. This brings up the Python install wizard, which is really easy to use. Just accept the default settings, wait until the install is finished, and you are done.

    运行下载的文件。 这将弹出Python安装向导,该向导非常易于使用。 只需接受默认设置,等待安装完成即可。

Macintosh安装 (Macintosh Installation)

Recent Macs come with Python installed, but it may be several years out of date. See http://www.python.org/download/mac/ for instructions on getting the current version along with extra tools to support development on the Mac. For older Mac OS's before Mac OS X 10.3 (released in 2003), MacPython is available.

最近的Mac装有Python,但可能已经过时了。 有关获取当前版本以及支持Mac上开发的其他工具的说明,请参见http://www.python.org/download/mac/ 。 对于Mac OS X 10.3(2003年发布)之前的旧Mac OS,可以使用MacPython。

Jack Jansen maintains it and you can have full access to the entire documentation at his website − http://www.cwi.nl/~jack/macpython.html. You can find complete installation details for Mac OS installation.

杰克·詹森(Jack Jansen)对此进行了维护,您可以在其网站( http://www.cwi.nl/~jack/macpython.html)上完全访问整个文档。 您可以找到Mac OS安装的完整安装详细信息。

设置路径 (Setting up PATH)

Programs and other executable files can be in many directories, so operating systems provide a search path that lists the directories that the OS searches for executables.

程序和其他可执行文件可以在许多目录中,因此操作系统提供了搜索路径,该路径列出了OS搜索可执行文件的目录。

The path is stored in an environment variable, which is a named string maintained by the operating system. This variable contains information available to the command shell and other programs.

路径存储在环境变量中,该变量是操作系统维护的命名字符串。 此变量包含命令外壳和其他程序可用的信息。

The path variable is named as PATH in Unix or Path in Windows (Unix is case sensitive; Windows is not).

路径变量在Unix中被命名为PATH,在Windows中被命名为Path(Unix区分大小写; Windows不区分大小写)。

In Mac OS, the installer handles the path details. To invoke the Python interpreter from any particular directory, you must add the Python directory to your path.

在Mac OS中,安装程序将处理路径详细信息。 要从任何特定目录调用Python解释器,必须将Python目录添加到路径中。

在Unix / Linux上设置路径 (Setting path at Unix/Linux)

To add the Python directory to the path for a particular session in Unix −

要将Python目录添加到Unix中特定会话的路径-

  • In the csh shell − type setenv PATH "$PATH:/usr/local/bin/python" and press Enter.

    在csh shell中 -键入setenv PATH“ $ PATH:/ usr / local / bin / python”并按Enter。

  • In the bash shell (Linux) − type export ATH="$PATH:/usr/local/bin/python" and press Enter.

    在bash shell(Linux)中 ,键入export ATH =“ $ PATH:/ usr / local / bin / python”,然后按Enter。

  • In the sh or ksh shell − type PATH="$PATH:/usr/local/bin/python" and press Enter.

    在sh或ksh shell中 -键入PATH =“ $ PATH:/ usr / local / bin / python”并按Enter。

  • Note − /usr/local/bin/python is the path of the Python directory

    注意 -/ usr / local / bin / python是Python目录的路径

在Windows上设置路径 (Setting path at Windows)

To add the Python directory to the path for a particular session in Windows −

要将Python目录添加到Windows中特定会话的路径-

At the command prompt − type path %path%;C:\Python and press Enter.

在命令提示符下 -键入path%path%; C:\ Python并按Enter。

Note − C:\Python is the path of the Python directory

注意 -C:\ Python是Python目录的路径

Python环境变量 (Python Environment Variables)

Here are important environment variables, which can be recognized by Python −

这是重要的环境变量,Python可以识别它们-

Sr.No. Variable & Description
1

PYTHONPATH

It has a role similar to PATH. This variable tells the Python interpreter where to locate the module files imported into a program. It should include the Python source library directory and the directories containing Python source code. PYTHONPATH is sometimes preset by the Python installer.

2

PYTHONSTARTUP

It contains the path of an initialization file containing Python source code. It is executed every time you start the interpreter. It is named as .pythonrc.py in Unix and it contains commands that load utilities or modify PYTHONPATH.

3

PYTHONCASEOK

It is used in Windows to instruct Python to find the first case-insensitive match in an import statement. Set this variable to any value to activate it.

4

PYTHONHOME

It is an alternative module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directories to make switching module libraries easy.

序号 变量与说明
1个

肺炎路径

它的作用类似于PATH。 这个变量告诉Python解释器在哪里可以找到导入程序的模块文件。 它应该包括Python源库目录和包含Python源代码的目录。 PYTHONPATH有时是由Python安装程序预设的。

2

PYTHON启动

它包含一个包含Python源代码的初始化文件的路径。 每次您启动解释器时都会执行它。 在Unix中,它的名称为.pythonrc.py,其中包含用于加载实用程序或修改PYTHONPATH的命令。

3

百事通

Windows中使用它来指示Python在import语句中查找第一个不区分大小写的匹配项。 将此变量设置为任何值以激活它。

4

PYTHONHOME

它是替代的模块搜索路径。 它通常嵌入在PYTHONSTARTUP或PYTHONPATH目录中,以简化切换模块库。

运行Python (Running Python)

There are three different ways to start Python −

有三种不同的启动Python的方式-

互动翻译 (Interactive Interpreter)

You can start Python from Unix, DOS, or any other system that provides you a command-line interpreter or shell window.

您可以从Unix,DOS或任何其他提供命令行解释器或Shell窗口的系统中启动Python。

Enter python the command line.

在命令行输入python

Start coding right away in the interactive interpreter.

立即在交互式解释器中开始编码。


$python # Unix/Linux
or
python% # Unix/Linux
or
C:> python # Windows/DOS

Here is the list of all the available command line options −

这是所有可用命令行选项的列表-

Sr.No. Option & Description
1

-d

It provides debug output.

2

-O

It generates optimized bytecode (resulting in .pyo files).

3

-S

Do not run import site to look for Python paths on startup.

4

-v

verbose output (detailed trace on import statements).

5

-X

disable class-based built-in exceptions (just use strings); obsolete starting with version 1.6.

6

-c cmd

run Python script sent in as cmd string

7

file

run Python script from given file

序号 选项和说明
1个

-d

它提供调试输出。

2

-O

它生成优化的字节码(产生.pyo文件)。

3

-S

不要在启动时运行导入站点来查找Python路径。

4

-v

详细输出(对import语句的详细跟踪)。

5

-X

禁用基于类的内置异常(仅使用字符串); 从1.6版开始已过时。

6

-c cmd

运行以cmd字符串形式发送的Python脚本

7

文件

从给定文件运行Python脚本

命令行脚本 (Script from the Command-line)

A Python script can be executed at command line by invoking the interpreter on your application, as in the following −

通过在应用程序上调用解释器,可以在命令行执行Python脚本,如下所示-


$python script.py # Unix/Linux

or

python% script.py # Unix/Linux

or 

C: >python script.py # Windows/DOS

Note − Be sure the file permission mode allows execution.

注意 -确保文件许可模式允许执行。

集成开发环境 (Integrated Development Environment)

You can run Python from a Graphical User Interface (GUI) environment as well, if you have a GUI application on your system that supports Python.

如果您的系统上有支持Python的GUI应用程序,则也可以从图形用户界面(GUI)环境中运行Python。

  • Unix − IDLE is the very first Unix IDE for Python.

    Unix -IDLE是第一个用于Python的Unix IDE。

  • Windows − PythonWin is the first Windows interface for Python and is an IDE with a GUI.

    Windows -PythonWin是Python的第一个Windows界面,并且是带有GUI的IDE。

  • Macintosh − The Macintosh version of Python along with the IDLE IDE is available from the main website, downloadable as either MacBinary or BinHex'd files.

    Macintosh-可以从主网站上获得Macintosh版本的Python和IDLE IDE,可以将其下载为MacBinary或BinHex文件。

安装SciPy Pack (Installing SciPy Pack)

The best way to enable the required packs is to use an installable binary package specific to your operating system. These binaries contain full SciPy stack (inclusive of NumPy, SciPy, matplotlib, IPython, SymPy and nose packages along with core Python).

启用所需软件包的最佳方法是使用特定于您的操作系统的可安装二进制软件包。 这些二进制文件包含完整的SciPy堆栈(包括NumPy,SciPy,matplotlib,IPython,SymPy和鼻子包以及核心Python)。

视窗 (Windows)

Anaconda (from www.continuum.io) is a free Python distribution for SciPy stack. It is also available for Linux and Mac.

Anaconda(来自www.continuum.io )是SciPy堆栈的免费Python发行版。 它还适用于Linux和Mac。

Canopy (www.enthought.com/products/canopy/) is available as free as well as commercial distribution with full SciPy stack for Windows, Linux and Mac.

Canopy( www.enthought.com/products/canopy/ )是免费的,也可以通过Windows,Linux和Mac的完整SciPy堆栈进行商业发行。

Python (x,y): It is a free Python distribution with SciPy stack and Spyder IDE for Windows OS. (Downloadable from www.python-xy.github.io/)

Python(x,y):它是一个免费的Python发行版,带有SciPy堆栈和Windows OS的Spyder IDE。 (可从www.python-xy.github.io/下载)

Linux (Linux)

Package managers of respective Linux distributions are used to install one or more packages in SciPy stack.

各个Linux发行版的软件包管理器用于在SciPy堆栈中安装一个或多个软件包。

对于Ubuntu (For Ubuntu)


sudo apt-get install python-numpy 
python-scipy python-matplotlibipythonipythonnotebook python-pandas 
python-sympy python-nose

对于Fedora (For Fedora)


sudo yum install numpyscipy python-matplotlibipython 
python-pandas sympy python-nose atlas-devel

从源头建造 (Building from Source)

Core Python (2.6.x, 2.7.x and 3.2.x onwards) must be installed with distutils and zlib module should be enabled.

必须使用distutils安装Core Python(2.6.x,2.7.x和3.2.x及更高版本),并应启用zlib模块。

GNU gcc (4.2 and above) C compiler must be available.

GNU gcc(4.2及更高版本)C编译器必须可用。

To install NumPy, run the following command.

要安装NumPy,请运行以下命令。


Python setup.py install

Let us test whether NumPy module is properly installed, try to import it from Python prompt.

让我们测试NumPy模块是否已正确安装,尝试从Python提示符下导入它。

If it is not installed, the following error message will be displayed.

如果未安装,将显示以下错误消息。


Traceback (most recent call last): 
   File "", line 1, in  
      import numpy 
ImportError: No module named 'numpy'

Similarly we can check for the installation of all the required Data Science packages shown in the next chapters.

同样,我们可以检查下一章中显示的所有必需的Data Science软件包的安装。

翻译自: https://www.tutorialspoint.com/python_data_science/python_data_science_environment_setup.htm

python 数据科学

你可能感兴趣的:(python,linux,java,ubuntu,windows)