V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2017-06-07 15:05:20 +08:00 · 1005 次点击
    这是一个创建于 2517 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 
    ~$ 
    

    参考

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1079 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 18:35 · PVG 02:35 · LAX 11:35 · JFK 14:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.