Centos7安装使用 virtualenv 虚拟环境

[root@ansible-fcm ~]# pip3 install virtualenv
Successfully installed virtualenv-16.4.3
You are using pip version 9.0.3, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@ansible-fcm ~]# pip3 install --upgrade pip #升级pip
Successfully installed pip-19.0.3
[root@ansible-fcm bin]# ln -s /usr/Python-3.6.5/bin/virtualenv /usr/bin/virtualenv #创建软连接
[root@ansible-fcm MyFirstPython]# virtualenv --no-site-packages -p python3 ./venv #创建python3的虚拟环境

[root@ansible-fcm MyFirstPython]# ls 
venv  venv#创建python3的虚拟环境
[root@ansible-fcm MyFirstPython]# cd venv
[root@ansible-fcm venv]# ll
total 4
drwxr-xr-x. 2 root root 4096 Apr  4 05:03 bin
drwxr-xr-x. 2 root root   24 Apr  4 05:03 include
drwxr-xr-x. 3 root root   23 Apr  4 05:03 lib
[root@ansible-fcm MyFirstPython]# source venv/bin/activate #激活当前文件夹的沙盒
(venv) [root@ansible-fcm MyFirstPython]# pip install pylint #安装语法检测的包
[root@ansible-fcm MyFirstPython]# ls venv/bin/
activate      activate.fish  activate_this.py  easy_install      epylint  pip   pip3.6  pyreverse  python3    python-config  wheel
activate.csh  activate.ps1   activate.xsh      easy_install-3.6  isort    pip3  pylint  python     python3.6  symilar
[root@ansible-fcm MyFirstPython]# vim helloword.py
(venv) [root@ansible-fcm MyFirstPython]# ll
total 4
-rw-r--r--. 1 root root 19 Apr  4 05:09 helloword.py
drwxr-xr-x. 5 root root 43 Apr  4 05:03 venv
(venv)[root@ansible-fcm MyFirstPython]# python helloword.py 
hello vir
(venv) [root@ansible-fcm MyFirstPython]# vim helloword.py 
(venv) [root@ansible-fcm MyFirstPython]# chmod +x helloword.py 
(venv) [root@ansible-fcm MyFirstPython]# ./helloword.py 
hello vir

(venv) [root@ansible-fcm MyFirstPython]# deactivate #终止当前虚拟环境
[root@ansible-fcm MyFirstPython]# 

 

你可能感兴趣的:(云计算)