简体   繁体   中英

python import from subprocess fails

I have been working on some makefiles which call some python scripts to perform various tasks. Up to now, I had always been make ing on a machine with Ubuntu 16.04 (64 bits) installed. Today, I have tried building on my old 32 bits machine with Lubuntu 16.04 using the same makefile and it fails when calling the Python script.

At first, I thought that my Python version was not new enough, but I also have Python 3.5 installed and I changed the line to python3 in the makefile and it still fails:

python3 /home/morane/Documents/Programming/ConnectX/cxPythonTools/RunUnitTests.py -t /home/morane/bin/tests/unit/cxUnitTests.out -l /home/morane/bin/tests/unit/log/unitTests.log
Traceback (most recent call last):
  File "/home/morane/RunUnitTests.py", line 41, in <module>
    from subprocess import CREATE_NEW_CONSOLE
ImportError: cannot import name 'CREATE_NEW_CONSOLE'
Makefile:51: recipe for target 'unittests' failed
make: *** [cxbaseunit] Error

To test, I have tried to repeat the error directly in the Python shell:

Python 3.5.2+ (default, Sep 22 2016, 12:18:14) 
[GCC 6.2.0 20160927] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> from subprocess import CREATE_NEW_CONSOLE
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'CREATE_NEW_CONSOLE'

and it still fails. Does anyone know whats going on?

Regards

It appears that you're running in Linux. The CREATE_NEW_CONSOLE constant is only available on Windows.

https://docs.python.org/3/library/subprocess.html#subprocess.CREATE_NEW_CONSOLE

Specifically the header of section 17.5.4:

The STARTUPINFO class and following constants are only available on Windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM