Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't import third-party library (numpy) #1209

Closed
1 of 2 tasks
MrModest opened this issue Sep 15, 2024 · 2 comments
Closed
1 of 2 tasks

Can't import third-party library (numpy) #1209

MrModest opened this issue Sep 15, 2024 · 2 comments

Comments

@MrModest
Copy link

MrModest commented Sep 15, 2024

Describe the current behavior

I know that Grist natively doesn't support adding additional libraries, so I tried a workaround from this link: https://community.getgrist.com/t/install-third-party-libraries/1087

But when I just add a line import numpy I get the error:

Traceback (most recent call last):
  File "/grist/sandbox/grist/engine.py", line 985, in _recompute_one_cell
    result = col.method(record, table.user_table)
  File "usercode", line 353, in Spent
    import numpy
ImportError: No module named numpy

Even though I didn't turn on sandboxing. (I tried with gvisor and without it - the same error).

Also, I tried to modify the /sandbox/grist/gencode.py#L173 file as described below by the same link, but then tables stopped loading in the browser and in the docker logs a saw this error [Sandbox] KeyError u'Projects' (the name of the table where I tried to use the formula is 'Projects'; this part changes according to the table name where I use the import in formulas).

Steps to reproduce

Dockerfile:

FROM gristlabs/grist:1.1.18

RUN \
  apt update && apt install -y openssl && \
  python3 -m pip install numpy

compose.yml

services:
  grist:
    build: .
    container_name: grist
    cap_add:
      - SYS_PTRACE
    environment:
      GRIST_SINGLE_ORG: default-team
    ports:
      - 8484:8484
    volumes:
      # Where to store persistent data, such as documents.
      - ./volumes/grist:/persist
    restart: unless-stopped

Describe the expected behavior

Import will work correctly. I can use import numpy in formulas.

Where have you encountered this bug?

Instance information (when self-hosting only)

  • Grist instance:
    • Version: 1.1.18
    • Installation mode: docker
    • Architecture: ???
@MrModest
Copy link
Author

MrModest commented Sep 15, 2024

New behaviour discovered. I can reproduce it only with the imported document (from the Desktop version if it matters).
When I create a new document and write

import numpy
return None

it doesn't show errors o_0

Oh, and it works with the new table in the same document as well.
But not with a new column in the existing table, for example 🤯

@MrModest
Copy link
Author

Nevermind 😅. I found a document setting where I can choose the python version. Once it chose 3rd, the error is gone

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant