Python installation in Mac OS X virtual environment that includes a framework that I can include into Xcode?(在 Mac OS X 虚拟环境中安装 Python,其中包含我可以包含到 Xcode 中的框架?)
问题描述
我喜欢将 Python 与 numpy、scipy 和其他一些软件包一起使用.我是一个绝对的 Python 初学者,在 Mac OS X 下安装时遇到了一些问题.
I like to use Python with numpy, scipy and some other packages. I am an absolute Python beginner and have some issues with the installation under Mac OS X.
我正在按照以下两个教程安装python:1 和 2.
I am following these two tutorials to install python: 1 and 2.
这里,HomeBrew 用于安装 Python(带有 pip)和 virtualenv.我对什么更好没有意见,MacPorts、HomeBrew、Fink...我只是发现本教程激发了信心.
Here, HomeBrew is used to install Python (with pip) and virtualenv. I do not have an opinion about what is better, MacPorts, HomeBrew, Fink... I just found this tutorial inspiring confidence.
如果我理解正确的话,我不应该接触的 OS X 系统 Python 位于/System/Library/Frameworks/Python.Framework 下.而且我不能在 Xcode 中使用这个,因为它没有我想要的包.HomeBrew Python 将安装在/usr/local/中的某个位置.我在那里找到了一个框架,但作为系统框架,它没有额外的包.本教程解释说,最好只在虚拟环境中安装额外的包,这通过 pip 完成.但我在那里找不到框架.
If I understand things correctly, OS X system Python, which I should never touch, is under /System/Library/Frameworks/Python.Framework. And I cannot use this one in Xcode because it does not have my wanted packages. The HomeBrew Python will be installed somewhere in /usr/local/. I found a framework there but as the system framework it does not have the additional packages. The tutorial explains that it might be better to install additional packages in virtual environments only which is done via pip. But I cannot find a framework there.
所以我的问题是:如何在包含可以包含到 Xcode 中的框架的虚拟环境中安装 Python?
So my question is: How can I get a Python installation in a virtual environment that includes a framework that I can include into Xcode?
推荐答案
- Apple Python 功能正常,正常的站点包文件夹是 /Library/Python/2.7/site-packages(而不是 /System/Library/Frameworks/Python.framework/版本/2.7/lib/python2.7/site-packages).您可以毫无问题地使用它.
- 我从来没有遇到任何问题来安装我想要作为框架的所有模块(numpy、scipy、matplotlib、pandas、shapely 和其他......),或者使用 pip 或 easy_install,包括 virtualenv(只需将它们安装在常规方式)或创建虚拟环境.
- 当你安装一个框架模块时,它被放置在普通的 site-packages 文件夹中.
- 唯一的问题可能是旧"的 Python 版本(对我来说不是问题,使用 2.6.x、2.7.x 和 3.3.x 版本)
- The Apple Python is functional and the normal site-packages folder is /Library/Python/2.7/site-packages (and not /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages). You can use it without problem.
- I never had any problem to install all modules (numpy, scipy, matplotlib, pandas, shapely, and others...) that I wanted as frameworks, or with pip or easy_install, including virtualenv (simply install them in the conventional way in Python) or creating virtual environments.
- when you install a framework module, It is placed in in the normal site-packages folder.
- the only problem is possibly the "old" Python version (not a problem for me, using 2.6.x, 2.7.x and 3.3.x versions)
但如果您愿意,您可以安装其他版本的 Python(64 位,而不是 32 位!):
But if you want, you can install others versions of Python (in 64-bits, not 32 !):
a) Apple 规定的方式:作为框架
- Python.org 的官方版本安装在 /Library/Frameworks/Python.framework 中,site-packages 文件夹位于 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
- Enthought 科学版 Python 也是如此(科学发行版,预装了许多模块,numpy、scipy、matplotlib...),
- (您也可以将 Homebrew Python 版本安装为框架,见下文)
- the official versions of Python.org are installed in /Library/Frameworks/Python.framework with site-packages folder in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
- same for the Enthought scientific version of Python (scientific distribution with many modules preinstalled, numpy, scipy, matplotlib,...),
- (you can also install the Homebrew Python version as a framework, see below)
您必须在 /usr/bin 中更改 Python 可执行文件的 PATH(通常,这是通过符号链接或在 /Users/me/.bash_profile 文件).
You must change the PATH of the Python executable in /usr/bin (usually, this is done automatically by the distribution by symlinks or in the /Users/me/.bash_profile file ).
安装在 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages 中的模块不会干扰安装在 /Library/Python 中的模块/2.7/site-packages 如果您使用适当的 Python 可执行文件,反之亦然.
The modules installed in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages do not interfere with those installed in /Library/Python/2.7/site-packages if you use the appropriate Python executable and viceversa.
b) 包管理系统方式
MacPorts 在文件夹 /opt/ 中安装自己的 Python 版本;
MacPorts install its own version of Python in the folder /opt/;
sudo port -v install python27
sudo port -v install python27
Fink 在文件夹 /sw/ 中安装自己的 Python 版本;
Fink install its own version of Python in the folder /sw/;
fink 安装 Python27
fink install Python27
Homebrew 在 /usr/local/Cellar 中安装 Python,并在 /usr/local/bin 中使用符号链接.
Homebrew installs Python in /usr/local/Cellar with symlinks in /usr/local/bin.
brew安装python
或
brew install python --framework
brew install python
or
brew install python --framework
要使用它们,您必须将 /sw/bin、/sw/lib/或/opt/bin、/opt/lib/ 添加到 PATH 并更改Python 可执行文件
To use them, you must add /sw/bin, /sw/lib/ or /opt/bin, /opt/lib/ to the PATH and change the PATH of the Python executable
c) 自主"方式
- 完美的解决方案是 Anaconda(另一种预装了许多模块的科学发行版,),
- 干净地安装到单个目录中(您想要的位置为 /Users/me/anaconda)
- 不需要 root 权限
- 不会影响您系统上的其他 Python 安装,或干扰 OS X 框架
- 只需设置 $PATH 或在 /Users/me/.bash_profile 中创建别名即可切换到/从 Anaconda
- 别名 anaconda='/Users/me/anaconda/bin/python'
- 别名 anaconda3='/Users/me/anaconda/envs/py33/bin/python3'
- the perfect solution is Anaconda (another scientific distribution with many modules preinstalled, ),
- Installs cleanly into a single directory (where you want as /Users/me/anaconda)
- doesn’t require root privileges
- doesn’t affect other Python installs on your system, or interfere with OS X Frameworks
- switch to/from Anaconda just by setting $PATH or creating an alias in /Users/me/.bash_profile
- alias anaconda='/Users/me/anaconda/bin/python'
- alias anaconda3='/Users/me/anaconda/envs/py33/bin/python3'
d) 硬"的方式
- 您可以以经典形式(在/usr/中)或作为框架编译您自己的 Python 版本.这需要时间,但并不难.
所以你的问题:
如何在包含可包含在 Xcode 中的框架的虚拟环境中安装 Python?
How can I get a Python installation in a virtual environment that includes a framework that I can include into Xcode?
除非您是 Unix 专家(路径管理),否则您必须使用 Apple 推荐的解决方案,即框架分发(包括 Apple Python)
Unless you are a Unix specialist (PATHs management) , you must use the Apple's recommended solution, a frameworks distribution (including the Apple Python)
这篇关于在 Mac OS X 虚拟环境中安装 Python,其中包含我可以包含到 Xcode 中的框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Mac OS X 虚拟环境中安装 Python,其中包含我可以包含到 Xcode 中的框架?
基础教程推荐
- Android - 如何在runOnUiThread 中将数据传递给Runnable? 2022-01-01
- 在视图控制器的宽度上水平均匀分布 UIButton 的最简单方法? 2022-01-01
- 更改 UITableView 部分标题的颜色 2022-01-01
- EditText 中的 setHintTextColor() 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Firebase 云消息传递令牌未生成 2022-01-01
- 从 UIWebView 访问元数据 2022-01-01
- 在 iOS 7 下 CCMenu 错位 2022-01-01
- UINavigationItem 的持久 rightBarButtonItem 属性 2022-01-01
- UINavigationBar 隐藏按钮文本 2022-01-01