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

Add support for passing environment variables when installing pip packages #1183

Open
IsakTheHacker opened this issue Jun 15, 2024 · 3 comments

Comments

@IsakTheHacker
Copy link
Contributor

Many pip packages support passing environment variables at install time. For example, to use the slower multidict Python implementation:

MULTIDICT_NO_EXTENSIONS=1 pip install multidict

I haven't tested this yet, I'm sorry. Maybe Chaquopy's pip already reads from the local environment variables? Regardless, I think it would be easier to have this be an explicit option in the gradle plugin. That would also lead to more reproducible builds across machines

@mhsmith
Copy link
Member

mhsmith commented Jun 20, 2024

If all you want is a newer version of multidict, you may be able to do that by moving to a newer version of Python. See the repository for the available version combinations – the newest versions are currently multidict 5.1.0 for Python 3.8-3.11, and multidict 6.0.4 for Python 3.12.

Most packages that support pure-Python fallbacks will either use them automatically if the native compilation fails, or have a pure-Python wheel on PyPI. I see multidict 6.0.4 doesn't do either of those things, so the environment variable would be necessary to install it on Python 3.11 or older.

However, the current multidict version 6.0.5 does have a pure-Python wheel on PyPI, so that should solve your immediate problem if you need a newer version of multidict on an older version of Python.

Maybe Chaquopy's pip already reads from the local environment variables?

Yes, it does, so you can pass the environment variable through Gradle on the command line, like this:

MULTIDICT_NO_EXTENSIONS=1 ./gradlew assembleDebug

After you've done this once, the wheel will be cached locally so you won't need to set the variable again.

But I agree it would be better to put it in a Gradle file so it's more reproducible, and I haven't managed to find an easy way of doing that:

  • Java has no setenv equivalent in its standard library.
  • Chaquopy runs pip using project.exec rather than an Exec task, so the subprocess environment can't be configured that way.
  • Setting a variable in gradlew apparently has no effect within Android Studio.

So I'll leave this issue open and see if anyone else has a similar problem.

@Sven65
Copy link

Sven65 commented Jan 20, 2025

Have you found any solution to this yet?

@mhsmith
Copy link
Member

mhsmith commented Jan 20, 2025

Only the workaround in the previous comment.

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

No branches or pull requests

3 participants