Incorrect Conda path after linux system migration

Viewed 46

Our server was updated to use the NFS system, and the previous /scratch path is now mapped to /local/scratch. My anaconda3 was installed under /scratch/xxx/anaconda3, which basically means it is now under /local/scratch/xxx/anaconda3. Intuitively, I have updated the PATH variable in .bash_profile, and running which conda actually gives me

/local/scratch/xxx/anaconda3/bin/conda

However, when I actually tried to run $conda, the system reports the error below:

-bash: /scratch/xxx/anaconda3/bin/conda: No such file or directory

which is quite weird and indicates an inconsistency with the result returned by which conda. In addition, I tried to directly cd into /local/scratch/xxx/anaconda3/bin/ and execute $./conda. It reports

-bash: ./conda: /scratch/xxx/anaconda3/bin/python: bad interpreter: No such file or directory

My wild guess is that in addition to the environment variable in .bash_profile, there are some internal settings of anaconda stored elsewhere, because the system actually knows the right path for python, while conda tries to execute python from the old path (i.e., /scratch/xxx/anaconda3/bin/python in the above error message). However, I couldn't seemingly find this file and change it to get things work.

Somehow, I feel this should be a common issue, however, I did not find any solutions from the internet. Any suggestions would be greatly appreciated.

1 Answers

I have fixed my issue using cpr (credits to @merv). Here I post the detailed instructions, so if some one has the same problem, he/she can almost just follow them to get things fixed.

1. Installation

According to anaconda.org, the recommended command to install cpr is

$ conda install -c anaconda conda-prefix-replacement

You may find this to be actually very awkward; the reason we need cpr is that our conda is broken due to the prefix issue, if we can run conda command to install cpr, then why should we need cpr?

Instead, we may install cpr directly from github:

$ git clone https://github.com/conda/conda-prefix-replacement.git
$ cd conda-prefix-replacement
$ python setup.py install

2. Rehome

After installation, running the rehome command to fix the prefix issue is quite straightforward. Say your anaconda is moving from path_A to path_B, simply do

$ cpr rehome path_B --old-prefix path_A

In my case, the command should be

$ cpr rehome /local/scratch/xxx/anaconda3 --old-prefix /scratch/xxx/anaconda3

After running the cpr command, exit the terminal and re-login. Everything should be good now!

Related