简体   繁体   English

Mac OS X虚拟环境中的Python安装是否包括我可以包含在Xcode中的框架?

[英]Python installation in Mac OS X virtual environment that includes a framework that I can include into Xcode?

I like to use Python with numpy, scipy and some other packages. 我喜欢将Python与numpy,scipy和其他一些软件包一起使用。 I am an absolute Python beginner and have some issues with the installation under Mac OS X. 我是绝对的Python初学者,在Mac OS X下安装时遇到一些问题。

I am following these two tutorials to install python: 1 and 2 . 我正在按照这两个教程安装python: 12

Here, HomeBrew is used to install Python (with pip) and virtualenv. 在这里,HomeBrew用于安装Python(带有pip)和virtualenv。 I do not have an opinion about what is better, MacPorts, HomeBrew, Fink... I just found this tutorial inspiring confidence. 我对MacPorts,HomeBrew,Fink哪个更好没有意见……我只是发现本教程激发了人们的信心。

If I understand things correctly, OS X system Python, which I should never touch, is under /System/Library/Frameworks/Python.Framework. 如果我理解正确,那么我永远都不会碰的OS X系统Python位于/System/Library/Frameworks/Python.Framework下。 And I cannot use this one in Xcode because it does not have my wanted packages. 而且我不能在Xcode中使用此代码,因为它没有我想要的软件包。 The HomeBrew Python will be installed somewhere in /usr/local/. HomeBrew Python将安装在/ 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. 本教程说明,最好仅在虚拟环境中通过pip安装其他软件包。 But I cannot find a framework there. 但是我在那里找不到框架。

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? 所以我的问题是:如何在虚拟环境中安装Python,并将其包含在Xcode中?

  1. 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 ). Apple Python可以正常使用,并且正常的site-packages文件夹为/Library/Python/2.7/site-packages (而不是/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages )。 You can use it without problem. 您可以毫无问题地使用它。
  2. 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. 我可以毫无问题地安装所有我想作为框架的模块(numpy,scipy,matplotlib,pandas,shapely和其他...),或者安装pip或easy_install,包括virtualenv(只需在Python中以常规方式安装它们) )或创建虚拟环境。
  3. when you install a framework module, It is placed in in the normal site-packages folder. 当您安装框架模块时,它将放置在普通的site-packages文件夹中。
  4. 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版本(使用2.6.x,2.7.x和3.3.x版本对我来说不是问题)

But if you want, you can install others versions of Python (in 64-bits, not 32 !): 但是,如果您愿意,可以安装其他版本的Python(64位而不是32位!):

a) the way prescribed by Apple: as a framework a)苹果规定的方式:作为框架

  • 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 Python.org的正式版安装在/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages中的site-packages文件夹中的/Library/Frameworks/Python.framework中
  • same for the Enthought scientific version of Python (scientific distribution with many modules preinstalled, numpy, scipy, matplotlib,...), 与Python的科学版科学思想相同(科学发行版,其中预先安装了许多模块,numpy,scipy,matplotlib等),
  • (you can also install the Homebrew Python version as a framework, see below) (您也可以将Homebrew Python版本安装为框架,请参见下文)

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 ). 您必须在/ usr / bin中更改Python可执行文件的PATH(通常,这是通过符号链接的分发或/Users/me/.bash_profile文件自动完成的)。

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. 安装在/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages的模块不与安装在/Library/Python/2.7/site-packages这些干扰,如果你使用适当的Python可执行程序反之亦然。

b) the package management system way b)包裹管理系统方式

  • MacPorts install its own version of Python in the folder /opt/ ; MacPorts在文件夹/ opt /中安装自己的Python版本。

    sudo port -v install python27 须藤端口-v安装python27

  • Fink install its own version of Python in the folder /sw/ ; Fink在/ sw /文件夹中安装自己的Python版本。

    fink install Python27 芬克安装Python27

  • Homebrew installs Python in /usr/local/Cellar with symlinks in /usr/local/bin . Homebrew在/ usr / local / bin中通过符号链接在/ usr / local / Cellar中安装Python。

    brew install python brew安装python
    or 要么
    brew install python --framework brew安装python --framework

  • 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 要使用它们,必须将/ sw / bin,/ sw / lib /或/ opt / bin,/ opt / lib /添加到PATH并更改Python可执行文件的PATH

  • For me, the main problem with Fink and MacPorts is that they do not take into account what is already installed and install all in their respective folders which can create real problems in the management of library paths. 对我来说,Fink和MacPorts的主要问题是它们没有考虑已经安装的内容,而是将它们全部安装在各自的文件夹中,这可能在管理库路径时造成真正的问题。
  • The Homebrew solution is "cleaner" (in /usr/local ) and is based on existing libraries if they are up to date, otherwise it installs its own versions of the libraries Homebrew解决方案“更干净”(在/ usr / local中 ),并且基于现有库(如果它们是最新的),否则将安装其自己的库版本

c) the "autonomous" way c)“自主”方式

  • the perfect solution is Anaconda (another scientific distribution with many modules preinstalled, ), 完美的解决方案是Anaconda (另一种科学发行版,其中预先安装了许多模块),
    • Installs cleanly into a single directory (where you want as /Users/me/anaconda ) 干净地安装到单个目录(您希望以/ Users / me / anaconda位置
    • doesn't require root privileges 不需要root权限
    • doesn't affect other Python installs on your system, or interfere with OS X Frameworks 不会影响系统上其他Python的安装,也不会干扰OS X Frameworks
    • switch to/from Anaconda just by setting $PATH or creating an alias in /Users/me/.bash_profile 只需通过设置$ PATH或在/Users/me/.bash_profile中创建别名即可与Anaconda进行切换
      • alias anaconda='/Users/me/anaconda/bin/python' 别名anaconda ='/ Users / me / anaconda / bin / python'
      • alias anaconda3='/Users/me/anaconda/envs/py33/bin/python3' 别名anaconda3 ='/ Users / me / anaconda / envs / py33 / bin / python3'
    • you can install Python versions from 2.6.x to 3.3.x 您可以安装2.6.x至3.3.x的Python版本
    • Innovative package and environment manager for Python, named conda , but you can use pip or easy_install without problem 适用于Python的创新软件包和环境管理器,名为conda ,但您可以使用pip或easy_install而不会出现问题
    • for me now, it is the best solution to install virtual environments (as /Users/me/anaconda/envs/py33 ) 对我而言,这是安装虚拟环境的最佳解决方案(如/ Users / me / anaconda / envs / py33

d) the "hard" way d)“硬性”方式

  • you can compile your own version of Python in a classical form (results in /usr/) or as a framework. 您可以以经典形式(结果为/ usr /)或作为框架来编译自己的Python版本。 It takes time but it is not difficult. 这需要时间,但并不难。

So your question: 所以你的问题是:

How can I get a Python installation in a virtual environment that includes a framework that I can include into Xcode? 我如何在虚拟环境中安装Python,该虚拟环境包括可以包含在Xcode中的框架?

Unless you are a Unix specialist (PATHs management) , you must use the Apple's recommended solution, a frameworks distribution (including the Apple Python) 除非您是Unix专家(PATHs管理),否则必须使用Apple推荐的解决方案,框架发行版(包括Apple Python)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM