Repository navigation
Environments needs to be activated before running code on the user's behalf (e.g. unit tests or DS) #3330
Description
Activity
- addedbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugand removed
on Nov 15, 2018 I can discover and run tests fine under conda using Python 3.7 and pytest without numpy, but I do get the same failure if the environment is not activated. It seems conda has chosen to package numpy in such a way that it can't be imported unless the environment is activated (which we don't do when running tests).
With a test of:
import numpy def test_fake(): return True
and settings of:
"python.unitTest.pyTestArgs": [ "." ], "python.unitTest.unittestEnabled": false, "python.unitTest.nosetestsEnabled": false, "python.unitTest.pyTestEnabled": true
I end up with:
============================= test session starts ============================= platform win32 -- Python 3.7.0, pytest-3.10.0, py-1.7.0, pluggy-0.8.0 rootdir: c:\Users\brcan\Desktop\Testing\Some 3.7 Bunk, inifile: collected 0 items / 1 errors =================================== ERRORS ==================================== ______________________ ERROR collecting example_test.py _______________________ ImportError while importing test module 'c:\Users\brcan\Desktop\Testing\Some 3.7 Bunk\example_test.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: ..\..\..\AppData\Local\Continuum\miniconda3\envs\activatetest\lib\site-packages\numpy\core\__init__.py:16: in <module> from . import multiarray E ImportError: DLL load failed: The specified module could not be found. During handling of the above exception, another exception occurred: example_test.py:1: in <module> import numpy ..\..\..\AppData\Local\Continuum\miniconda3\envs\activatetest\lib\site-packages\numpy\__init__.py:142: in <module> from . import add_newdocs ..\..\..\AppData\Local\Continuum\miniconda3\envs\activatetest\lib\site-packages\numpy\add_newdocs.py:13: in <module> from numpy.lib import add_newdoc ..\..\..\AppData\Local\Continuum\miniconda3\envs\activatetest\lib\site-packages\numpy\lib\__init__.py:8: in <module> from .type_check import * ..\..\..\AppData\Local\Continuum\miniconda3\envs\activatetest\lib\site-packages\numpy\lib\type_check.py:11: in <module> import numpy.core.numeric as _nx ..\..\..\AppData\Local\Continuum\miniconda3\envs\activatetest\lib\site-packages\numpy\core\__init__.py:26: in <module> raise ImportError(msg) E ImportError: E Importing the multiarray numpy extension module failed. Most E likely you are trying to import a failed build of numpy. E If you're working with a numpy git repo, try `git clean -xdf` (removes all E files not under version control). Otherwise reinstall numpy. E E Original error was: DLL load failed: The specified module could not be found. !!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!! =========================== 1 error in 0.11 seconds =========================== __________There was an error in identifying unit tests in example_test.py__________ ______________________ ERROR collecting example_test.py _______________________ ImportError while importing test module 'c:\Users\brcan\Desktop\Testing\Some 3.7 Bunk\example_test.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: ..\..\..\AppData\Local\Continuum\miniconda3\envs\activatetest\lib\site-packages\numpy\core\__init__.py:16: in <module> from . import multiarray E ImportError: DLL load failed: The specified module could not be found. During handling of the above exception, another exception occurred: example_test.py:1: in <module> import numpy ..\..\..\AppData\Local\Continuum\miniconda3\envs\activatetest\lib\site-packages\numpy\__init__.py:142: in <module> from . import add_newdocs ..\..\..\AppData\Local\Continuum\miniconda3\envs\activatetest\lib\site-packages\numpy\add_newdocs.py:13: in <module> from numpy.lib import add_newdoc ..\..\..\AppData\Local\Continuum\miniconda3\envs\activatetest\lib\site-packages\numpy\lib\__init__.py:8: in <module> from .type_check import * ..\..\..\AppData\Local\Continuum\miniconda3\envs\activatetest\lib\site-packages\numpy\lib\type_check.py:11: in <module> import numpy.core.numeric as _nx ..\..\..\AppData\Local\Continuum\miniconda3\envs\activatetest\lib\site-packages\numpy\core\__init__.py:26: in <module> raise ImportError(msg) E ImportError: E Importing the multiarray numpy extension module failed. Most E likely you are trying to import a failed build of numpy. E If you're working with a numpy git repo, try `git clean -xdf` (removes all E files not under version control). Otherwise reinstall numpy. E E Original error was: DLL load failed: The specified module could not be found. !!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!Reacted by Mark Mikofski and PhilippI also forgot to mention that I verified this in an Anaconda Prompt by running directly the Python interpreter and then indirectly through an activated terminal and got the same results, so it's definitely based on how they have chosen to package numpy for at least Python 3.7.
We might have to use
child_process.exec()and compose the activation + command together to make this work which is not going to be trivial to do as we would have to re-architect how to execute Python just for this one case.Reacted by Mark Mikofskimikofski commented
on Nov 15, 2018 on Nov 15, 2018 · Hidden as resolvedAuthorshow commentMore actionsmikofski commented
on Nov 15, 2018 on Nov 15, 2018 · Hidden as resolvedAuthorshow commentMore actionsmikofski commented
on Nov 15, 2018 on Nov 15, 2018 · Hidden as resolvedAuthorshow commentMore actionsmikofski commented
on Nov 15, 2018 on Nov 15, 2018 · Hidden as resolvedAuthorshow commentMore actions10 remaining items
Don Jayamanne (@DonJayamanne) How does the failure manifest itself? I would be curious to know why it's occurring (if it's because of virtualenv then I can understand that).
- changed the title
[-]Conda needs to be activated before running code on the user's behalf[/-][+]Environments needs to be activated before running code on the user's behalf (e.g. unit tests or DS)[/+]on Jan 10, 2019 - assigned and unassigned
on Jan 29, 2019 ericsnowcurrently commented
on Jan 29, 2019 More actionsI validated this.
yay! thanks so much everyone!
Is this issue solved now? I have the latest version of Anaconda and VS code and I still have this problem.
Abarajithan G (@abarajithan11) yes, it's resolved. If you're having issues then please open a new issue.
- locked as resolved and limited conversation to collaborators
on Feb 26, 2019
Environment data
Related Issues:
Actual behavior
Tests are discovered and run in Python-3.6 conda env, but not in Python-3.7, which doesn't discover tests and/or fails in
conftests.pywhen importing numpy, fails to load DLLmultiarray. But numpy does work in a terminal, when py37 is activated, and I can importmultiarrayfromnumpy.core.Also I can even run
pytestdirectly from the terminal inside vscode, so it's something specific to how the tests are implemented. Maybe it's not implementing the conda environment correctly?Same issue with both
pytestandnosetests.Expected behavior
discover and run tests in Python-3.7 same as in Python-3.6
Steps to reproduce:
Logs
Output for
Pythonin theOutputpanel (View→Output, change the drop-down the upper-right of theOutputpanel toPython)here's the output from
pytest:Details
Output from
Consoleunder theDeveloper Toolspanel (toggle Developer Tools on underHelp)