Unit test option under Atom gives an error

Purely out of curiosity, I clicked the unit test menu option in the Atom menu. It briefly opens a console window, but does nothing else. I was able to quickly copy the following error message which appears:

File "main.py", line 8, in init main (C:\users\root\appdata\local\temp\tmpyeysqp\main.c:2299)
File "c:\users\dap124\.atom\packages\platformio-ide\penv\lib\site-packages\requests\__init__.py", line 60, in <module>
from .packages.urllib3.exceptions import DependencyWarning
File "c:\users\dap124\.atom\packages\platformio-ide\penv\lib\site-packages\requests\packages\__init__.py", line 29, in <module>
import urllib3
ImportError: No module named urllib3

I’m not sure which is the appropriate repository to report this issue to, so I’m reporting here.

Could you try to open PlatformIO IDE Terminal and this command:

pip install urllib3 --upgrade

Did it help?

That removes the error with missing urllib3. However it now gives a different error:

from .connectionpool import (
File "c:\users\dap124\.atom\packages\platformio-ide\penv\lib\site-packages\urllib3\connectionpool.py", line 7, in <module>
from socket import error as SocketError, timeout as SocketTimeout
File "C:\Users\dap124\Anaconda3\envs\py27\Lib\socket.py", line 47, in <module>
import _socket
ImportError: DLL load failed: %1 is not a valid Win32 application.

This seems rather inexplicable. To investigate further, I opened a platformio terminal, then ran python. I tried to reproduce this error, with: import urllib3, import socket and from socket import error as SocketError, timeout as SocketTimeout, and none of them caused this error.

I guess that it is possible that this error might be specific to the Anaconda python distribution which I am using, as it avoids having to install Python 2.7 system-wide. If you suspect this, then I could install the official python 2.7 to check, although this would be a bit of a PITA as I’d need to reinstall platformio.

You are right, the problem is caused by Anaconda. I’ve just found one solution but need to test it. PlatformIO IDE downloads PyPi virtualenv by default and make virtual environment here c:\users\dap124\.atom\packages\platformio-ide\penv. Nevertheless, I think that we can check “if virtualenv already exists, then use it”. In you case, the virtualenv will be provided by Anaconda distribution. Let’s try it:

  1. Please close Atom and remove c:\users\dap124\.atom\packages\platformio-ide\penv
  2. Now, need to create virtual environment with Anaconda’s virtualenv
> cd c:\users\dap124\.atom\packages\platformio-ide
> virtualenv penv
> penv\Scripts\activate
> (penv) pip install platformio
  1. Restart IDE.

Does it work?

Unfortunately it still doesn’t work. What’s really strange is that if I go into the platformio terminal and run python, then none of those imports causes a problem. I confirmed with which python that it is definitely the interpreter with a path in the virtualenv that is running.

I found a couple of github issues which suggest that Anaconda is fundamentally incompatible with virtualenv (it offers its own environments which can be different python versions)

If the conclusion is that anaconda is not supported, then that would be reasonable. Anyway, I don’t have any immediate need for this unit testing functionality.

I’ve never used this Anaconda. How do you work with a virtual environment with Anaconda? I found this intro:

We have other option. Please go to PlatformIO IDE Menu: PlatformIO > Settings > PlatformIO IDE.

  1. Uncheck “Use built-in PlatformIO”. Close IDE
  2. Open Windows CMD Shell and run
> pip install -U platformio
  1. Open IDE.

If PIO still doesn’t work, you need to specify PATH ("Environment PATH to run platformio) to binary directory in the step #1.

@ivankravets: I found the problem, and it has nothing to do with using anaconda. Instead, it occurs because I am using 64 bit python on windows. The problem does not occur if I install the official python 2.7 win32 binaries. However, it does occur if I install the official 64 bit binaries. I did everything from the command-line, so it clearly has nothing to do with atom.

In a fresh python 2.7.12, I did pip install platformio, which runs find. Then I run pio test, which produces the following output:

Traceback (most recent call last):
  File "main.py", line 8, in init main (C:\users\root\appdata\local\temp\tmpyeysqp\main.c:2299)
  File "c:\python27\lib\site-packages\requests\__init__.py", line 60, in <module>
    from .packages.urllib3.exceptions import DependencyWarning
  File "c:\python27\lib\site-packages\requests\packages\__init__.py", line 29, in <module>
    import urllib3
ImportError: No module named urllib3

After running pip install -U urllib3, then running pio test, I get the following output:

Traceback (most recent call last):
  File "main.py", line 8, in init main (C:\users\root\appdata\local\temp\tmpyeysqp\main.c:2299)
  File "c:\python27\lib\site-packages\requests\__init__.py", line 60, in <module>
    from .packages.urllib3.exceptions import DependencyWarning
  File "c:\python27\lib\site-packages\requests\packages\__init__.py", line 29, in <module>
    import urllib3
  File "c:\python27\lib\site-packages\urllib3\__init__.py", line 8, in <module>
    from .connectionpool import (
  File "c:\python27\lib\site-packages\urllib3\connectionpool.py", line 7, in <module>
    from socket import error as SocketError, timeout as SocketTimeout
  File "c:\python27\lib\socket.py", line 47, in <module>
    import _socket
ImportError: DLL load failed: %1 is not a valid Win32 application.

Further update: It turns out that I had an extra python installation in my path, due to having installed GNAT on my system. After cleaning up my path, I can report the following situation

  1. After installing platformio within a standard 32bit windows python console pio test seems to work fine (i.e. it gives the expected error that I do not have a tests directory)
  2. Running pio test under 64 bit python brings up the following error

Looking at pioplus.exe with dependency walker, I see that it depends on python27.dll. I guess it is a python program packaged with py2exe or a similar tool. If you compiled it as a 32 bit windows binary, then it may be trying to link to the 32 bit dll, and having problems when it only finds the 64 bit one.

I’ve just prepared 2 different binaries for 32/64bits. Please download this archive.

You need to rename one of it to platformio.exe before running. If these binaries work in both combinations, we will add logic and automatically use based on Python Arch.

Thanks!

Just confirmed, using the correction version of pioplus.exe works under 32 bit and 64 bit official python. The 64 bit version also solves the problems I had using anaconda python. Also works fine from within atom. Thanks a lot for the fix.

Thanks for the report! We are working on a new feature for PlatformIO Plus named “PIO Remote”. We will include 2 binaries next time.