1

So I've finished building my new PC, basically a fresh windows install with just some drivers and basic programs. After setting everything up I decided to install Anaconda and VSCode. Thats what I did and that is ALL I installed. I set up environment paths to the python.exe. Despite this when I try to import numpy in VSCode it doesnt work.

I tried running this tiny bit of code to see if VSCode could import conda modules:

import numpy as np
data = [1, 32, 345, 2, 543, 48237, 3, 432, 378, 946, 234, 12, 345, 1, 2, 3, 4567, 32]
print(np.mean(data)

Running the above code resulted in this error:

Traceback (most recent call last):
  File "c:\Users\Daniel\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "c:\Users\Daniel\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\lib\python\ptvsd\__main__.py", line 432, in main
    run()
  File "c:\Users\Daniel\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\lib\python\ptvsd\__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "C:\Users\Daniel\Anaconda3\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\Daniel\Anaconda3\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\Daniel\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\dev\test\main.py", line 1, in <module>
    import numpy as np
  File "C:\Users\Daniel\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import _distributor_init
  File "C:\Users\Daniel\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.

I tried seeing if Visual Studio Code is using the correct interpreter just in case but just like I expected there is only one interpreter to choose from

EDIT: It does work in command line as expected and I tried doing conda install numpy with no success

EDIT2: Solved! I noticed the following error in my VS Code:

File *name* cannot be loaded because running scripts is disabled on this system.

So I went into powershell and allowed to run signed scripts by typing in 'Set-ExecutionPolicy RemoteSigned' and everything worked like a charm afterwards

6
  • does it work in command line? Is the error just in VS Code? Commented Aug 27, 2019 at 13:54
  • ok, if VSCode and python are realy THE ONLY things you installed, than you forget to install numpy. link Commented Aug 27, 2019 at 13:54
  • @VaibhavVishal yep works in python shell perfectly it looks like its VS Code thats causing issues Commented Aug 27, 2019 at 13:56
  • @MateuszBoruch numpy comes with conda preinstalled last I checked but in any case I tried to install numpy separately again and it results in the same error Commented Aug 27, 2019 at 13:56
  • anaconda makes a virtual-env by default. make sure VS Code is using that virtual-env. Use the official Python extension for VS Code by Microsoft to easily select venv in VS Code. Commented Aug 27, 2019 at 13:58

1 Answer 1

1

Managed to solve this one myself. I noticed the following error in my VS Code:

File *name* cannot be loaded because running scripts is disabled on this system.

So I went into powershell and allowed to run signed scripts by typing in 'Set-ExecutionPolicy RemoteSigned' and everything worked like a charm afterwards

In any case thanks to everyone who tried to help, turns out i have to learn to read

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.