Move in "/content"
import os
os.chdir("/content")
Setup git email and username
!git config --global user.email <"Your Email">
!git config --global user.name <"Your Username">
Clone the project from git
!git clone https://<token>@github.com/<Github Username>/<Repository Name>.git
Install poetry from pip
!pip install poetry
Move in the project folder (created after cloning the repository from git)
import os
os.chdir("/content/<Repository Name>")
Configure poetry not to create virtual environments in the project folder
!poetry config virtualenvs.in-project false
Install all dependencies and eventually add extra dependencies
!poetry install
# !poetry run pip install <Extra Dependency Name>
Add poetry virtual environment to python path so that all installed dependencies can be found by the python interpreter
import sys
sys.path.append("/root/.cache/pypoetry/virtualenvs/<Virtual Environment Name>/lib/<Python Version>/site-packages")
Move in the project folder and run the project
import os
os.chdir("/content/<Repository Name>")
!poetry run python <Path to main.py> <Arguments>
Hi @sirykd,
Thanks for your reply, it works!
And after all, my main issue was that pyproject.toml was not updated automatically, so I just decided to modify it by hand.
Here is the steps for using poetry in Colab, whether you create your own poetry project, or cloning a repo on Github.
https://github.com/elise-chin-adway/poetry-and-colab/blob/main/Using_python_poetry_in_Google_Colab.ipynb