Create a virtual environment python3

 

The method of creating a virtual environment there are many, I'll share with you my most commonly used method of creating virtual environments and the use of some commands,

What is a virtual environment?

  Know you can skip, do not know can listen to the next, I simply said the words virtual environment, one you will understand what it means, first of all understand how the "environment", the environment is the code you write operation environment you this code is run under unix or linux or win under ah, here I am talking about operating platform is counted as an environment, and I give a more vivid example, say you are using djago module, he has a version divided it, and django2 djago1 the environment is not the same now, do you use djago1 a project, thinking to build a project in djago environment, this time, you django2 environment must be installed, but the question is, after you install django2, django1 version of this module will automatically be covered, that means you use djago1 environment disappears, your djago1 the code will error! how to do that? is there a way I can make two at the same time a django version of mutual coexistence? unaffected between projects it?

  So a good way to make money, using a virtual environment, he can let you simultaneously have two django, django two exist in two worlds, like parallel universes, like, django2 on the installation of both a world, and between the environment and the environment it will not affect each other up! thus avoiding the above problem!

 


virtualenvwrapper, upgraded version of the virtual environment tool

  1. Install, Do not activate the virtual environment
    pip3 install -i https://pypi.douban.com/simple virtualenvwrapper


  2. modify the configuration file, every time you turn on the tool load virtualenvwrapper

  1. Open a personal user profile environment variables
  global configuration file / etc / profile # Each user login take effect
  the user's personal configuration file ~ / .bash_profile

  vim ~ / .bash_profile #root landing time, reads this file the code

  2. fill in the following information, modify your own python environment for
  export WORKON_HOME = ~ / Envs # virtualenv set of unified management directory
  export VIRTUALENVWRAPPER_VIRTUALENV_ARGS = '- no-site -packages' # virtualenvwrapper add parameters to generate clean, isolated environment
  export VIRTUALENVWRAPPER_PYTHON = / opt / python367 / bin / python3.6 # Specifies the python interpreter
  source /opt/python367/bin/virtualenvwrapper.sh # virtualenvwrapper execute the installation script

  3. At this point you can use this tool to quickly create virtual environmental
  mkvirtualenv create a virtual environment virtual environment name # 
  lsvirtualenv # lists the virtual environment name 
  workon virtual environment name # activate or switch virtual environment 
  lssitepackages # listed in the module information in a virtual environment, in fact, 
  cdvirtualenv # home directory into the virtual environment 
  cdsitepackages # third-party modules into the virtual environment directory 

Guess you like

Origin www.cnblogs.com/well-666/p/11788389.html