I've upgraded to an M1 Macbook Pro and need to reinstall all of the goodies that I use regularly.
This includes Homebrew.
I have been to the official Homebrew site and done what they suggest:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
It then suggests to run
echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/username/.bash_profile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/username/.bash_profile
eval "$(/opt/homebrew/bin/brew shellenv)"
To keep it within the path for future use - I would think this was the thing that keeps it being reusable when you restart/get a new Terminal
And this works great. I can then use brew install xxx after installation to install whatever packages I require.
The issue comes when I get a new Terminal or restart etc. I go to perform another brew install and I get the annoying
-bash: brew: command not found
Is there something that I've not done after the initial install that means my Mac doesn't remember it's installed brew?
I was running into the same issue as you. My issue was my terminal was set to bash instead of zsh by default. I had to run chsh -s /bin/zsh and followed the top answer on another post, which is similar if not identical to the steps you include in your question. I restarted my terminal and ran through brew help worked!
I'm working on a script to put into my MDM for Mac deployments that will install some development plugins. It seems like the homebrew path changes depending on whether or not the machine is M1 or Intel based. I've started writing an if/then script to change the brew path depending on the above, but I'm running into issues. Any help is greatly appreciated.
#!/bin/bash
PROCESSOR=$(/usr/sbin/sysctl -n machdep.cpu.brand_string)
M1PATH=/opt/homebrew/bin/brew
INTELPATH=/usr/local/bin/brew
if [ "$PROCESSOR" == "Apple M1" ]
then
brew=$M1PATH
else
brew=$INTELPATH
fi
brew install cocoapods
brew install maven
brew eclipse-jee
brew elm
brew node
brew install python3
npm install -g react-native-cli
npm install --global gulp-cli
brew install vim
brew install watchman
brew install yarn
yarn global add jest
npm install -g appcenter-cli
brew install ios-deploy
I imagine the OP has since succeeded in their goal by now, but for those that need a solution, you just need to update the PATH variable with your 'detected` Homebrew path:
case `arch` in
arm64) # M1
export BREW_PREFIX=/opt/homebrew
;;
i386) # Intel
export BREW_PREFIX=/usr/local
;;
esac
export PATH="$BREW_PREFIX/bin:$PATH"
If like me you have scripts with the #! /usr/bin/env bash preamble, you may get extra mileage by adding a symbolic-link:
ln -snf $BREW_PREFIX/bin/{,brew_}bash
Then change your scripts to use #! /usr/bin/env brew_bash
Addendum 2022/12/29
The point of a new/temp environment variable is that we are at bootstrap i.e. when brew or any of its settings aren't yet known to the system.
In my personal setup, I have amassed a huge collection of convenience variables, functions, aliases and completions, so I have organised them into dedicated files, respectively; hence you don't see any eval/sourcing of brew hooks here and probably wouldn't even bother in a standalone-script.
In Terminal enter printenv command.
You will notice HOMEBREW_REPOSITORY variable set to /opt/homebrew for Apple Silicon chip (M1, M2...).
No need to set an extra variable as BREW_PREFIX.
HOMEBREW_REPOSITORY does not seem to be set on Intel chip Mac, a workaroud could be👇
case $(arch) in
arm64) # M1
eval "$(/opt/homebrew/bin/brew shellenv)"
;;
i386) # Intel
# Warning: Homebrew's "sbin" was not found in your PATH but you have installed
# formulae that put executables in /usr/local/sbin.
# Consider setting your PATH for example like so:
export PATH="/usr/local/sbin:$PATH"
export HOMEBREW_REPOSITORY="/usr/local"
;;
esac
Is there a way to specify the architecture/platform when creating a new conda environment? Alternatively, how does conda detect its current architecture/platform when its run?
What I'm aiming to do is this: I'm running on an Apple Silicon laptop. My pre-existing environments are running fine through Rosetta2, but I'd like to start experimenting with python running natively on Apple Silicon. miniforge provides a conda-forge repository with Apple Silicon builds, and I can tell conda to use the conda-forge channel when I create an environment. But I'm not seeing a way to specify that I'd like this to be an arm64 environment rather than an x86_64 environment, other than starting from miniforge's installer.
Thanks in advance.
CONDA_SUBDIR=osx-arm64 conda create -n native numpy -c conda-forge will get you a osx-arm64 native env.
To make it permanent, do,
conda activate native
conda config --env --set subdir osx-arm64
How to configure python conda Environments for both arm64 and x86_64 on M1 Apple Silicon
Adding to the answers, it is possible to configure conda to use both osx-arm64(arm64) and osx-64(x86_64) architectures.
I found adding conda config --env --set subdir osx-arm64 changes the option globally which created issues for me. Some of my projects relied on python dependencies that were only supported in either one or the other architecture not both: specifically tensorflow.
Install Xcode:
xcode-select --install
Install miniforge3
Install miniforge3 by downloading the shell script from here: https://github.com/conda-forge/miniforge. Ensure you select arm64 (Apple Silicon) architecture. You may need to enable execution of the shell script with:
chmod +x Miniforge3-MacOSX-arm64.sh
Then execute is with:
sh Miniforge3-MacOSX-arm64.sh
Add shortcuts to ~/.zshrc or ~/.bashrc:
Add the following code to ~/.zshrc.
The code will add two shortcut functions to create either an osx-64 or osx-arm64 conda environment.
# Create x86 conda environment
create_x86_conda_environment () {
# example usage: create_x86_conda_environment myenv_x86 python=3.9
CONDA_SUBDIR=osx-64 conda create -n $#
conda activate $1
}
# Create ARM conda environment
create_ARM_conda_environment () {
# example usage: create_ARM_conda_environment myenv_x86 python=3.9
CONDA_SUBDIR=osx-arm64 conda create -n $#
conda activate $1
}
Create conda environment
Now to create a python 3.9.13 osx-64(x86_64) environment with the name env_x86:
create_x86_conda_environment env_x86 python=3.9.13
Alternatively for osx-arm64 (arm64) environment:
create_ARM_conda_environment env_ARM python3.9.13
Pip install packages
Once activated you can install packages accordingly. In my case I needed an arm64 environment to install tensorflow-macos.
conda install -c apple tensorflow-deps
pip install tensorflow-macos tensorflow-metal
Prerequisites
Have Conda installed (anaconda / miniconda / miniforge3)
Have a terminal (Terminal or iTerm app) running with rosetta (for x64)
Add shortcut to create the environment
what does this do?
This function checks which architecture your current shell is using.
e.g. if you're running a terminal with rosetta, it will run with x86
Base on the architecture, it will add a prefix to your environment name
x86: x86_{name}
arm64: arm64_{name}
Creates the Environment & Activates it
function
add the following function to ~/.zshrc or ~/.bashrc:
create_conda_env () {
arch_name="$(uname -m)"
echo "Creating $arch_name environment"
if [ "${arch_name}" = "x86_64" ]; then
arch_type=osx-64
env_prefix="x86_"
elif [ "${arch_name}" = "arm64" ]; then
arch_type=osx-arm64
env_prefix="arm64_"
else
echo "Unknown architecture: $arch_name"
exit -1
fi
echo "New environment name: $env_prefix$1"
CONDA_SUBDIR=$arch_type conda create -n $env_prefix$#
conda activate $env_prefix$1
}
How to use?
create_conda_env {name} python={version} {aditional packages (optional)}
replace name, version and add any additional packages
I tried to update or install new packages from anaconda and lately, this message has appeared:
The environment is inconsistent, please check the package plan carefully
The following package are causing the inconsistency:
- defaults/win-32::anaconda==5.3.1=py37_0
done
I tried with conda clean --all and then conda update --all but it persists.
Conda Info
active environment : base
active env location : C:\Users\NAME\Continuum
shell level : 1
user config file : C:\Users\NAME\.condarc
populated config files : C:\Users\NAME\.condarc
conda version : 4.6.11
conda-build version : 3.17.7
python version : 3.7.3.final.0
base environment : C:\Users\NAME\Continuum (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/win-32
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/win-32
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/win-32
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/msys2/win-32
https://repo.anaconda.com/pkgs/msys2/noarch
package cache : C:\Users\NAME\Continuum\pkgs
C:\Users\NAME\.conda\pkgs
C:\Users\NAME\AppData\Local\conda\conda\pkgs
envs directories : C:\Users\NAME\Continuum\envs
C:\Users\NAME\.conda\envs
C:\Users\NAME\AppData\Local\conda\conda\envs
platform : win-32
user-agent : conda/4.6.11 requests/2.21.0 CPython/3.7.3 Windows/10 Windows/10.0.17763
administrator : False
netrc file : None
offline mode : False
I had faced the same problem. Simply running
conda install anaconda
solved the problem for me.
saw this on Google Groups
This message was added in conda 4.6.9, previously there was no indication when conda detected an inconsistent environment unless conda was run in debug mode. It is likely that your environment was inconsistent for some time but the upgrade to conda made it visible. The best option it to run "conda install package_name" for the inconsistent packages to let conda try to restore consistency.
and it really works for me.
Maybe you should try conda install anaconda in your situation.
The inconsistencies are caused due to different versions of the packages, and their clashing dependencies.
conda update --all
This command updates all the packages, and then conda solves the inconsistency on its own.
Had this same problem and none of the other solutions worked for me. Ended up having to uninstall and reinstall conda, then reinstall all of my libraries.
Ultimate solutions:
conda activate base
conda install anaconda
conda update --all
Works on Windows 10 and Ubuntu 18.04 (credits to #MF.OX for ubuntu).
Removed following problems for me:
The environment is inconsistent
WARNING conda.base.context:use_only_tar_bz2(632)
If the other solutions don't work, reverting the environment can fix this.
Use conda list --revisions, pick a revision number, and use conda install --revision [#] going back step-by-step until everything works again.
Given a situation like the following,
> conda update -c intel --all
Collecting package metadata: done
Solving environment: |
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:
- intel/win-64::ipython==6.3.1=py36_3
- intel/win-64::prompt_toolkit==1.0.15=py36_2
done
As mentioned in other answers, the idea is to have some sort of re-installation to occur for the inconsistent packages.
Thus, with a few copy-&-paste's, you could:
> conda install intel/win-64::ipython==6.3.1=py36_3
Collecting package metadata: done
Solving environment: /
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:
- intel/win-64::ipython==6.3.1=py36_3
- intel/win-64::prompt_toolkit==1.0.15=py36_2
done
## Package Plan ##
environment location: c:\conda
added / updated specs:
- ipython
The following NEW packages will be INSTALLED:
jedi intel/win-64::jedi-0.12.0-py36_2
parso intel/win-64::parso-0.2.0-py36_2
pygments intel/win-64::pygments-2.2.0-py36_5
wcwidth intel/win-64::wcwidth-0.1.7-py36_6
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(and you would have to repeat for all the packages)
My “Shortcut”
Alternatively, cook up an (ugly) one-liner (this should work for Windows as well as other platforms)
Note: by "ORIGINAL_COMMAND", I'm referring to any command that gives you the error message (without any other side-effects, ideally)
<ORIGINAL_COMMAND> 2>&1 | python -c "import sys,re,conda.cli; conda.cli.main('conda','install','-y',*re.findall(r'^\s*-\s*(\S+)$',sys.stdin.read(),re.MULTILINE))"
Expanding the above one-liner:
from re import findall, MULTILINE
from sys import stdin
from conda.cli import main
main(
"conda", "install", "-y",
"--force", # Maybe add a '--force'/'--force-reinstall' (I didn't add it for the one-liner above)
*findall(r"^\s*-\s*(\S+)$", stdin.read(), MULTILINE) # Here are the offenders
)
I was getting an environment is inconsistent error when I tried to update my base conda environment. I'm using miniconda. Unfortunately, none of the answers above worked for me.
What did work for me was:
conda activate base
conda install conda --force-reinstall
conda install conda --force-reinstall
conda update --all
(Yes, for some reason it was necessary to run conda install conda --force-reinstall twice!)
The command conda install -c anaconda anaconda did the trick for me. For my setup, I need to specify the channel otherwise it would not work. After running the command in the terminal, I was prompted to update a list of packages that was found to be inconsistent. Without this step, I was not able to install or update any packages with conda install <package_name> or conda update <package_name respectively.
What worked for me was to
`conda remove <offending_packagename>`,
`conda update --all`
and then finally
`conda install <offending_packagename>`.
I had this problem for ages. The conda install anaconda might work, but it takes just way too long -- more than 24 hours on my machine.
Here is a solution that worked for me in under 5 minutes:
Remove all the unneeded packages -- being careful to leave the ones that are essential for conda to operate.
Then, use conda install anaconda.
But how?? there is a lot of them!
This is what I have done:
Make a fresh envinroment with python, fairly bare-bone. then, list the packages in there:
conda create -n fresh python
conda activate fresh
conda list
Save the output, you will need it.
1b. go back to the base envinroment:
conda deactivate
use the following snippet to generate a conda command that will remove all the inconsistent packages:
(good packages are)
exclusion_text = '''
_libgcc_mutex 0.1 main
_openmp_mutex 4.5 1_gnu
anyio 2.2.0 py39h06a4308_1
argon2-cffi 20.1.0 py39h27cfd23_1
async_generator 1.10 pyhd3eb1b0_0
...
... and more! get this from a good environment.
Note the usage of triple quotes (''') to use a multiline-string in python.
bad_packages_text = '''
- https://repo.continuum.io/pkgs/main/linux-64/networkx-2.1-py36_0.tar.bz2/linux-64::networkx==2.1=py36_0
- https://repo.continuum.io/pkgs/main/linux-64/spyder-3.2.6-> py36_0.tar.bz2/linux-64::spyder==3.2.6=py36_0
py36h4c697fb_0.tar.bz2/linux-64::jdcal==1.3=py36h4c697fb_0
- defaults/noarch::jupyterlab_server==1.1.4=py_0
- defaults/linux-64::argh==0.26.2=py37_0
...
... and more! get this by copy-pasting the "The following packages are causing the inconsistency." message.
then, in python, process this:
exclusions = [line.split(' ')[0] for line in exclusion_text_lines if line !='']
bad_packages_lines = bad_packages_text.split('\n')
bad_packages = [line.split('::')[1].split('==')[0] for line in bad_packages_lines if line!='']
exclusions.append('conda') # make sure!
exclusions.append('tqdm')
finally, construct the life-saving command:
command_line = 'conda remove '
for bad_package in bad_packages:
if bad_package not in exclusions:
command_line = f'{command_line} {bad_package}'
command_line
Since in solving the environment, all the packages on the remove list can be ignored, conda no longer needs to consider their versions, and the process is fast.
Possibly someone can refactor this method to make it easier -- or better yet, upgrade conda to enable quick reset base command.
This worked for me -- it took me longer to write this post than to execute these actions.
Good luck!
To those of us who have miniconda and can't/don't want to install anaconda: the accepted answer works when adapted.
conda install conda
conda update --all
Would have commented, but my rep is too low.
conda install anaconda
conda clean --all
conda update --all
fix the problem for me
To solve this message I had to run conda update --all in my base environment three times after each other.
Every time the number of inconsistent packages decreased until conda said:
# All requested packages already installed.
I'm on macOS Big Sur 11.6 using conda version 4.10.3.
In my case, none of the above worked. But this did the trick in less than a minute:
1- I downloaded again the lastest installer (miniconda in my case)
2- Run the installer with the -u option:
bash Miniconda3-py39_xxxx-Linux-x86_64.sh -u
3- Answer yes to all questions and let the installer finish
4- Then I could run conda update conda -all
Hope this helps...
You probably installed anaconda with python 2.7 but later you used python 3.x. Thus, you are getting an error message. In my case, I solved the problem by activating anaconda with python 2.7:
conda create --name py2 python=2.7
Try to have a look to the environment management
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
By using something along the lines
conda create --name astra python=3.5
conda activate astra
conda install -c astra-toolbox astra-toolbox
You can see that you can even specify target python version. Now play with the new packages installed. When unsatisfied, you can always do
conda deactivate
conda env remove -n astra
If you install everything to the base env and something gets broken, then probably better is not to install conda at all and go with default python managing it through pip.
In my environment.
1.
conda install anaconda
conda update --all
Then it works correctly.
I am trying to write a shell script that will install all of our development tools & dependencies onto a clean OSX machine.
Does anybody know the best approach to automate the installation of Xcode?
I am doing this to:
Document the development environment.
Speed up the on-boarding process for new developers.
Follow the automate-everything principle.
Fully Automated XCode Installation
First, login to the Apple Developer Downloads Site and get the version of XCode.dmg that works for your version of OSX. You might want to grab a couple versions to support the different OSX platforms (e.g.: 10.10 Yosemite, 10.9 Mavericks, etc...). Upload the dmg to a file host you can access (e.g.: Amazon S3, Dropbox, your shared hosting provider of choice, etc...)
Change the DOWNLOAD_BASE_URL in the following script, and rename the dmgs appropriately with the version & build number or add it to the script below:
#!/bin/bash
DOWNLOAD_BASE_URL=http://example.com/path/to/xcode/dmgs/
## Figure out OSX version (source: https://www.opscode.com/chef/install.sh)
function detect_platform_version() {
# Matching the tab-space with sed is error-prone
platform_version=$(sw_vers | awk '/^ProductVersion:/ { print $2 }')
major_version=$(echo $platform_version | cut -d. -f1,2)
# x86_64 Apple hardware often runs 32-bit kernels (see OHAI-63)
x86_64=$(sysctl -n hw.optional.x86_64)
if [ $x86_64 -eq 1 ]; then
machine="x86_64"
fi
}
detect_platform_version
# Determine which XCode version to use based on platform version
case $platform_version in
"10.10") XCODE_DMG='XCode-6.1.1-6A2008a.dmg' ;;
"10.9") XCODE_DMG='XCode-5.0.2-5A3005.dmg' ;;
*) XCODE_DMG='XCode-5.0.1-5A2053.dmg' ;;
esac
# Bootstrap XCode from dmg
if [ ! -d "/Applications/Xcode.app" ]; then
echo "INFO: XCode.app not found. Installing XCode..."
if [ ! -e "$XCODE_DMG" ]; then
curl -L -O "${DOWNLOAD_BASE_URL}/${XCODE_DMG}"
fi
hdiutil attach "$XCODE_DMG"
export __CFPREFERENCES_AVOID_DAEMON=1
sudo installer -pkg '/Volumes/XCode/XCode.pkg' -target /
hdiutil detach '/Volumes/XCode'
fi
You might be interested in installing the XCode Command Line Tools, and bypassing the XCode License Agreement also:
curl -Ls https://gist.github.com/trinitronx/6217746/raw/58456d6675e437cebbf771c60b6005b4491a0980/xcode-cli-tools.sh | sudo bash
# We need to accept the xcodebuild license agreement before building anything works
# Silly Apple...
if [ -x "$(which expect)" ]; then
echo "INFO: GNU expect found! By using this script, you automatically accept the XCode License agreement found here: http://www.apple.com/legal/sla/docs/xcode.pdf"
expect ./bootstrap-scripts/accept-xcodebuild-license.exp
else
echo -e "\x1b[31;1mERROR:\x1b[0m Could not find expect utility (is '$(which expect)' executable?)"
echo -e "\x1b[31;1mWarning:\x1b[0m You have not agreed to the Xcode license.\nBuilds will fail! Agree to the license by opening Xcode.app or running:\n
xcodebuild -license\n\nOR for system-wide acceptance\n
sudo xcodebuild -license"
exit 1
fi
Alternative Method
An alternative is to use this applescript I created.
To use:
git clone https://gist.github.com/6237049.git
cd 6237049/
# Edit the script with AppleScript Editor to replace your APPLE ID and PASSWORD
osascript Install_XCode.applescript
You might also be interested in my answer here: How download and Install Command Line Tools for Xcode.
I would recommend the other method over the applescript method. The applescript depends on a UI element hierarchy that may not always stay the same for future versions of the App Store app on OSX. It just seems fragile to me. Installing XCode via the command line via a dmg is probably the most reliable way.
Well, just for who reach this page, there is a gem build by one of author of Fastlane to automatic this process.
https://github.com/KrauseFx/xcode-install
Starting with Xcode 4.3, it's delivered as an app bundle. The first time you launch the app, it will continue the installation. Since it's a beta, it's still not fixed, but currently the post-launch installation packages are in the app bundle inside a directory called Contents/Resources/Packages.
So, depending on your environment, your install script can just copy the Xcode.app bundle into the Applications directory and your users can complete the installation the first time they launch it. Or, you can copy the bundle and then manually install the additional packages using the installer(8) utility. For more information on using installer, see the man pages.
A lot of things of things out there for automating both downloading and installing are outdated. I've been at work on something for another project and think I have a pretty good solution working:
https://github.com/rockholla/macosa/blob/master/bin/macosa_xcode
And here's the download part:
https://github.com/rockholla/macosa/blob/master/bin/macosa_xcode_download
# Install Command-line tools as dependency for Homebrew
xcode-select --install # Sets the development directory path to /Library/Developer/CommandLineTools
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Mas (command-line interface for Mac App Store)
brew install mas
# Search for Xcode showing only the first 5 results
mas search xcode | head -5
# Install Xcode using App ID
mas install 497799835 # The appid for Xcode shown when doing search
sudo xcode-select -r # Reset the development directory path to put to Xcode /Applications/Xcode.app/Contents/Developer
#sudo xcodebuild -license
# Updaate all Apple software and auto agree to any licenses and restart if necessary
sudo softwareupdate --install --agree-to-license -aR