1

When I activate a conda environment from a command terminal in Windows, the system path changes. That is, if I open a new terminal and do:

echo %PATH%
conda activate env_name
echo %PATH%

I get two different results. Specifically, my path outside of conda is more "up to date", including locations for external programs that I installed after installing Anaconda. For instance, I installed ImageMagick and this is included in the Windows path outside conda, but not inside my conda environment.

In other words, it looks like conda is behaving as you'd expect, preserving a certain environment, including the path environment variable of the Windows shell. That's all fine, but now I'd like to (permanently) change this variable inside of my conda environment (in particular, I want my path to include the location of ImageMagick). So far haven't found a great solution for this. The method described here does work, but seems clumsy as it's using a script to modify the path variable automatically when the conda environment is activated. Clearly this variable is stored somewhere, so I'd like to just to modify it permanently. Any ideas?

  • The question seems to imply that you installed ImageMagick externally (or without using conda) - which is something I'm interested in. Just curious, why didn't you to install ImageMagick from conda directly into your environment so this problem wouldn't occur? https://anaconda.org/conda-forge/imagemagick – Prashant Bharadwaj Sep 30 '21 at 05:46
  • Huh - I didn't realize that was possible. Thanks! – Ruben van Bergen Oct 04 '21 at 11:42
  • Actually, as an update to this, I had to install ImageMagick again on a new Windows system, so I thought I'd try the conda route, but it doesn't look like the package is available under Windows. – Ruben van Bergen Dec 13 '21 at 11:20
  • Ah, sorry. I didn't realize that it was not compatible with Windows. Have you tried creating a symlink of the imagemagik file to the big folder within environment of interest? – Prashant Bharadwaj Dec 14 '21 at 21:32

2 Answers2

2

One solution for your issue is to create a symbolic link (~ a shortcut) of the Imagemagik file in the bin/ folder in the path of the conda environment

To know the path, you would do conda info --envs and you will get the environments and the corresponding paths (this path is also the first one you see in the echo $PATH call when the environment is activated)

In windows, you can open the cmd prompt as administrator and type mklink conda/path/of/environment/bin/ original/location/of/Imagemagik

After that I believe you should be able to call Imagemagik from the commandline as if it was in your path.

In Ubuntu you can use ln to make the symbolic link

0

I just wanted to add one more solution that I found (thanks to this answer) and ended up (sometimes) using myself, which is to include in the relevant code the following:

import os
os.environ["PATH"] += os.pathsep + magick_path

The advantage of this solution is that you can put it in any script or function that needs to access, in my case, ImageMagick, or more generally some executable that isn't currently found in the path. So it depends on what you want. Prashant's nice solution is more permanent as it effectively adds the executable to the entire conda environment. The solution above is more flexible as you can add it as needed, but you have to redo that every time you need it.