gitpod icon indicating copy to clipboard operation
gitpod copied to clipboard

Python init prebuild not working

Open quental96 opened this issue 4 years ago • 4 comments

Bug description

Hello,

Prebuilds in python are not working at all for me, and I am following exactly what the docs advise. My problem is even reproducible in the official gitpod pandas example.

The prebuild looks like this:

tasks:
   - init: pip3 install -r requirements.txt
     command: python3 src/app.py

When I launch any type of workspace that has this sort of prebuild for the first time, it seems to work. However, the second time that I launch it, the init has not been saved; what this means here is that the python packages are not present and the command fails because of import errors.

I have been struggling with this for a couple days now and I found other inconsistencies with the docs. Namely, My pyenv is never saved. This is impossible to work with because I have to reinstall everything each time I reopen a workspace…

Thanks for your quick help, I can’t do any Gitpod work while this is not fixed…

Quentin

Steps to reproduce

  • Launch the example cited above.
  • Wait for init and command.
  • Close workspace.
  • Reopen workspace.

Workspace affected

ivory-cardinal-kxl6nm71

Expected behavior

Workspace should be saved.

Example repository

https://github.com/gitpod-io/Gitpod-Pandas

Anything else?

No response

quental96 avatar Dec 06 '21 10:12 quental96

Similar to this.

quental96 avatar Dec 06 '21 11:12 quental96

Also Similar to https://github.com/gitpod-io/gitpod/issues/7110 I also have the same issue.

tiamot avatar Dec 18 '21 01:12 tiamot

Here is the fix (thank you @lechien73, see: https://github.com/gitpod-io/gitpod/issues/7064#issuecomment-988049050):

Problem & Solution Walkthrough

  • Create a new repo (e.g. test-for-prebuild) in gitlab with a readme (or github or bitbucket, etc)
  • Launch gitpod
  • Initialize gitpod with gp init
  • Edit .gitpod.yml
tasks:
  - init: pip install pip_install_test
  • Commit your changes and sync

The library is installed in new workspaces

  • Manually stop the workspace and restart it
  • From the terminal:
gitpod /workspace/test-for-prebuild $ pip freeze | grep pip-install-test
pip-install-test==0.5

We can see from the pip freeze, that the library pip-install-test is indeed available in this new workspace. 👍🏼

Turning on prebuild breaks something

  • Manually stop the workspace
  • Launch a prebuild by prefixing the repo path with gitpod.io/#prebuild/
  • From the terminal:
gitpod /workspace/test-for-prebuild $ pip freeze | grep pip-install-test

We can see from the pip freeze, that the library pip-install-test is not available in this workspace. 👎🏼

Fix the problem with a custom docker image

By default gitpod uses the gitpod/workspace-full docker image, so for this example I will use that image as the base, but you can use any image you like.

  • Manually stop the workspace and restart it
  • Edit .gitpod.yml add these lines to the top
Image:
  file: .gitpod.Dockerfile
  • Create the file .gitpod.Dockerfile
FROM gitpod/workspace-full 
ENV PYTHONUSERBASE=/workspace/.pip-modules
ENV PATH=$PYTHONUSERBASE/bin:$PATH
ENV PIP_USER=yes
  • Commit your changes and sync

Final Test

  • Manually stop the workspace and restart it
  • From the terminal:
gitpod /workspace/test-for-prebuild $ pip freeze | grep pip-install-test
pip-install-test==0.5

We can see from the pip freeze, that the library pip-install-test is indeed available in this new workspace. 👍🏼

tiamot avatar Dec 18 '21 04:12 tiamot

Thank you @tiamot @quental96 for sharing this. I'll make sure this is reflected in the docs as well. Appreciate the effort, let me know if you are having any more issues 🙏🏼 Can you close this issue?

pawlean avatar Jan 04 '22 10:01 pawlean