有关虚拟环境的相关的我之前也介绍过,python高级(4)—— 虚拟环境安装使用 比如pipenv,还有virtualenv之类的,还有本篇文章的主角 -- poetry
到底哪个更好用呢,看你个人吧,我觉得poetry更好一点咯,不过还是看个人喜好了
一:conda创建虚拟环境1.安装conda这个就省略了,网上太多教程了 2.创建虚拟环境:conda create -n py37 python=3.7
二:poetry使用教程简介:poetry是一个依赖项管理和打包工具,它运行声明项目所依赖的库,很方便的管理项目环境,仅支持python3.6+ 安装:官方不推荐用pip安装,虽然也能安装,但是使用起来不方便 1.mac/linux:curl -sSL https://raw./python-poetry/poetry/master/get-poetry.py | python3 2.windows:
配置poetry环境变量windows系统:path变量里添加如下: mac/linux:
验证是否安装成功
注意:如果上面安装时,速度较慢解决办法:
poetry常用命令三: pip 切换安装源
四:poetry+conda配置环境以下步骤请在终端下执行,如果是windows的话,建议使用commder或者ConEmu,不要用cmd,cmd有中文编码问题 0.创建目录:poetry new xx文件夹名 1.初始化:
This command will guide you through creating your pyproject.toml config.
Package name [baseprojectone]:
Version [0.1.0]:
Description []:
Author [xxxxxx <yh@xxxxxtech.com>, n to skip]:
License []:
Compatible Python versions [^3.7]:
Would you like to define your main dependencies interactively? (yes/no) [yes] no
Would you like to define your development dependencies interactively? (yes/no) [yes] no
Generated file
[tool.poetry]
name = "baseprojectone"
version = "0.1.0"
description = ""
authors = ["xxxxxx <yh@xxxxxtech.com>"]
[tool.poetry.dependencies]
python = "^3.7"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Do you confirm generation? (yes/no) [yes]
2.指定解释器:
3.安装相关初始环境
Updating dependencies
Resolving dependencies... (12.4s)
Writing lock file
Package operations: 13 installs, 0 updates, 0 removals
· Installing typing-extensions (3.7.4.3)
· Installing zipp (3.4.0)
· Installing importlib-metadata (3.4.0)
· Installing pyparsing (2.4.7)
· Installing atomicwrites (1.4.0)
· Installing attrs (20.3.0)
· Installing colorama (0.4.4)
· Installing more-itertools (8.6.0)
· Installing packaging (20.8)
· Installing pluggy (0.13.1)
· Installing py (1.10.0)
· Installing wcwidth (0.2.5)
· Installing pytest (5.4.3)
四.配置项目环境:
poetry add requests 注意:
如果有提示更新pip的,复制相关命令执行:C:\Users\xxxxx\AppData\Local\pypoetry\Cache\virtualenvs\mypj1-HtrT1G92-py3.7\Scripts\python.exe -m pip install --upgrade pip Updating dependencies
Resolving dependencies... (3.8s)
Package operations: 1 install, 0 updates, 0 removals
· Installing xxx (0.0.2 1bd38afe2c)
五:pycharm使用poetry创建的虚拟环境创建项目
1.pycharm先安装poetry插件低版本的pycharm不支持,最好用最新版pycharm
2.打开项目所在目录:在打开时,会弹出一个创建bat文件的窗口,点【ok】
接下来就可以进行你的项目开发了
|
|