Wednesday 21 October 2020

What's the meaning of "a trimmed down value for PATH env var" in the Anaconda release notes?

I uninstalled "Anaconda3 5.2.0" and reinstalled "Anaconda3 2020.07" on my Windows computer two days ago. As recommended by the installer, when I installed Anaconda3 5.2.0 last year or reinstalled Anaconda3 2020.07 two day ago, I didn't add Anaconda path to the system path environment variable. Things go well when I use python from Anaconda Prompt because the Prompt has added Anaconda directories to the path variable.

However, I find a strange different behavior between Anaconda3 5.2.0 and Anaconda3 2020.07 when used outside the Anaconda Prompt. I have a bat file containing a single line C:\Anaconda3\python xxx.py, and in xxx.py I import several python packages including numpy. When I used Anaconda 5.2.0, this bat file can be executed successfully by double-click (It's equivalent to running C:\Anaconda3\python xxx.py in an ordinary CMD, which doesn't know the Anaconda path). However, after I reinstalled Anaconda3 2020.07, I get a DLL load failed error when runing this bat file because the numpy package can't be successfully imported.

I'm sure the error is caused by the path variable and I realized that getting the DLL load failed error should be a reasonable result when running C:\Anaconda3\python xxx.py in ordinary CMD because the DLL can't be found without Anaconda directories added to the path variable in CMD.

My question is why it can be executed successfully under Anaconda 5.2.0. What's special about Anaconda 5.2.0? Why can the command find those DLL files in the ordinary CMD?

Then I checked the release notes of Anaconda. Under the Anaconda 5.2.0 part, I read the following:

Windows installer uses a trimmed down value for PATH env var, to avoid DLL hell with existing software

I guess that this may be the reason. But I can't understand the meaning of a trimmed down value for PATH env var. Does anyone know how Anaconda 5.2.0 deals with the path variable so the python interpreter can find correct DLL even outside the Anaconda Prompt in an ordinary CMD?


p.s.

The DLL load failed error is not specific to numpy package. I just take it as an example.

When importing numpy in xxx.py, the error is (last line):

Original error was: DLL load failed while importing _multiarry_umath: The specified module could not be found.

If importing sqlite3 in xxx.py, the error is (last line):

ImportError: DLL load failed while importing _sqlite3: %1 is not a valid Win32 application.

Other packages may also cause similar problem. The point is that the python interpreter used outside Anaconda Prompt (by writing the full path C:\Anaconda3\python xxx.py, or by using py xxx.py if the Python Launcher is also installed) can find correct DLL under Anaconda3 5.2.0 but can not find correct DLL under Anaconda3 2020.07, though the Anaconda directories are not added to the system path variable in both cases.


This is an example of xxx.py.

import numpy
import sqlite3
print('Hello World!')


from What's the meaning of "a trimmed down value for PATH env var" in the Anaconda release notes?

No comments:

Post a Comment