Thanks in advance for your kind support all the ti...
# general
q
Thanks in advance for your kind support all the time. I have encountered error when I add “pyaudio” python package into my project. According to “stackoverflow” (ref), it seems we need to add path for apple silicon environment.
.pydistutils.cfg
Copy code
[build_ext]
include_dirs=<YOUR PATH>/include/
library_dirs=<YOUR PATH>/lib/
I have confirmed it works fine if I have tried
$ pip install pyaudio
in my terminal with the above file. My question is how can we apply this in pantsbuild environment. Could you help me?
1
h
Hi there Keigo, welcome! Hm, I would need to check if pex consults the file `$HOME/.pydistutils.cfg`; my instinct is it would not. One idea maybe worth trying, based on the first SO suggestion, is to set something like this:
Copy code
[python-native-code]
cpp_flags.add = ["-I/opt/homebrew/Cellar/portaudio/19.7.0/include"]
ld_flags.add = ["-L/opt/homebrew/Cellar/portaudio/19.7.0/lib"]
But replace it with the relevant values on your machine
👀 1
If that doesn't work, another idea is to prebuild the wheel for M1s, since you got it working with pip. You can then use a local requirement to install that wheel. I'm actually finishing up a PR documenting how to do that 😄
e
I don't think this will have anything to do with Pex. Pex does invoke Pip with:
Copy code
--isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
But that's just about Pip's own configuration. It looks like
.pydistutils.cfg
is not a Pip thing, but a Python thing: https://docs.python.org/3/install/#distutils-configuration-files
👍 1
So if that file is at an expected path, Python should find it.
In Pants, things often aren't at expected paths because it copies files into /tmp sandboxes. So that may or may not come into play here.
And, although this config is Python, really distutils is superceded by setuptools; so setuptools is likely involved here more than anything else.
But this is all background info. What Eric said is the way to go, It's always better to have pre-built wheels for numerous reasons (in a project used by >=2 people - a personal project can work with just about anything of course).
So ... perhaps this is the fact Pants masks $HOME - I think.
@quiet-painter-18838 I do not recommend this as a a long term strategy, but you can try adding this to your Pants command line
--subprocess-environment-env-vars=HOME
If that works we can discuss more about this.
q
@hundreds-father-404 Thanks for your help. That worked completely. Now I am trying to add “CPPFLAGS” of environment variable because the above configuration is only for the apple silicon machine. I will get back to you after I tried.
💯 1
❤️ 1
@enough-analyst-54434 Thanks for the info. That will work as well I think. I will try that as well.
h
Now I am trying to add “CPPFLAGS” of environment variable because the above configuration is only for the apple silicon machine.
If you only want this to apply for some users, you may want to use a
.pants.rc
file: https://www.pantsbuild.org/docs/options#pantsrc-file
👀 1
q
@hundreds-father-404 Adding path into “CPPFLAGS” and “LDFLAGS” worked completely. We will use env vars because it will make our lives easier I think. and @enough-analyst-54434, thanks for the info again. I have no idea that option. Again, thanks all for your kind support!
❤️ 1
h
I'm glad to hear that! Building wheels like this is sometimes super tricky 😬 Let us know if we can help with other things 🙂
😍 1