Ubuntu 18.04 install virtualenv and virtualenvwrapper

Install and configure virtualenv and virtualenvwrapper

  1. Install virtualenv and virtualenvwrapper
    pip install virtualenv
    pip install virtualenvwrapper
    
  2. Create folder
    mkdir $HOME/.virtualenvs
    
  3. Add in ~/.bashrc
    export WORKON_HOME=$HOME/.virtualenvs
    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
    source /usr/local/bin/virtualenvwrapper.sh
    
    The location of virtualenvwrapper.sh depends on the situation. It may be in the \usr\local\binmiddle or ~/.local/binmiddle.
  4. Activate the .bashrc file
    source .bashrc
    

Note: If ERROR: virtualenvwrapper could not find virtualenv in your path appears , you can ~/.bashrcadd PATH=$PATH:~/.local/binor PATH=$PATH:/usr/local/bin.

pip change source

Commonly used domestic sources

How to modify the source

  1. temporary use
    1. When using pip, add -iparameters to specify the pip source.
      For example:
      	pip install scrapy -i  http://mirrors.aliyun.com/pypi/simple/
      
  2. Permanent modification
    1. create~/.pip/pip.conf
    2. Add the following content
      [global]
      index-url = https://pypi.tuna.tsinghua.edu.cn/simple
      
    3. Just save

Common commands for virtualenv

  1. Create a virtual environment
    1. Based on python2
      mkvirtualenv <env_name>
      
    2. Based on python3
      mkvirtualenv -p python3 <env_name>
      
    Note: The creation of a virtual environment requires networking. After the creation is successful, it will automatically work on this virtual environment (env_name will appear before the command line prompt).
  2. Exit the virtual environment
    deactivate
    
  3. Delete virtual environment
    rmvirtualenv <env_name>
    
  4. View all virtual environments
    workon
    
    or
    lsvirtualenv
    
  5. Navigate to the directory of the currently active environment
    cdvirtualenv
    
  6. Navigate to the site-packages directory of the currently active environment
    cdsitepackages
    
  7. Display all contents in the site-packages directory
    lssitepackages
    
  8. View the installed packages in the current environment
    pip list
    
    or
    pip freeze
    
  9. Check which packages in the current environment need to be updated
    pip list --outdated
    
    or
    pip list -o
    
  10. Upgrade the current environment package
    pip install -U package_name
    
    or
    pip install --upgrade package_name
    
  11. Install the package online for the current environment (you can specify the package version by using "==", ">=", "<=", ">", "<")
    pip install package_name
    
    or
    pip install -r package_names.txt
    
  12. Install the downloaded local installation package for the current environment
    pip install <目录>/<文件名>
    
  13. Uninstall the package of the current environment
    pip uninstall package_name
    
    or
    pip uninstall -r package_names.txt
    
  14. View the package directory
    pip show -f package_name
    
  15. Search package
    pip search keywords
    
  16. Download the package without installing
    pip install package_name -d <目录>
    
    or
    pip install -r package_names.txt -d <目录>
    
  17. Package all packages of the current virtual environment
    pip freeze > package_names.txt
    

Guess you like

Origin blog.csdn.net/qyhaill/article/details/98472936