PyCall not working when run from vscode run command

I’ve setup PyCall (note I have an anaconda distribuiton)

ENV["PYTHON"] = "C:\Anaconda3\python.exe""PyCall")

In vscode when I open a new terminal (I’m on windows so a power shell opens) and then start julia

(base) PS C:\dev\Apollo> julia
   _       _ _(_)_     |  Documentation:
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.0-rc1 (2023-03-07)
 _/ |\__'_|_|_|\__'_|  |  Official release
|__/                   |

and activate my environment with ] activate .

The following code works just fine

julia> using PyCall
julia> const np = pyimport("numpy")
PyObject <module 'numpy' from 'C:\\Anaconda3\\lib\\site-packages\\numpy\\'>

However now if I put this code in a julia scipt, myfile.jl


using PyCall
const np = pyimport("numpy")

and run the script using the “Julia: Execute active File in REPL” command. This will start a new Julia REPL but now I get the following error

C:\Anaconda3\lib\site-packages\numpy\ UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see
  from . import _distributor_init
ERROR: PyError (PyImport_ImportModule

The Python package numpy could not be imported by pyimport. Usually this means
that you did not install numpy in the Python version being used by PyCall.

PyCall is currently configured to use the Python version at:


and you should use whatever mechanism you usually use (apt-get, pip, conda,
etcetera) to install the Python package containing the numpy module.

One alternative is to re-configure PyCall to use a different Python
version on your system: set ENV["PYTHON"] to the path/name of the python
executable you want to use, run"PyCall"), and re-launch Julia.

Another alternative is to configure PyCall to use a Julia-specific Python
distribution via the Conda.jl package (which installs a private Anaconda
Python distribution), which has the advantage that packages can be installed
and kept up-to-date via Julia.  As explained in the PyCall documentation,
set ENV["PYTHON"]="", run"PyCall"), and re-launch Julia. Then,
To install the numpy module, you can use `pyimport_conda("numpy", PKG)`,
where PKG is the Anaconda package that contains the module numpy,
or alternatively you can use the Conda package directly (via
`using Conda` followed by `Conda.add` etcetera).

) <class 'ImportError'>
ImportError('\n\nIMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!\n\nImporting the numpy C-extensions failed. This error can happen for\nmany reasons, often due to issues with your setup or how NumPy was\ninstalled.\n\nWe have compiled some common reasons and troubleshooting tips at:\n\n\n\nPlease note and check the following:\n\n  * The Python version is: Python3.9 from "C:\\Julia-1.9.0-rc1\\bin\\julia.exe"\n  * The NumPy version is: "1.21.5"\n\nand make sure that they are the versions you expect.\nPlease carefully study the documentation linked above for further help.\n\nOriginal error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.\n')
  File "C:\Anaconda3\lib\site-packages\numpy\", line 150, in <module>
    from . import core
  File "C:\Anaconda3\lib\site-packages\numpy\core\", line 48, in <module>
    raise ImportError(msg)

 [1] pyimport(name::String)
   @ PyCall C:\Users\myusername\.julia\packages\PyCall\twYvK\src\PyCall.jl:558
 [2] top-level scope
   @ c:\dev\Apollo\src\qvfx\myfile.jl:3

Now one thing I noticed between the two REPL’s is the environment variables that are loaded

println(ENV) in the working REPL spits out all my environment variables including



But when I println(ENV) from the non working REPL (started from “Julia: Execute active File in REPL”) these environment variables are not present. I’m thinking this could be the issue so I modified myfile.jl by adding all these additional environment variables (including the changes made to the path)


ENV["PATH"] = raw"C:\Anaconda3;C:\Anaconda3\Library\mingw-w64\bin;C:\Anaconda3\Library\usr\bin;C:\Anaconda3\Library\bin;C:\Anaconda3\Scripts;C:\Anaconda3\bin;C:\Anaconda3\condabin;C:\Program Files\WindowsApps\Microsoft.PowerShell_7.3.3.0_x64__8wekyb3d8bbwe;" * ENV["PATH"]

using PyCall
const np = pyimport("numpy")

And viola it works. So my question is what is adding all these env variables to one REPL but not the other (the one using the “Julia: Execute active File in REPL” command) and how can I fix it so these variables are automatically added.