1、用pip来使用第3方模块,先安装pip
# 下载安装脚本 $ curl -O https://bootstrap.pypa.io/get-pip.py # 安装 sudo python3 get-pip.py
2、安装成功后,查看安装版本,确定与你目前的python3版本一致
pip3 -V pip 22.1.2 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
3、安装virtualenv
pip3 install virtualenv
4、使用虚拟机环境
$ cd /var/www/your_project_name # 创建虚拟环境,其中py-env为你自定义的环境名称 $ virtualenv -p python3 py-env # 激活虚拟环境 $ source py-env/bin/activate # 这时命令行路径前面会出现你的虚拟环境名,例如: (py-env) [root@zjz ~]# # 查看你目前的插件,有些可能之前系统python环境已经安装了,你可以不用重复安装 pip3 list Package Version ---------- ------- pip 22.1.2 setuptools 62.6.0 wheel 0.37.1
5、安装python模块
pip3 install Flask Collecting Flask Using cached Flask-2.1.2-py3-none-any.whl (95 kB) Collecting itsdangerous>=2.0 Using cached itsdangerous-2.1.2-py3-none-any.whl (15 kB) Collecting Jinja2>=3.0 Using cached Jinja2-3.1.2-py3-none-any.whl (133 kB) Collecting click>=8.0 Using cached click-8.1.3-py3-none-any.whl (96 kB) Collecting Werkzeug>=2.0 Using cached Werkzeug-2.1.2-py3-none-any.whl (224 kB) Collecting importlib-metadata>=3.6.0 Using cached importlib_metadata-4.12.0-py3-none-any.whl (21 kB) Collecting zipp>=0.5 Using cached zipp-3.8.0-py3-none-any.whl (5.4 kB) Collecting MarkupSafe>=2.0 Using cached MarkupSafe-2.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB) Installing collected packages: zipp, Werkzeug, MarkupSafe, itsdangerous, click, Jinja2, importlib-metadata, Flask Successfully installed Flask-2.1.2 Jinja2-3.1.2 MarkupSafe-2.1.1 Werkzeug-2.1.2 click-8.1.3 importlib-metadata-4.12.0 itsdangerous-2.1.2 zipp-3.8.0
6、退出虚拟环境
deactivate
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/273790.html