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

Numpy error when using bundled libs from different python version #209

Open
inimaz opened this issue Jun 30, 2024 · 4 comments
Open

Numpy error when using bundled libs from different python version #209

inimaz opened this issue Jun 30, 2024 · 4 comments

Comments

@inimaz
Copy link

inimaz commented Jun 30, 2024

Hello team,

thanks for this template!
I am building an extension using this template, see the repo.
And it works, but only if the python version is the same as the python version used when it was built.

If it is not the case, when the user's python (python 3.12) has not the same version as the one that built it (python 3.11). I get the following error from numpy:

 File "/home/inigo/.vscode-server/extensions/codecarbon.codecarbon-0.1.0/bundled/libs/codecarbon/core/cpu.py", line 13, in <module>
    import pandas as pd
  File "/home/inigo/.vscode-server/extensions/codecarbon.codecarbon-0.1.0/bundled/libs/pandas/__init__.py", line 19, in <module>
    raise ImportError(
ImportError: Unable to import required dependencies:
numpy: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python interpreter from there.

What do you think I should do? Build an extension per python version and then detect which one to load?

Thanks!

@inimaz
Copy link
Author

inimaz commented Jun 30, 2024

Exact line in my repo that triggers this error https://github.com/inimaz/vscode-extension-codecarbon/blob/main/bundled/tool/lsp_server.py#L210 . This line imports codecarbon, codecarbon imports pandas and pandas imports numpy ==> the error appears

@karthiknadig
Copy link
Member

@inimaz You will need to use platform specific builds. The template was designed with universal builds in mind. But, for scenarios like this where you need platform specific binaries like with numpy, you will need to change the build steps to install numpy with the binaries. You will also need to change packaging the vsix to use platform target (see vsce command line for more details)

Here is an 3rd party extension that builds and ships native binaries based on this template.
https://github.com/astral-sh/ruff-vscode

@inimaz
Copy link
Author

inimaz commented Jul 3, 2024

Thanks for the response and the link! @karthiknadig

I agree I will need to do this platform specific builds. Thanks for the tip!
It does not solve this problem though, in my case it is the same platform (Windows laptop) just changing the python version. Do I need to do a full matrix of builds per platform per python version?

For example if I support windows and mac, and python 3.7 and python 3.8... Do I need to do:

  • windows-py3.7
  • windows-py3.8
  • mac-py3.7
  • mac-py3.8

@karthiknadig
Copy link
Member

You will have to pull the native builds for each python ABI (i.e, py37, py38, py39, etc) at build time if you want to package it.

We do this for debugpy, in the python debugger extension. We pull each of the compiled variants for the debugger.

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

2 participants