0

First, I've found how to call a script from within an other script in Python, the call works perfectly well, but here's the problem I'm running into :

In order to easy-install my web-app (Bottle) on an another server, I packed inside a /redist rep, with mod_wsgi and PyMySQL source files. What I'm trying to achieve is a kind of "setup.py" file, that will launch the /mod_wsgi/setup.py install file and the same with the PyMySQL setup file.

Here's what I'm doing for PyMySQL for example :

subprocess.call("python3 ./redist/PyMySQL/setup.py install", shell=True)

The instalation runs fine, BUT, I end up with a /build, a /dist and a /PyMySQL.egg-info folders in my app directory, and when I'm trying to launch anything that imports PyMySQL, it told me that the module didn't exist.

If I manually install it (using my terminal I mean, like cd /redist/PyMySQL/ and then py3 setup.py install), it works great, and the import will then work ...

Any idea ? Am I doing something wrong ?

By advance, thanks :)

Zabka
  • 104
  • 1
  • 10
  • I think this would solve your issue : http://stackoverflow.com/questions/1685157/python-specify-popen-working-directory-via-argument – Azurtree May 29 '15 at 10:06
  • Yeah, but, what workingdir should I use ? /usr/local/lib/pythonx.y ? / ? – Zabka May 29 '15 at 11:32

1 Answers1

1

I think this would solve your issue : Python specify popen working directory via argument

I suppose in the "./redist/PyMySQL/" directory could be used as parameter because it is where the setup.py is located

try this :

subprocess.Popen("py3 setup.py", cwd='/redist/PyMySQL/')

on my end this works :

subprocess.Popen(['py3','setup.py'], cwd='path-of-my-setup')
Community
  • 1
  • 1
Azurtree
  • 369
  • 4
  • 11
  • I ended up with this : `x = os.getcwd() install_path = ''.join(["",str(x),"/redist/PyMySQL/"]) subprocess.Popen("%ssetup.py" %install_path, cwd="'%s'" %install_path)` Not working – Zabka May 29 '15 at 11:52
  • Hum, you are forgetting the python command, maybe that would help. – Azurtree Jun 01 '15 at 06:32
  • if I use this line : `subprocess.Popen("python3 %ssetup.py" %install_path, cwd="'%s'" %install_path)` (where install_path is the right path to the /PyMySQL folder, I got an error say that /var/www/AGS/redist/PyMySQL/setup.py doesn't exist (but it does !) – Zabka Jun 01 '15 at 11:46
  • I updated the code in the answer, did you try it ? (note to put the correct dir in the cws ;) ) – Azurtree Jun 01 '15 at 13:04
  • Ok and try the new code where 'path-of-my-setup' is your absolute path from root '/' to the setup.py file :=) – Azurtree Jun 01 '15 at 13:19
  • 1
    Ok, it's now working fine, thanks a lot ! I'm using `subprocess.Popen(args, cwd='%s' %working_dir)` where `args` is : `args = ['%ssetup.py' %working_dir,'install']` I was already using path from root (working_dir is `''.join(["",str(os.getcwd),"/redist/PyMySQL/"])`) – Zabka Jun 01 '15 at 13:21
  • Actually, why do we need to run `setup.py` on the directory itself? is there any documentation that refer to this? – Joshua H Feb 20 '19 at 05:39
  • @joshuaH you might want to put your comment in the question of the topic itself :) – Azurtree Feb 20 '19 at 07:40