python虚拟环境创建和激活

作者: admin 分类: Python 发布时间: 2019-04-15 18:39

#00创建虚拟环境

$ mkdir 04Form
$ python3 -m venv 04Form/

# 查看虚拟环境目录结构
$ cd 04Form
$ ls
bin  include  lib  lib64  pyvenv.cfg  share

# 查看虚拟环境配置
$ vi pyvenv.cfg

--------------------------------------
home = /usr/bin
include-system-site-packages = false
version = 3.5.2
--------------------------------------

或者在文件夹中直接运行创建虚拟环境

$ pip install pipenv
euming@eumingdeMBP:~/Documents/PyCharm/04Form % ll
total 56
-rw-r--r--   1 euming  staff   244B  4  1 15:01 Pipfile
-rw-r--r--   1 euming  staff   7.7K  4  1 15:01 Pipfile.lock
drwxr-xr-x   4 euming  staff   128B  4  1 17:48 __pycache__
-rw-r--r--   1 euming  staff   7.6K  4  1 17:48 app.py
-rw-r--r--   1 euming  staff   2.7K  4  1 17:23 forms.py
-rw-r--r--@  1 euming  staff   631B  3 30 23:23 readme.txt
drwxr-xr-x   6 euming  staff   192B  3 30 23:27 static
drwxr-xr-x  16 euming  staff   512B  4  1 17:33 templates
drwxr-xr-x  10 euming  staff   320B  4  1 17:48 uploads
drwxr-xr-x   8 euming  staff   256B  3 30 23:22 venv

#02激活虚拟环境

$ cd work
$ source bin/activate

# 前面有括号xx,即表示虚拟环境激活成功,在激活环境下pip安装的包单独管理,不会冲突 
(04Form) $

#03退出虚拟环境

(04Form) $ deactivate

发表评论

电子邮件地址不会被公开。 必填项已用*标注