osx python 位置_在OSX(和必要的模块)上安装Python

osx python 位置

If you need help installing python on OSX, read on.

如果您需要在OSX上安装python的帮助,请继续阅读。

For the last three years, I’ve used a mac for all my development. I love the fact that everything ‘just works’ on the platform. That said, when you get into scientific computing and data analytics, especially with python, you can  run into some issues.

在过去的三年中,我一直使用Mac进行开发。 我喜欢在平台上一切都“正常运行”的事实。 也就是说,当您进入科学计算和数据分析领域时,尤其是使用python时,可能会遇到一些问题。

Just like linux, python is included with the operating system. Unlike linux, this can cause problems long-term for you due to upgrades and changes that Apple may make to the python ecosystem.

就像linux一样,python也包含在操作系统中。 与linux不同,这可能会因Apple可能对python生态系统进行升级和更改而给您带来长期问题。

On OS X, I recommend those of you starting out to go with Anaconda or Enthought Canopy.  As I said in “Installing python on Windows“, I prefer Canopy over Anaconda for scientific computing / data analytics but either will work for you.  Installing Canopy on the mac is very similar to installing it on Windows…so I’ll let this post be your guide for installing Canopy.

在OS X上,我建议那些开始使用AnacondaEnthought Canopy的人使用 。 正如我在“ 在Windows上安装python ”中所说的那样,在科学计算/数据分析方面,我更喜欢Canopy而不是Anaconda,但两者都可以为您工作。 在Mac上安装Canopy与在Windows上安装非常相似...因此,我将以本文章作为您安装Canopy的指南

If you want to get into the nitty-gritty and install and configure python and the modules yourself, you can easily do so, but be prepared to spend some time on the command line.

如果您想进入nitty-gritty并自己安装和配置python及其模块,则可以轻松地做到这一点,但要准备在命令行上花一些时间。

Before we get started installing python on your Mac, we need to install homebrew, which is a package manager for OS X (it acts similar to the ‘apt’ package manager on ubuntu / debian).

在我们开始在Mac上安装python之前,我们需要安装homebrew ,它是OS X的软件包管理器(其作用类似于ubuntu / debian上的“ apt”软件包管理器)。

To install homebrew, open a terminal and paste the following:

要安装自制软件,请打开终端并粘贴以下内容:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

This command installs the homebrew ecosystem onto your machine and preps your machine to be ready to install various packages, including python.

此命令将自制软件生态系统安装到您的计算机上,并使您的计算机准备就绪,可以安装各种软件包,包括python。

在OSX上安装Python (Installing Python on OSX)

Step 1: Let’s get python installed via homebrew.  In your terminal, type:

步骤1:让我们通过自制软件安装python。 在您的终端中,键入:

brew install python

This will install a version of python onto your machine and set up your environment to use that version. This helps mitigate any issues you might have down the road if / when Apple makes changes to the system provided python.   Additionally, brew installs pip into the system to make it easy to get the necessary modules onto your machine.

这会将python版本安装到您​​的计算机上,并设置您的环境以使用该版本。 如果/当Apple对系统提供的python进行更改时,这有助于减轻您可能遇到的任何问题。 此外,brew将pip安装到系统中,以便轻松将必要的模块安装到计算机上。

From this point on, we are generally going to follow exactly the same steps that I outline in Installing Python on Linux except we don’t need to install any additional tools.

从这一点开始,我们通常将遵循与我在Linux上安装Python所概述的步骤完全相同的步骤,只是不需要安装任何其他工具。

Step 2: Not required, but highly recommended – install a virtual environment.  I recommend virtualenv. Install it with this command:

步骤2:不是必需的,但强烈建议 -安装虚拟环境。 我推荐virtualenv。 使用以下命令安装它:

pip install virtualenv

When you are ready to get started on a new project, type the below command to install python into a new virtual environment (the ‘env’ is the name of the environment). You only have to do this once per project. Note: You should use a folder per project to keep your virtual environments separated.

当您准备开始新项目时,请键入以下命令以将python安装到新的虚拟环境中(“ env”是环境的名称)。 每个项目只需执行一次。 注意:您应该为每个项目使用一个文件夹,以保持虚拟环境分离。

virtualenv env

Whenever you want to work on a specific project, change into that folder and type the following. This will set up your environment with all of your installed python modules:

每当您要处理特定项目时,请切换到该文件夹​​并键入以下内容。 这将使用所有已安装的python模块设置您的环境:

source env/bin/activate

For the purpose of this walk-through let’s create a new directory, set up a new virtual environment and then install the necessary modules.

为了完成本演练,让我们创建一个新目录,设置一个新的虚拟环境,然后安装必要的模块。

  • Create a folder in your home directory called ‘projects’.
  • Type “mkdir projects” to do this from the command line.
  • Change into that folder and then type “mkdir install_example” to create another folder inside the projects folder.
  • Type “virtualenv env” to create your virtual environment.
  • Type “source env/bin/activate” to begin using this environment
  • 在您的主目录中创建一个名为“ projects”的文件夹。
  • 在命令行中键入“ mkdir projects”以执行此操作。
  • 转到该文件夹​​,然后键入“ mkdir install_example”以在项目文件夹中创建另一个文件夹。
  • 输入“ virtualenv env”以创建您的虚拟环境。
  • 输入“ source env / bin / activate”以开始使用此环境

Now that we have our environment ready to go, we need to install some of the modules that are most often used when doing data work inside python. These modules are:

现在我们已经准备好环境,我们需要安装一些在python中进行数据工作时最常用的模块。 这些模块是:

The above modules can be installed with one pip command.

可以使用一个pip命令安装以上模块。

pip install pandas scipy scikitlearn statsmodels sympy matplotlib jupyter

You’re ready to start working with python for data analysis on your mac. Just remember, for each virtualenv you create, you’ll need to reinstall these modules if you wish to use them.

您已经准备好开始使用python在Mac上进行数据分析。 请记住,对于您创建的每个virtualenv,如果要使用它们,都需要重新安装这些模块。

翻译自: https://www.pybloggers.com/2016/11/installing-python-on-osx-and-the-necessary-modules/

osx python 位置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值