問題描述
我在我的 Mac OS X 上廣泛使用 Python,用于數字應用程序和 Web 開發(大致相同).我檢查了我最近在筆記本電腦上安裝的 Python 數量,震驚地發現 四個:
I use Python extensively on my Mac OS X, for both numerical applications and web development (roughly equally). I checked the number of Python installations I had on my laptop recently, and was shocked to find four:
Came with Mac OS X:
/usr/bin/python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Installed via Homebrew
/usr/local/bin/python
Python 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Installed via Anaconda/Miniconda
~/anaconda/bin/python
Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, Oct 19 2015, 18:31:17)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
Came with the downloaded .pkg from python.org
/System/Library/Frameworks/Python.framework/Versions/Current/bin/python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
我決定統一所有這些,并使用 conda
.我刪除了 Homebrew 版本和 Python.org 下載(保留主系統).Conda 非常適合數值計算,因為我可以在根環境中安裝 Jupyter/Numpy/Pandas,而不必為每個項目都安裝 virtualenvs.
I decided to unify all of this, and use conda
. I removed the Homebrew version and the Python.org download (kept the main system one). Conda is great for numerical computing, because I can install Jupyter/Numpy/Pandas in the root environment, and not have to bother install virtualenvs for every project.
但是現在我的整個 Web 開發工作流程都搞砸了.我的 virtualenvs 都不起作用,因為顯然不應該同時使用 conda 和 virtualenv.我嘗試從 requirements.txt
文件創建 conda 環境.我與 django 一起使用的一個包是markdown_deux",它在 Conda 存儲庫中不可用.我查看了構建它的方法,但創建一個配方需要付出很多努力(創建 YAML 文件等)
But now my entire web development workflow is messed up. None of my virtualenvs work, since apparently one's not supposed to use conda and virtualenv together. I tried to create conda environments from the requirements.txt
file. One package I was using with django was "markdown_deux", which is not available in the Conda repo. I looked at ways of building it, but creating a recipe takes a lot of effort (create YAML file, etc..)
有沒有人為此找到一個好的折衷方案?我正在考慮回到自制版本以供一般使用,并編寫一個別名以根據需要將路徑更改回 conda 版本.雖然這也需要跟蹤我現在使用的是哪一個..
Has anyone found a good compromise for this? I'm thinking of going back to the homebrew version for general use, and writing an alias for changing the path back to the conda version as necessary. Though this will also require tracking which one I'm using now..
推薦答案
我的所有項目(數據科學、一些 Web 開發)都使用 Homebrew Python.
I use Homebrew Python for all my projects (data science, some web dev).
Conda 沒有什么花哨的,您可以通過組合 pip
和 自制科學.實際上,它甚至更好,因為您可以更好地控制您安裝的內容.
Conda is nothing fancy, you can have the same packages by hand with a combination of pip
and Homebrew science. Actually, it is even better because you have more control on what you install.
您只能在進行 Web 開發時使用您的 virtualenvs.對于數字應用程序,您可能希望始終擁有最新版本的軟件包.
You can use your virtualenvs only when you do web development. For the numerical applications you will probably want to have the latest versions of your packages at all times.
如果你想用 pip 一次性更新你所有的包,你可以使用這個命令:
If you want to update all your packages at once with pip, you can use this command:
sudo -H pip freeze --local | grep -v '^-e' | cut -d = -f 1 | xargs -n1 sudo -H pip install -U
這個答案是舊的,如果你想要一個更最新的比較,我發現這篇不錯的博客文章比較了這兩種方法:
This answer is old, if you want a more up-to-date comparison, I found this nice blog article which compares the two approaches:
https://towardsdatascience.com/pipenv-vs-conda-for-data-scientists-b9a372faf9d9
我仍然使用 Homebrew Python,并在 conda 上使用 pip/pipenv.
I still use Homebrew Python, and pip / pipenv over conda.
這篇關于OS X - 在 anaconda 和自制 Python 環境之間做出決定的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!