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

Specify custom python binary path for "func start" terminal command? #2844

Closed
aescolastico opened this issue Nov 27, 2021 · 5 comments
Closed

Comments

@aescolastico
Copy link

Currently I have to set an alias for "python" if I want core tools to use a specific version. Is there a parameter I can feed the command or some value in the settings file I can use to achieve this? The reason being that I need to use a different version of python for az func development then I do for every day use. Modifying my alias' is quite inconvenient.

Thanks in advance and apologies if this has been asked before. Ive been searching for hours.

@aescolastico
Copy link
Author

aescolastico commented Nov 30, 2021

I tried setting the env variable based on comments in this file ("languageWorkers:python:defaultExecutablePath"):

string pythonDefaultExecutablePath = Environment.GetEnvironmentVariable(_pythonDefaultExecutableVar);

  // If users are overriding this value, we will use the path it's pointing to.
  // This also allows for an escape path for complicated envrionments.
  string pythonDefaultExecutablePath = Environment.GetEnvironmentVariable(_pythonDefaultExecutableVar);
  if (!string.IsNullOrEmpty(pythonDefaultExecutablePath))
  {
      return await GetVersion(pythonDefaultExecutablePath);
  }

But the cli did not use the binary I specified in that ENV variable

@michaelpeng36
Copy link
Contributor

@aescolastico, what version of Python are you trying to use? Typically, we encourage users to use a virtual environment.

@aescolastico
Copy link
Author

aescolastico commented Nov 30, 2021

I have a rosetta x86_64 emulated install of python3 located in '/usr/local/bin/python3'
and an arm version installed in '/opt/homebrew/opt/python@3.9/libexec/bin/python'

Im running 3.9 for both. I need to use the emulated version in order to run func tools on my M1 mac. Arm python is not currently supported by this application.

When func tools "finds" the python located at '/usr/local/bin/python3' (x86 emulated) it works without issue. But to do this I need to either uninstall the arm python, or remove all references of "python" or "python3" that point to that arm version.

How would I use a virtual environment? I use func tools in the terminal and not with vscode if that helps.

@anthonychu
Copy link
Member

@aescolastico I don't have an M1 Mac yet to test this but give this a try:

# create the virtual environment
/usr/local/bin/python3 -m venv .venv

# activate it
source .venv/bin/activate

# this should point to the python binary in your virtual environment
which python

# install dependencies in the virtual env
python -m pip install -r requirements.txt

Now when you use func, it should use the right binary.

M1 support is tracked here #2834

@aescolastico
Copy link
Author

So this:

# install dependencies in the virtual env
python -m pip install -r requirements.txt

actually still pointed to my opt python "site-packages" directory (likely due to some hardcoded alias' in my bash_profile). I think that's what I was running into when I tried to use venvs the other day. Your use of which gave me that hint.

when I manually specified the path to the binary in my venv, it worked.

.venv/bin/python -m pip install -r requirements.txt

image

Thanks for your help @anthonychu

For anyone else on M1 hardware. I had to do this in the Rosetta copy of my terminal editor and also had to install an intel emulated version of home-brew to get az func working.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants