1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > mac搭建python开发环境_Mac中基于Homebrew搭建python开发环境

mac搭建python开发环境_Mac中基于Homebrew搭建python开发环境

时间:2020-04-08 13:48:54

相关推荐

mac搭建python开发环境_Mac中基于Homebrew搭建python开发环境

转移到mac上了。这里是在lion中搭建python开发环境的简单记录。这份记录不是一份step by step.而是事后写的记录,可能有记忆遗漏。如果有错误,请指正。

1.安装homebrew的准备$ sudo chown -R `whoami` /usr/localhomebrew希望在没有sudo的环境下工作(Homebrew is designed to work without using sudo.)所以首先对/usr/local/这个文件夹赋权限。(homebrew的软件是安装在这里的)

2.通过shell安装$ ruby -e "$(curl -fsSL /raw/323731/install_homebrew.rb)"

3.配置环境变量:$ nano ~/.bash_profile

加入以下内容:#Setting PATH for HomebrewPATH="/usr/local/bin:${PATH}"export PATH

Ok,这样homebrew就装好了。

4.brew的简单命令$ brew search #查找软件包$ brew install #安装软件包$ brew list #列出软件包$ brew uninstall #卸载软件包$ brew update #更新$ brew info #查看软件包的基本资料

5.安装python$ brew install python --framework --universal

The –framework option tells it to build as a Framework, which has some downstream niceties, and –universal builds a universal (32/64 bit) version.

6.将python加入path$ nano ~/.bash_profileexport PATH=/usr/local/share/python:$PATH

7.检查安装是否正确

此时,最好重启term。如果要确认修改是否正确,可以用which python和which easy_install查看python的路径是否正确。如果返回为

/usr/local/bin/python

/usr/local/share/python/easy_install

那么,安装正确

8.通过easy_install安装pip$ easy_install pip

9.安装virtualenv 和 virtuanenvwarpper$ /usr/local/share/python/pip install virtualenv

$ /usr/local/share/python/pip install virtualenvwrapper ##其实这个装不装已经无所谓了。

10.建立和项目相关的env

比如,项目文件在~/projects中,那么,$ cd ~/projects

$ virtualenv --no-site-packages project_name

The --no-site-packages flag is deprecated; it is now the default behavior.

New python executable in project_name/bin/python

Installing setuptools............done.

Installing pip...............done.

11.启动虚拟环境

首先进入刚刚建立的虚拟环境目录,比如:$ cd project_name

$ source bin/activate

注意,此时shell提示符前多了虚拟环境的名称提示:

(project_name)….$

Now,do anything you want.

12.退出虚拟环境$ deactivate

13.pip的设定

如果要保证在虚拟环境中调用系统的pip,可以在~/.bash_profile里加上:export PIP_REQUIRE_VIRTUALENV=true

如果要让系统的pip自动调用虚拟环境中的pipexport PIP_RESPECT_VIRTUALENV=true

14.安装你需要的软件包(注意提示符)

(project_name)....$ pip install pkg_name

【END】

文/全栈攻城狮(简书作者)

原文链接:/p/b26b86bff852

著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。