venv 이용하는 방법
python3 -m venv [env name]source [env name]/bin/activate
How to escape :
Ctrl + D
pyenv
you can use multiple python by using
pyenv
How to install (in Mac)
1
2
3
4
brew update
brew install pyenv
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
How to use
- Install additional python :
pyenv install [python version]eg.pyenv install 3.9.7 - Setup python in current directory :
pyenv local [python version]eg.pyenv local 3.9.7 - Unset python in current directory :
pyenv local --unset
Poetry
Why poetry
- smarter dependency resolvement compared to pip
- easier virtual env setting
- easier packaging
How to use
pip3 install poetry: install poetrypoetry shell: activate virtual envdeactivate: stop virtual env
- Use following commands
poetry install: generate poetry.lock file and install dependencies--no-root: do not install root packages(your project)--no-dev: skip development dependencies
poetry update: update poetry.lock filepoetry run [command]: run command in virtual envpoetry add: adds required packages to yourpyproject.toml- eg.
poetry add pendulum@^2.0.5orpoetry add "pendulum>-2.0.5
- eg.
- Using different python version
poetry env use python3.xorpoetry env use 3.x
- Remove virtual env
- cd into the folder where pyproject.toml is
- Run poetry env list (this will show you the venv for that project)
- Then run poetry env remove whatever-WhATeVs-py3.9 to delete it