SoFunction
Updated on 2024-11-13

Python development preparations for the configuration of the virtual environment (very important)

As a rookie, I never knew how to create virtual environments for development.python, are using the global to develop the project, so the end result is that all the packages are installed in the global, can not have a good in the switch!py2Now we explain the use of virtual environments for development under widow.pythonThe project takes care of that.

I. Steps for use

1. Installationvirtualenvwrapper

 # under window
 pip install virtualenvwrapper-win
 # under linux
 pip install virtualenvwrapper

2, configure the computer to store the virtual environment of the directory (note that after the configuration to exit the black window)

3. UsevirtualenvwrapperCreating a Virtual Environment

mkvirtualenv py3demo

4. Designationpythonreleases

mkvirtualenv --python=[You installpythonVersion file directory\] space name

5. Commonly used space commands

  • workonView all spaces
  • workon [space name]Get in that space.
  • deactivateExit current space

6、pycharmUsing the virtual environment of thepythonDevelopment projects (in the form ofdjango(Lecture) [inScriptsTable of Contents]

II. Supplementary notes

Sometimes we usepip installThe installation of the package is relatively slow, you can choose to use the domestic image to install, similar to thenpmchange to use taobao mirror the same, but do not recommend the global configuration, some of the latest package, the domestic mirror source may not be included

Using domestic mirror sources to speed up python pypi package installation

The default pip is to use the official Python source, but because the foreign official source is often walled, resulting in unavailability, we can use the domestic python mirror source, so as to solve the trouble of not installing libraries on Python.

There are many available sources online,for example:
Douban, PRC social networking website:/simple/
Tsinghua University:/simple 

Note the /simple directory at the back!!!!

1、Temporary use, only use the specified source when installing the pillow

pip3 install -i /simple pillow 

2、Permanent modification, once and for all

Linuxarrive at (a decision, conclusion etc),modifications ~/.pip/ (If you don't have one, create one.), modifications index-urluntiltuna,内容as ifarrive at (a decision, conclusion etc):

 [global]

 index-url = /simple

windowsarrive at (a decision, conclusion etc),directly in theuserdirectory to create apipcatalogs,as if:C:\Users\xx\pip,New file,内容as ifarrive at (a decision, conclusion etc):

 [global]

 index-url = /simple 

Third, in the mac system or linux system under the same operation

This is the whole content of this article.