Virtualenv condaenv

本文总阅读量次 ,原创教程,严禁转载

It's worth mentioning pip here as well, as conda and pip have similarities and differences that are relevant to this topic.

pip: the Python Package Manager.

You might think of pip as the python equivalent of the ruby gem command pip is not included with python by default. You may install Python using homebrew, which will install pip automatically: brew install python The final version of OSX did not include pip by default. To add pip to your mac system's version of python, you can sudo easy_install pip You can find and publish python packages using PyPI: The Python Package Index The requirements.txt file is comparable to the ruby gemfile To create a requirements text file, pip freeze > requirements.txt Note, at this point, we have python installed on our system, and we have created a requirements.txt file that outlines all of the python packages that have been installed on your system. pyenv: Python Version Manager

From the docs: pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. This project was forked from rbenv and ruby-build, and modified for Python. Many folks hesitate to use python3. If you need to use different versions of python, pyenv lets you manage this easily. virtualenv: Python Environment Manager.

From the docs: The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded. To create a virtualenv, simply invoke virtualenv ENV, where ENV is is a directory to place the new virtual environment. To initialize the virtualenv, you need to source ENV/bin/activate. To stop using, simply call deactivate. Once you activate the virtualenv, you might install all of a workspace's package requirements by running pip install -r against the project's requirements.txt file. Anaconda: Package Manager + Environment Manager + Additional Scientific Libraries.

From the docs: Anaconda 4.2.0 includes an easy installation of Python (2.7.12, 3.4.5, and/or 3.5.2) and updates of over 100 pre-built and tested scientific and analytic Python packages that include NumPy, Pandas, SciPy, Matplotlib, and IPython, with over 620 more packages available via a simple conda install As a web developer, I haven't used Anaconda. It's ~3GB including all the packages. There is a slimmed down miniconda version, which seems like it could be a more simple option than using pip + virtualenv, although I don't have experience using it personally. While conda allows you to install packages, these packages are separate than PyPI packages, so you may still need to use pip additionally depending on the types of packages you need to install. See also:

conda vs pip vs virtualenv (section in documentation from anaconda) the difference between pip and conda (stackoverflow) the relationship between virtualenv and pyenv (stackoverflow)