简体   繁体   中英

Python script file containing parameters fails to execute in batch file

I'm trying to run a simple Windows batch file containing just one line:

python c:\temp\script.py

The input file to be executed by python, script.py, contains these lines:

# This Python file uses the following encoding: utf-8
import os
os.chdir("C:/Program Files/QGIS 2.18/apps/Python27/Scripts")
code = "python –m pip install –U pip setuptools"
os.system(code)

Script.py of course executes fine on its own, but when run from within the setup.bat file, the following error results:

python: can't open file 'ΓÇôm': [Errno 2] No such file or directory

It is stumbling on the "-m" option in the script.py command line, because if a command without signed options is passed in the script.py file (ie, "code=pip install setuptools"), it works just fine. Any substring with a "-" character messes the batch file execution up.

Any thoughts are welcome.

You need pip to be installed prior to executing the command. Something like this should work.

import pip

# to install requirements
pip.main(['install', '-r', 'requirements.txt'])

# to install one package
pip.main(['install', 'package_name'])

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