Skip to content

Environments needs to be activated before running code on the user's behalf (e.g. unit tests or DS) #3330

Description

Environment data

  • VS Code version: 1.29.0
  • Extension version (available under the Extensions sidebar): 2018.10.1
  • OS and version: Windows10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.1 (Anaconda) and 3.6.7 (Anaconda)
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda-4.5.11
  • Relevant/affected Python packages and their versions: numpy-1.15.3, pytest-3.10, nose-1.3.7

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.py when importing numpy, fails to load DLL multiarray. But numpy does work in a terminal, when py37 is activated, and I can import multiarray from numpy.core.

Also I can even run pytest directly 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 pytest and nosetests.

Expected behavior

discover and run tests in Python-3.7 same as in Python-3.6

Steps to reproduce:

  1. install anaconda
  2. create py3.6 and py3.7 environments
  3. install vscode, python extension
  4. open a python project with testing (that uses numpy?), enable testing, select each environment and run tests.

Logs

Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

here's the output from pytest:

Details
============================= test session starts =============================
platform win32 -- Python 3.7.1, pytest-3.10.0, py-1.7.0, pluggy-0.8.0
rootdir: c:\Users\mikm\Projects\pvlib-python, inifile:
collected 0 items / 1 errors

=================================== ERRORS ====================================
______________________________ ERROR collecting  ______________________________
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\_pytest\config\__init__.py:429: in _importconftest
    return self._conftestpath2mod[conftestpath]
E   KeyError: local('c:\\Users\\mikm\\Projects\\pvlib-python\\pvlib\\test\\conftest.py')

During handling of the above exception, another exception occurred:
..\..\AppData\Local\Continuum\miniconda3\envs\py37\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:
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\_pytest\config\__init__.py:435: in _importconftest
    mod = conftestpath.pyimport()
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\py\_path\local.py:668: in pyimport
    __import__(modname)
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\_pytest\assertion\rewrite.py:294: in load_module
    six.exec_(co, mod.__dict__)
pvlib\test\conftest.py:3: in <module>
    import numpy as np
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\numpy\__init__.py:142: in <module>
    from . import add_newdocs
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\numpy\add_newdocs.py:13: in <module>
    from numpy.lib import add_newdoc
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\numpy\lib\__init__.py:8: in <module>
    from .type_check import *
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\numpy\lib\type_check.py:11: in <module>
    import numpy.core.numeric as _nx
..\..\AppData\Local\Continuum\miniconda3\envs\py37\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.

During handling of the above exception, another exception occurred:
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\py\_path\common.py:377: in visit
    for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\py\_path\common.py:429: in gen
    for p in self.gen(subdir):
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\py\_path\common.py:418: in gen
    dirs = self.optsort([p for p in entries
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\py\_path\common.py:419: in <listcomp>
    if p.check(dir=1) and (rec is None or rec(p))])
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\_pytest\main.py:599: in _recurse
    ihook = self.gethookproxy(dirpath)
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\_pytest\main.py:417: in gethookproxy
    my_conftestmodules = pm._getconftestmodules(fspath)
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\_pytest\config\__init__.py:413: in _getconftestmodules
    mod = self._importconftest(conftestpath)
..\..\AppData\Local\Continuum\miniconda3\envs\py37\lib\site-packages\_pytest\config\__init__.py:452: in _importconftest
    raise ConftestImportFailure(conftestpath, sys.exc_info())
E   _pytest.config.ConftestImportFailure: (local('c:\\Users\\mikm\\Projects\\pvlib-python\\pvlib\\test\\conftest.py'), (<class 'ImportError'>, ImportError("\nImporting the multiarray numpy extension module failed.  Most\nlikely you are trying to import a failed build of numpy.\nIf you're working with a numpy git repo, try `git clean -xdf` (removes all\nfiles not under version control).  Otherwise reinstall numpy.\n\nOriginal error was: DLL load failed: The specified module could not be found.\n"), <traceback object at 0x0000012E97C8C688>))
 generated xml file: C:\Users\mikm\AppData\Local\Temp\tmp-18512deYtowEyIRt8.xml 
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.53 seconds ===========================

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

There were some errors in discovering unit tests

t.onDidNotificationChange @ notificationsAlerts.ts:40
(anonymous) @ notificationsAlerts.ts:26
e.fire @ event.ts:145
t.notify @ notifications.ts:113
t.notify @ notificationService.ts:52
e._showMessage @ mainThreadMessageService.ts:83
e._showMessage @ mainThreadMessageService.ts:44
e.$showMessage @ mainThreadMessageService.ts:38
t._doInvokeHandler @ rpcProtocol.ts:439
t._invokeHandler @ rpcProtocol.ts:424
t._receiveRequest @ rpcProtocol.ts:341
t._receiveOneMessage @ rpcProtocol.ts:271
(anonymous) @ rpcProtocol.ts:146
e.fire @ event.ts:145
a @ ipc.net.ts:103
n._socketDataListener @ ipc.net.ts:132
emitOne @ events.js:116
emit @ events.js:211
addChunk @ _stream_readable.js:263
readableAddChunk @ _stream_readable.js:250
Readable.push @ _stream_readable.js:208
onread @ net.js:594

Activity

  1. brettcannon commented on Nov 15, 2018

    @brettcannon
    Member

    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 !!!!!!!!!!!!!!!!!!!
    
  2. brettcannon commented on Nov 15, 2018

    @brettcannon
    Member

    I 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.

  3. mikofski commented on Nov 15, 2018

    @mikofski
    Author
  4. mikofski commented on Nov 15, 2018

    @mikofski
    Author
  5. mikofski commented on Nov 15, 2018

    @mikofski
    Author
  6. mingwandroid commented on Nov 15, 2018

    @mingwandroid
  7. mingwandroid commented on Nov 15, 2018

    @mingwandroid
  8. mikofski commented on Nov 15, 2018

    @mikofski
    Author
  9. 10 remaining items

  10. brettcannon commented on Jan 7, 2019

    @brettcannon
    Member

    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).

  11. 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
  12. ericsnowcurrently commented on Jan 29, 2019

    @ericsnowcurrently

    I validated this.

  13. mikofski commented on Jan 29, 2019

    @mikofski
    Author

    yay! thanks so much everyone!

  14. abarajithan11 commented on Feb 21, 2019

    @abarajithan11

    Is this issue solved now? I have the latest version of Anaconda and VS code and I still have this problem.

  15. brettcannon commented on Feb 26, 2019

    @brettcannon
    Member

    Abarajithan G (@abarajithan11) yes, it's resolved. If you're having issues then please open a new issue.

  16. locked as resolved and limited conversation to collaborators on Feb 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-testingbugIssue identified by VS Code Team member as probable bugimportantIssue identified as high-priority

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions