Skip to content

Instantly share code, notes, and snippets.

@papaemman
Last active July 22, 2023 16:03
Show Gist options
  • Select an option

  • Save papaemman/edd6820699483c53cde99cec9dbcc585 to your computer and use it in GitHub Desktop.

Select an option

Save papaemman/edd6820699483c53cde99cec9dbcc585 to your computer and use it in GitHub Desktop.
Use Poetry and Pyenv for Dependecy managment in python

Using Poetry and Pyenv for Python Dependency Management

Step 1

  1. Install pyenv https://github.com/pyenv/pyenv

    > curl https://pyenv.run | bash
    > 
    > nano .bashrc
    
    # Add to .bashrc
    export PATH="$HOME/.pyenv/bin:$PATH"
    eval "$(pyenv init --path)"
    eval "$(pyenv virtualenv-init -)"
    
  2. Install poetry https://python-poetry.org/docs/#installation

    > curl -sSL https://install.python-poetry.org | python3 -
    > nano .bashrc
    # Add
    export PATH="/home/panos/.local/bin:$PATH
    

Step 2

Install required Python version:

pyenv install -l
pyenv --version
pyenv install 3.9.17
pyenv local 3.9.17
pyenv versions

Step 3

Configure Poetry to create the virtual environment in the project root:

> poetry --version
> poetry config virtualenvs.in-project true

Step 4

Start poetry and follow the prompts

poetry init

Step 5

Install all the dependencies with a single command:

poetry install

Step 6

Activate the virtual environment

poetry check
poetry shell

Step 7

Add Jupyter notebook support and add virtual environment as kernel

> poetry add --group dev ipykernel
> jupyter kernelspec list
> poetry run python -m ipykernel install --name=.venv --user

README.md

Using Poetry and Pyenv for Dependency Management

  1. Install pyenv https://github.com/pyenv/pyenv and poetry https://python-poetry.org/docs/#installation on your machine.

  2. Install the appropriate Python version:

    cd ./email-classifier-ai
    pyenv install 3.9.16
    pyenv local 3.9.16
    
  3. Configure Poetry to create the virtual environment in the project root:

    poetry config virtualenvs.in-project true
    
  4. Install all the dependencies with a single command:

    poetry install
    
  5. Activate the virtual environment

    poetry shell
    
  6. Run the server

    uvicorn src.main:app --reload
    

The API is live at http://localhost:8000.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment