推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ansheng
V2EX  ›  Python

Ubuntu 上使用 virtualenv 和 virtualenvwrapper

  •  
  •   ansheng ·
    anshengme · Jun 7, 2017 · 1348 views
    This topic created in 3284 days ago, the information mentioned may be changed or developed.

    virtualenvvirtualenvwrapper在 Python 虚拟环境中真是天作之合,我没有用过pyenv...

    安装

    如果你使用的是python3,那么你需要用pip(python2)来安装包

    $ sudo pip3 install virtualenv virtualenvwrapper
    

    配置

    • 设置默认使用 python 版本

    .profile或者.bashrc文件中加入下行环境变量

    $ echo 'export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3' >> .bashrc 
    $ tail -1 .bashrc 
    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
    $ source .bashrc 
    
    • 生成 virtualenvwrapper
    $ source /usr/local/bin/virtualenvwrapper.sh
    

    使用

    • 创建一个新的 virtualenv
    $ mkvirtualenv as  # 因为已经指定了默认的 Python 版本,所以默认的是 Python3
    (as) ~$  # 创建成功之后会自动进入 virtualenv 中
    
    • 退出 virtualenv

    在任意目录执行deactivate就可以退出

    (as) ~$ deactivate 
    ~$ 
    
    • 查看所有 virtualenv
    ~$ workon 
    as
    
    • 在工作环境之间切换
    ~$ workon as
    (as) ~$ 
    
    • 删除一个 virtualenv
    (as) ~$ deactivate 
    ~$ rmvirtualenv as
    Removing as...
    ~$ workon 
    ~$ 
    

    参考

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5190 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 05:52 · PVG 13:52 · LAX 22:52 · JFK 01:52
    ♥ Do have faith in what you're doing.