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, thank you for this tutorial! It is well explained π
I tried to reproduce it but unfortunately, I encountered some issues.
1.
poetry install
does not workI have a github repo with
poetry.lock
andpyproject.toml
, I cloned it using Colab, moved in the project folder as you specified, but then when I run!poetry install
, no packages are installed in the virtual environment, and not even in Colab environment... The output is the following:I can't find why it is not working π£
2.
poetry add <package>
According to poetry's documentation, to install a new package, we need to run
poetry add
. I ran this command, but again no packages are installed. Moreover, thepoetry.lock
file is indeed updated, but not thepyproject.toml
. This happens only on Colab, I tried on my local computer, and the command indeed automatically update thepyproject.toml
file as well.3.
poetry run pip install <package>
So I followed the above command, that you indicated in this tutorial. The packages are installed in the virtual environment, but
pyproject.toml
is not updated.Also, what is the difference between
poetry run pip install <package>
andpoetry add <package>
?Thank you in advance for your help π