Fixing PATH for Python libraries using Bash
Solution 1
The error message is telling you to add Python 3 to your path.
To do that, use a text editor to open /Users/<you>/.profile
, and as the very last line add:
export PATH=/Users/<you>/Library/Python/3.8/bin:$PATH
Then you'll need to launch a new Terminal window for those settings to take effect. (you could make it take effect in your current shell by entering the line directly into your shell)
[Edit: now that macOS 12.3 has removed all versions of Python, Homebrew is the easiest way to install Python. Fortunately things are simpler because there's only one version of Python on your system and you won't need to override the system's version (because there isn't one any longer).]
Solution 2
Update: As of python 3.8, the following path should be used:
export PATH=/Library/Frameworks/Python.framework/Versions/3.8/bin:$PATH
If you're using bash, you can store this in your /.bashrc
If you're using zsh, you can store this in your /.zshrc
Solution 3
You have to update the seeking path location, to needed bin
folder, in your .zshrc
, .bashrc
etc.
Example
For /Library/Python/3.8/bin
,
you can prepend the variable $HOME
, and use with the needed path:
export PATH="$HOME/Library/Python/3.8/bin:$PATH"
Epilogue
In current Terminal
tab, you have to reload your shell, with the config, by . ~/.zshrc
, or .bashrc
etc
The Pointer
Updated on January 28, 2022Comments
-
The Pointer over 2 years
I am attempting to install some Python libraries by executing variations of the following command in Bash:
pip install --user -U numpy
I installed Python3 using Homebrew.
I then get variations of the following message each time:
WARNING: The scripts f2py, f2py3 and f2py3.7 are installed in '/Users/x/Library/Python/3.7/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
How can I fix this issue to avoid problems in the future?
-
The Pointer over 4 yearsThanks for the answer. There is
.bash_history
,.bash_profile
, and.bash_sessions
, but no.bashrc
? -
The Pointer over 4 yearsOk, I created a new
.bashrc
file by using the commandecho >> ~/.bashrc
, as specified by the Hastur's answer superuser.com/questions/584540/… -
Dylan McNamee over 4 yearsYou could have used
echo export PATH=/Users/you/Library/Python/3.7/bin:$PATH >> ~/.bashrc
to add it to your path. Using an editor lets you see the other stuff in your.bashrc
which is your case was nothing. Happy to help. -
wick about 3 yearsAnd what is the point when Mac's python is v2? Nothing in that new path would work, right?
-
Dylan McNamee about 3 years@wick - macOS Python has long been able to have 2.7 and 3.x coexist. Apple (and everyone else) will eventually no longer support v2, but in the meantime, many users will need to have both versions available. I'm 95% migrated to Python 3.x. This is off-this-topic, so I won't elaborate.
-
wick about 3 years@DylanMcNamee yes, somehow it works for me, even though
python --version
is still v2. I suppose it is mercy of each software package to determine how/which python it is calling.. -
harshikerfuffle over 2 yearsI am getting this message when I run the .bashrc command: no such file or directory: /Users/<myname>/.bashrc
-
harshikerfuffle over 2 yearscould you describe the sequence of steps to follow here? I'm a bit lost