Search code examples
pythonanacondamigrationcondaapple-m1

Conda environments not working migrating from an x86 Mac to a M1 Mac


I am migrating my conda environments to a new computer, from x86 based to a M1 based silicon.

  1. I installed a fresh Anaconda with native support for M1. Default environment does execute python command correctly and starts the Python shell.

  2. I copy the envs directory and ´conda activate virtenv´ works fine but Python is not working, no Python shell and no answer if I execute python --version. The packages in those environments are the ones for x86, of course.

I like to know:

  1. Should they work with Rosetta anyway and be transparent despite the loss of performance?
  2. How can I move those environments to the new computer and Anaconda installation and make them work with the present versions and levels for each one?

I tried to move the environments as they are and see if it worked. Some searches have been done and I don’t see what is the most efficient way to migrate the environments.

I also checked by executing python and. python3 directly from the path of the environment but nothing happens. Checked that the +x permission is granted.

Thanks!


Solution

  • One cannot simply copy environments. You need to rewrite a bunch of hardwired paths using the cpr tool for them to work. This answer expands on that, but I don't recommend that approach.

    Rather, it would be better to export the environments, either as YAMLs or as conda-lock lockfiles. Then recreate them. When doing this, since OP has installed an osx-arm64 version of Conda, that means Conda will not search the correct channels when solving to recreate osx-64 environments. You'll need to override the subdir configuration variable to create the environments, something like:

    CONDA_SUBDIR=osx-64 conda create -n my-env -f my-env.yaml 
    

    Keep in mind that this override needs to be used whenever mutating these environments in the future.

    Additionally, the assumption that everything will just work with Rosetta is false. In particular, any packages that used Intel-specific optimizations, like mkl will not work. Rosetta emulates x86_64, but not Intel.


    Additional Thoughts

    Many users find it more sustainable to use only a minimal Conda base environment, i.e., avoid the Anaconda installer. Also, many users find Mamba to provide an improved frontend user experience for managing Conda environments. For this reason, those starting fresh should consider Mambaforge as their base install.

    If one ever actually needs the full multiple-hundred package Anaconda install, one can always create that as a separate environment:

    mamba create -n anaconda-py310 -c anaconda anaconda python=3.10