Comparisonof time-If you're not using a Python virtual environment

Source: Internet
Author: User
Tags virtual environment continuum analytics

A computer for many years of the program Ape, bring you a few programming routines and a few smart tools, hope for your way of programming, add blood back to blue, together to chop thorns, common growth. Collectively: comparisonof time, 8th brother.

1. Why use a Python virtual environment

The actual work, we touch the Python version and the relevant version of the Web framework is often different, such as some combinations may be python2 + Django1.8, some may be python3.6 + Django1.12, two is OK, I installed two versions of P on the computer Ython not good?

However, if you have 5678 projects, you need 5678 sets of Python environments? This is the turn of the virtual environment.

2. Download and install
    • Tsinghua's Mirror [https://mirror.tuna.tsinghua.edu.cn/help/anaconda/]
    • Official note [http://conda.pydata.org/docs/using/envs.html]
2.1 Windows

Download the installation package directly, download it, and install it directly next to the default.

2.2 Linux or Mac

Direct download Script xxxx.sh, XXXX refers to version number, open console terminal, CD to that download directory, and then direct sh xxxx.sh installation is OK

3 How to Play-Basic Command 3.1 basic command description

(Windows best works with Conemu)
Related documents are here:
"8 Group programmer comparisonof Time" tool Link: https://pan.baidu.com/s/1i5HtBFn Password: kw4f

# view version Conda Info-envs or Conda env list# * * Note that to avoid your network being too slow, first run the following command to speed up some **conda config--add channels https:// Mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/conda config--set show_channel_urls yes# Install the full version Python2 Create-n py2 python=2 anaconda# Remove Virtual Environment Conda Remove--all-n 3todo# create only Django Python2 environment, name PY2-DJ, note, python=2 Django is a continuous parameter Conda Create python=2 django-n py2-dj# If you do not specify a python version, it is not able to drip, will error Conda create-n env-testerror:too Few arguments, must sup Ply command line Package specs or--file# so you can specify at least one Python version, without any libraries Conda create-n env-test python=3fetching Package Metada Ta ... # 2 ways to clone the environment 1. Pip (just copy the installation package) (Pytest) c:\programdata\anaconda3>cd D:\pyTools (pytest) C:\programdata\anaconda3>d: (pytest) D:\ Pytools>pip Freeze > Env.txtenv.txt The contents are as follows: django==1.10.5 new Environment Pytest2, and enter, join here only a requests (PYTEST2) D:\pyTools >pip freezerequests==2.14.2 under the Pytest package installed (PYTEST2) D:\pytools>pip freezerequests==2.14.2 (pytest2) d:\ Pytools>pip Install-r env.txtcollecting django==1.10.5 (From-r env.txt (line 1)) downloading DJANGO-1.10.5-PY2.PY3-NONE-ANY.WHL (6.8MB) 100% |██████████████████████████ ██████| 6.8MB 144kb/sinstalling collected packages:djangosuccessfully installed Django-1.10.5 (pytest2) D:\pytools>pip freezedjango==1.10.5requests==2.14.22. Use the Clone command (copy the entire environment) D:\pytools>conda Create--clone pytest2-n Py3source:c:\anaconda3\envs\pytest2destination:c:\an Aconda3\envs\py3 (py3) D:\pytools>pip freezedjango==1.10.5requests==2.14.2

Create a new virtual environment:

3.2 Write a Django Environment test:
D:\pyTools>cc py2dj18 python=2 django=1.8Fetching package metadata .......Solving package specifications: ..........coa py2dj18 # 激活环境1. 新建 projectdjango-admin.py startproject pxjgz2. 新建 appcd pxjgz 进入目录python manage.py startapp app01或 django-admin.py startapp app013. python manage.py runserver

Open the browser, you can 127.0.0.1:8000 see the work of the interface.

4 custom command Aliases [This is the key]

Are some of the above commands not working? Don't worry, because I have customized some.

Here is my own compilation, you can customize. Then put it on .bashrc , or you .bash_profile can!

4.1 Linux or Mac
# alias for conda alias cl="conda env list" alias cc="conda create -n" alias coa="source activate" alias cod="source deactivate" alias cr="conda remove --all -n"

Note: For Linux, it's a good idea to add an environment variable yourself, and you'll be alerted when the Conda script finishes executing.
Add the following line to the .bashrc ,

export PATH=/root/anaconda3/bin:$PATH

Don't forget to reload it at the end.

source ~/.bashrc

4.2 Windows is best used with Conemu

In Settings->startup>environment

alias cl=conda env listalias cc=conda create -n $*alias coa=activate $*alias cod=deactivatealias cr=conda remove --all -n $*
Example of "supplemental" use in Mac

Establish PY3-DJ, use and delete the entire process

-------~ CC PY3-DJ python=3 djangofetching package metadata .... Solving Package Specifications: ..... Package plan for installation in environment/users/howie/anaconda3/envs/py3-dj:the following packages would be downloaded            : Package |           Build---------------------------|-----------------django-1.9.5 |           PY35_0 3.6 MB setuptools-26.1.1 |                                           Py35_0 524 KB------------------------------------------------------------ total:4.1 mbthe following NEW packages would be installed:django:1.9.5-py35_0 openssl:1.0.2h -2 pip:8.1.2-py35_0 python:3.5.2-0 readline:6.2-2 setuptools:26.1.1-py35_0 sqlite:3.1 3.0-0 tk:8.5.18-0 wheel:0.29.0-py35_0 xz:5.2.2-0 zlib:1.2.8-3proceed ([y]/n)? yfetching Packages Django-1.9.5-p 100% |################################|time:0:00:08 437.51 kb/ssetuptools-26. 100% |################################| time:0:00:03 154.73 kb/sextracting Packages ... [Complete]|###################################################| 100%linking packages ... [Complete]|###################################################| 100%## to activate the environment, use:# $ source Activate py3-dj## to deactivate this environment, use:# $ source Deact  ivate#? ~ cl# Conda environments: #py2/users/howie/anaconda3/envs/py2py2-dj/users/howie/an Aconda3/envs/py2-djpy3-dj/users/howie/anaconda3/envs/py3-djroot */users/howie/anacon  Da3?  ~ CoA py3-dj (PY3-DJ)? ~ Pythonpython 3.5.2 | Continuum Analytics, inc.| (Default, Jul 2 2016, 17:52:12) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on Darwintype ' help ', ' copyright ', ' credits ' or ' license ' for more information.>>> import django>>> django.__version__ ' 1.9.5 ' >>>(PY3-DJ)?  ~ Cod? ~ cl# Conda environments: #py2/users/howie/anaconda3/envs/py2py2-dj/users/howie/an Aconda3/envs/py2-djpy3-dj/users/howie/anaconda3/envs/py3-djroot */users/howie/anacon  Da3? ~ CR Py3-djpackage Plan for package removal in environment/users/howie/anaconda3/envs/py3-dj:the following packages would Be removed:django:1.9.5-py35_0 openssl:1.0.2h-2 pip:8.1.2-py35_0 python:3.5.2-0 Read    Line:6.2-2 setuptools:26.1.1-py35_0 sqlite:3.13.0-0 tk:8.5.18-0 wheel:0.29.0-py35_0 Xz:5.2.2-0 zlib:1.2.8-3proceed ([y]/n)? Yunlinking packages ... [Complete]|###################################################| 100%

第8哥,转载请注明出处

Comparisonof time-If you're not using a Python virtual environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.