Tips of Python virtual environment

    virtualenvwrapper

    virtualenvwrapper provides a set of commands which makes working with virtual environments much more pleasant. It also places all your virtual environments in one place.

    pip install packages

    $ sudo pip install virtualenv virtualenvwrapper
    

    Edit the profile ~/.bashrc, add the following lines

    ...
    ...
    # virtualenv and virtualenvwrapper
    export WORKON_HOME=$HOME/.virtualenvs
    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
    source /usr/local/bin/virtualenvwrapper.sh
    

    Apply the profile

    $ source ~/.bashrc
    
    Create a virtual environment
    $ mkvirtualenv py3cv3 -p python3
    
    py3cv3 is my project name, you can name it as whatever you like (and create as many Python virtual environments as you want).
    -p specify the version of python
    Quit virtualenv console
    (env)$ deactivate
    
    Remove a virtual environment
    $ rmvirtualenv py3cv3
    
    Other useful commands
    // List all of enviroments
    $ lsvirtualenv
    or
    $ workon
    
    // Navigate into the directory of the currently activated virtual environment
    $ workon your-env
    $ cdvirtualenv
    
    // Like the above, but directly into site-packages directory.
    $ workon your-env
    $ cdsitepackages
    
    // Shows contents of site-packages directory.
    $ workon your-env
    $ lssitepackages
    
    標籤 (Edit tags)
    • No tags
    您必須 登入 才能發佈評論。
    Powered by MindTouch Core