热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

怎么在苹果手机上安装python_在苹果上安装Python

在苹果上安装PythonThelatestversionofMacOSX,Lion,comeswithPython2.7outofthebox.Youdonotneedtoin

在苹果上安装Python¶

The latest version of Mac OS X, Lion, comes with Python 2.7 out of the box.

You do not need to install or configure anything else to use Python. Having

said that, I would strongly recommend that you install the tools and libraries

described in the next section before you start building Python applications

for real-world use. In particular, you should always install Distribute, as it

makes it much easier for you to use other third-party Python libraries.

The version of Python that ships with OS X is great for learning, but it’s not

good for development. It’s slightly out of date, and Apple has made significant

changes that can cause hidden bugs.

正确做法¶

让我们安装一个真正版本的Python.

First, you’ll need to have GCC installed to compile Python. You can either get

this from XCode or the smaller

OSX-GCC-Installer package.

While Lion comes with a large number of UNIX utilities, those familiar with

Linux systems will notice one key component missing: a decent package manager.

Homebrew fills this void.

$ ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

Then, insert the Homebrew directory at the top of your PATH environment

variable. You can do this by adding the following line at the bottom of your

~/.bashrc file

export PATH=/usr/local/bin:$PATH

Now, we can install Python 2.7:

$ brew install python --framework

This will take a minute or two. Once that’s complete, you’ll have to add the

new Python scripts directory to your PATH

export PATH=/usr/local/share/python:$PATH

The --framework option tells Homebrew to compile a Framework-style Python

build, rather than a UNIX-style build. The outdated version of Python that

Snow Leopard comes packaged with is built as a Framework, so this helps avoid

some future module installation bugs.

发布包 & Pip¶

The most crucial third-party Python software of all is Distribute, which

extends the packaging and installation facilities provided by the distutils

in the standard library. Once you add Distribute to your Python system you can

download and install any compliant Python software product with a single

command. It also enables you to add this network installation capability to

your own Python software with very little work.

Homebrew already installed Distribute for you. Its easy_install command is

considered by many to be deprecated, so we will install its replacement:

pip. Pip allows for uninstallation of packages, and is actively maintained,

unlike easy_install.

To install pip, simply open a command prompt and run

$ easy_install pip

虚拟环境(Virtualenv)¶

After Distribute & Pip, the next development tool that you should install is

virtualenv. Use pip

$ pip install virtualenv

The virtualenv kit provides the ability to create virtual Python environments

that do not interfere with either each other, or the main Python installation.

If you install virtualenv before you begin coding then you can get into the

habit of using it to create completely clean Python environments for each

project. This is particularly important for Web development, where each

framework and application will have many dependencies.

To set up a new Python environment, change the working directory to where ever

you want to store the environment, and run the virtualenv utility in your

project’s directory

$ virtualenv --distribute venv

To use an environment, run source venv/bin/activate. Your command prompt

will change to show the active environment. Once you have finished working in

the current virtual environment, run deactivate to restore your settings

to normal.

Each new environment automatically includes a copy of pip, so that you can

setup the third-party libraries and tools that you want to use in that

environment. Put your own code within a subdirectory of the environment,

however you wish. When you no longer need a particular environment, simply

copy your code out of it, and then delete the main directory for the environment.

This page is a remixed version of another guide,

which is available under the same license.



推荐阅读
  • CentOS7源码编译安装MySQL5.6
    2019独角兽企业重金招聘Python工程师标准一、先在cmake官网下个最新的cmake源码包cmake官网:https:www.cmake.org如此时最新 ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 本文详细介绍了 Dockerfile 的编写方法及其在网络配置中的应用,涵盖基础指令、镜像构建与发布流程,并深入探讨了 Docker 的默认网络、容器互联及自定义网络的实现。 ... [详细]
  • MySQL 数据库迁移指南:从本地到远程及磁盘间迁移
    本文详细介绍了如何在不同场景下进行 MySQL 数据库的迁移,包括从一个硬盘迁移到另一个硬盘、从一台计算机迁移到另一台计算机,以及解决迁移过程中可能遇到的问题。 ... [详细]
  • 本文介绍了在安装或运行 Python 项目时遇到的 'ModuleNotFoundError: No module named setuptools_rust' 错误,并提供了解决方案。 ... [详细]
  • 本文介绍了一款用于自动化部署 Linux 服务的 Bash 脚本。该脚本不仅涵盖了基本的文件复制和目录创建,还处理了系统服务的配置和启动,确保在多种 Linux 发行版上都能顺利运行。 ... [详细]
  • 本文深入探讨了Linux系统中网卡绑定(bonding)的七种工作模式。网卡绑定技术通过将多个物理网卡组合成一个逻辑网卡,实现网络冗余、带宽聚合和负载均衡,在生产环境中广泛应用。文章详细介绍了每种模式的特点、适用场景及配置方法。 ... [详细]
  • 本文详细分析了Hive在启动过程中遇到的权限拒绝错误,并提供了多种解决方案,包括调整文件权限、用户组设置以及环境变量配置等。 ... [详细]
  • 本文介绍了在Windows环境下使用pydoc工具的方法,并详细解释了如何通过命令行和浏览器查看Python内置函数的文档。此外,还提供了关于raw_input和open函数的具体用法和功能说明。 ... [详细]
  • 使用Vultr云服务器和Namesilo域名搭建个人网站
    本文详细介绍了如何通过Vultr云服务器和Namesilo域名搭建一个功能齐全的个人网站,包括购买、配置服务器以及绑定域名的具体步骤。文章还提供了详细的命令行操作指南,帮助读者顺利完成建站过程。 ... [详细]
  • 在现代网络环境中,两台计算机之间的文件传输需求日益增长。传统的FTP和SSH方式虽然有效,但其配置复杂、步骤繁琐,难以满足快速且安全的传输需求。本文将介绍一种基于Go语言开发的新一代文件传输工具——Croc,它不仅简化了操作流程,还提供了强大的加密和跨平台支持。 ... [详细]
  • 解决微信电脑版无法刷朋友圈问题:使用安卓远程投屏方案
    在工作期间想要浏览微信和朋友圈却不太方便?虽然微信电脑版目前不支持直接刷朋友圈,但通过远程投屏技术,可以轻松实现在电脑上操作安卓设备的功能。 ... [详细]
  • 使用Python在SAE上开发新浪微博应用的初步探索
    最近重新审视了新浪云平台(SAE)提供的服务,发现其已支持Python开发。本文将详细介绍如何利用Django框架构建一个简单的新浪微博应用,并分享开发过程中的关键步骤。 ... [详细]
  • Splay Tree 区间操作优化
    本文详细介绍了使用Splay Tree进行区间操作的实现方法,包括插入、删除、修改、翻转和求和等操作。通过这些操作,可以高效地处理动态序列问题,并且代码实现具有一定的挑战性,有助于编程能力的提升。 ... [详细]
  • 本文介绍了如何通过 Maven 依赖引入 SQLiteJDBC 和 HikariCP 包,从而在 Java 应用中高效地连接和操作 SQLite 数据库。文章提供了详细的代码示例,并解释了每个步骤的实现细节。 ... [详细]
author-avatar
来日方长吗_Xcc
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有