0

I have installed Python on my Apple Silicon (ARM64) machine, but it installs it as python3 and not python.

The problem is that I have a node.js project with dependencies which need python (and pip). They fail to build because they are unable to find python.

python3 is on the path at /opt/homebrew/python3 which in turn is a link to

/opt/homebrew/Cellar/python@3.10/3.10.8/bin/python3

I think I need to create a symbolic link python to /opt/homebrew/python3, but am unsure which path the use /opt/homebrew/python or /Applications/python or something else.

Or would it just be cleaner to create a virtualenv ?

chughts
  • 4,210
  • 2
  • 14
  • 27
  • Creating a virtual environment and running your `node.js` project from there is probably the simplest solution, as no matter what Python you use to create the virtual environment, it will be installed as `python` in the virtual environment's `bin` directory. – chepner Jan 11 '23 at 15:05
  • Some OS distributions do let you choose whether `python` will refer to a Python 2 or Python 3 installation, and someday Python 3 should become the default, but the recommendation to use virtual environments may delay that or make the point moot. – chepner Jan 11 '23 at 15:06
  • Have you considered creating aliases? – DarkKnight Jan 11 '23 at 15:07
  • (Keep in mind that even if `python` *does* refer to a Python 3 version, it may not be the correct *minor* version that your project requires. Maybe it needs Python 3.11 and you haven't upgraded from Python 3.9 yet.) – chepner Jan 11 '23 at 15:07
  • 1
    @Fred Aliases are expanded by the shell; a reference to Python in a `node` script won't care about any shell aliases that have been defined. – chepner Jan 11 '23 at 15:08

1 Answers1

0

https://github.com/pyenv/pyenv might be able to solve your issue. Depending on the directory you are in, it will intelligently set your python version.

Here's a diagram that explains how python environments work

kwehmeyer
  • 63
  • 8
  • I've gone for virtualenv, but the principle is the same. – chughts Jan 12 '23 at 08:47
  • Not quite, but if it solves your immediate issue then great! `virtualenv` will isolate your python libraries. `pyenv` isolates your python versions. Here's a good write up: https://stackoverflow.com/questions/41573587/what-is-the-difference-between-venv-pyvenv-pyenv-virtualenv-virtualenvwrappe. I use a combination of pyenv and https://python-poetry.org. – kwehmeyer Jan 12 '23 at 14:47