I try to call a Python script from setup.py during installation, using a custom install:
class CustomInstall(install):
def run(self):
install.run(self)
...
p = subprocess.Popen(
[sys.executable, 'demo_package/deploy_database.py'],
shell=True,
stdout=subprocess.PIPE,
cwd=os.path.join(self.install_lib, 'demo_package'))
out, err = p.communicate()
setup(..., cmdclass=dict(install=CustomInstall))
When deploying the package on a Ubuntu machine, the process, instead of executing deploy_database.py, shows nothing. When I stop it manually with Ctrl+C, the output seems to indicate that instead of actually running deploy_database.py, it simply starts Python:
^CDownloading/unpacking PypiPackagesMonitoring
Downloading demo-1.0.64.zip
Running setup.py egg_info for package demo
Installing collected packages: demo
Running setup.py install for demo
Python 3.3.2+ (default, Oct 9 2013, 14:50:09)
[GCC 4.8.1 on linux
Type "help", "copyright", "credits" or "license" for more information.
Cleaning up...
Operation cancelled by the user
Storing complete log in /home/.../.pip/pip.log
What is wrong in the way I call a Python script? How should I do it instead?
execfile.shell=Trueought to imply that you need a feature that cannot be expressed as a simple sequence of strings, i.e. when usingshell=Trueyou must use a single string that represents the whole shell command*(which is *not simply calling an external program, but includes some shell features such as pipes/redirection/calling a built-in etc.). Otherwise you should useshell=Falseand you can represent the program to execute and its arguments in the same format ofsys.argv. Mixing the two methods results in this strange results.