代码改变世界

PyCharm使用pipenv创建虚拟环境

2021-06-25 13:27  abce  阅读(668)  评论(0编辑  收藏  举报

安装pipenv

  • pip install pipenv

创建项目目录

  • mkdir myproject

  • cd myproject

  • pipenv install # 创建虚拟环境

    To activate this project's virtualenv, run pipenv shell. Alternatively, run a command inside the virtualenv with pipenv run.

  • pipenv shell # 进入新环境

  • pipenv --venv

C:\Users\Administrator.virtualenvs\fisher-susCSosD

  • pipenv install flask # 安装第三方包

  • pipenv uninstall flask # 卸载第三方包

  • exit # 退出

配置PyCharm使用pipenv环境

  • 启动PyCharm,打开名称为myproject的项目

  • 进入项目设置,搜索Project Interpreter

  • 在Project Interpreter的右上角配置按钮上选择Add Local

  • 选择VirtualEnv Environment

  • 复制刚才的环境路径"C:\Users\Administrator.virtualenvs\fisher-susCSosD\Scripts\python.exe"到粘贴板,粘贴到existing environment的interpreter下面,点击确定。

  • 这样,就可以在PyCharm里用为myproject专门创建的python环境了。