美文网首页Python 运维
使用virtualenv搭建python3开发环境

使用virtualenv搭建python3开发环境

作者: 靖小侠 | 来源:发表于2017-02-23 13:32 被阅读1138次

First step -install virtualenv:

sudo pip install virtualenv

Now create one python dev environment

'>'virtualenv venv

New python executable in /home/ubuntu/venv/bin/python

Installing setuptools, pip, wheel...done.

Usersourceavtivate virtualenv environment

'>'source venv/bin/activate

(venv)>wich python

/home/ubuntu/venv/bin/python

Quit

(venv)>deactivate

virtualenv定制化

生成virtualenv环境时同时安装flake8的自定义脚本:

'>'sudo chown ubuntu:ubuntu 'which virtualenv'

生成自定义脚本如下(create-venv-script.py):

import subprocess

import virtualenv

virtualenv_path = subprocess.check_output(['which', 'virtualenv']).strip()

EXTRA_TEXT = '''

def after_install(options, home_dir):

subprocess.call(['{}/bin/pip'.format(home_dir), 'install', 'flask8'])

'''

def main():

text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version='2.7')

print 'Updating %s' % virtualenv_path

with open (virtualenv_path, 'w') as f:

f.write(text)

if __name__ == '__main__':

main()

生成脚本:

'>'python /''/create-venv-script.py

Updating /usr/local/bin/virtualenv

现在生成一个虚拟环境,就会自动安装flake8了:

'>'virtualenv tmp

New python executable in /home/ubuntu/web_dev/tmp/bin/python2.7

Also creating executable in /home/ubuntu/web_dev/tmp/bin/python

Installing setuptools, pip, wheel...done.

...

Installing collected packages: mccabe, pyflasks, pep8, flake8

Succerssfully installed flake8-2.5.4 mccabe-0.4.0 pep8-1.7.0 pyflakes-1.0.0

搭建python3开发环境

创建虚拟环境

virtualenv -p /usr/local/bin/python3.4 py34env激活

source py34env/bin/activate

退出虚拟环境

deactivate


原文链接

相关文章

网友评论

    本文标题:使用virtualenv搭建python3开发环境

    本文链接:https://www.haomeiwen.com/subject/foqbwttx.html