<div dir="ltr">It does not work in python console of QGIS.<div>pip have __main__() methot that too for internal use.</div><div><br></div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div>Thanks & Regards<br>Shiva Reddy K.<br>Scientist/Engineer 'SD'<br>Indian Institute of Remote Sensing,<br>Indian Space Research Organisation<br>Department of Space<br></div>4-Kalidas Road<br></div>Dehradun<br><div><div>mobile: 8791806093<br></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Jul 8, 2018 at 11:58 AM Luke Pinner <<a href="mailto:lukepinnerau@gmail.com">lukepinnerau@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="auto">Rather than using a subprocess and needing to figure out which pip/python etc., have you tried importing and using the pip module directly? Something like:</div><div dir="auto"><br></div><div dir="auto"><pre style="font-size:13px;margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-variant-numeric:inherit;font-stretch:inherit;line-height:inherit;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;vertical-align:baseline;box-sizing:inherit;width:auto;max-height:600px;overflow:auto;background-color:rgb(239,240,241);word-wrap:normal;color:rgb(36,39,41)"><code style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;vertical-align:baseline;box-sizing:inherit;white-space:inherit">import sys

try:
    import matplotlib
except:
    import pip
</code>    pip.main([<span style="font-style:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit;white-space:inherit">'install', 'matplotlib'])
</span>    import matplotlib</pre></div><div class="gmail_quote"><div>Luke</div><div dir="ltr"><br></div><div dir="ltr">On Sun., 8 Jul. 2018, 15:42 Axel Andersson, <<a href="mailto:axel.n.c.andersson@gmail.com" target="_blank">axel.n.c.andersson@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi, <div><br></div><div>I added this to my code just 3 days ago :)</div><div><br></div><div><pre style="margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-variant-numeric:inherit;font-stretch:inherit;line-height:inherit;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;font-size:13px;vertical-align:baseline;box-sizing:inherit;width:auto;max-height:600px;overflow:auto;background-color:rgb(239,240,241);word-wrap:normal;color:rgb(36,39,41)"><code style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;vertical-align:baseline;box-sizing:inherit;white-space:inherit">import sys

try:
    import matplotlib
except:
    import subprocess
    print('installing matplotlib')
    subprocess.call([sys.exec_prefix + '/python', "-m", 'pip', 'install', 'matplotlib'])
    import matplotlib
    print('installation completed')</code></pre><br>I dont know if it is a better or worse solution, I've only tested it on a Windows machine with the standalone version and the osgeo4w installation.</div><div><br></div><div>I tried calling <span class="m_-7882859215590091882m_-1687825856108736648m_1086043957033455071gmail-pln" style="font-family:inherit;font-style:inherit;font-variant:inherit;font-weight:inherit;white-space:inherit;background-color:rgb(239,240,241);font-size:13px;margin:0px;padding:0px;border:0px;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;color:rgb(48,51,54)">sys</span><span class="m_-7882859215590091882m_-1687825856108736648m_1086043957033455071gmail-pun" style="font-family:inherit;font-style:inherit;font-variant:inherit;font-weight:inherit;white-space:inherit;background-color:rgb(239,240,241);font-size:13px;margin:0px;padding:0px;border:0px;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;color:rgb(48,51,54)">.</span><span class="m_-7882859215590091882m_-1687825856108736648m_1086043957033455071gmail-pln" style="font-variant-numeric:inherit;margin:0px;padding:0px;border:0px;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit"><font color="#303336" face="inherit"><span style="font-style:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit;white-space:inherit;background-color:rgb(239,240,241)">executable first, </span></font>instead of<font color="#303336" face="inherit"><span style="font-style:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit;white-space:inherit;background-color:rgb(239,240,241)"> </span></font></span><span style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;font-style:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit;white-space:inherit;background-color:rgb(239,240,241);color:rgb(36,39,41);font-size:13px">sys.exec_prefix + '/python',</span> which resulted in a new qgis window started :)</div><div><br></div><div>Axel</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 7 July 2018 at 14:23, Richard Duivenvoorde <span dir="ltr"><<a href="mailto:rdmailings@duif.net" rel="noreferrer" target="_blank">rdmailings@duif.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On 07/07/2018 01:26 PM, shiva reddy wrote:<br>
> Thanks,<br>
> In OS X following works:<br>
> subprocess.call(['pip3','install','pyxform'])<br>
> <br>
> Does same works  works for Ubuntu/linux also?<br>
>  <br>
> for windows, I am assuming 'python' refers to python 3 inside QGIS3.<br>
<br>
</span>Yep:<br>
<br>
import subprocess<br>
subprocess.call(['pip3','install','pyxform','--user'])<br>
<br>
works too.<br>
<br>
But as said, not sure if all distro's call the python3 pip: pip3 (and/or<br>
python3). I still would be afraid to force a specific version of a<br>
module, as I would be afraid to override some excisting one.<br>
I do like your solution though, the libs end up in my user site-packages<br>
dir:<br>
/home/richard/.local/lib/python3.5/site-packages<br>
<br>
<br>
Ah: <a href="http://zetcode.com/lang/python/introspection/" rel="noreferrer noreferrer" target="_blank">http://zetcode.com/lang/python/introspection/</a><br>
>>> import sys<br>
>>> sys.executable<br>
'/usr/bin/python3'<br>
<br>
gives you your actual python exe...<br>
<br>
I wonder if you can create an venv from within QGIS in the subprocess way.<br>
Mmm, this works (from within QGIS):<br>
<br>
>>> import sys<br>
>>> py_exe = sys.executable<br>
>>> venv_path =<br>
'/home/richard/.local/share/QGIS/QGIS3/profiles/default/venv'<br>
>>> subprocess.call([py_exe,'-m','venv', venv_path])<br>
<br>
Had to install python3-venv though:<br>
sudo apt-get install python3-venv<br>
<br>
sourcing it does not work with me:<br>
<br>
>>> subprocess.call(['source', venv_path+'/bin/activate'])<br>
FileNotFoundError: [Errno 2] No such file or directory: 'source'<br>
<br>
Now somebody with more knowledge of the different python-path/lib-dir's<br>
should come in, to tell us if this is usable after activating that venv...<br>
<br>
Not sure if this would work with the already running python interpreter<br>
in QGIS...<br>
<br>
Idea's?<br>
<div class="m_-7882859215590091882m_-1687825856108736648m_1086043957033455071HOEnZb"><div class="m_-7882859215590091882m_-1687825856108736648m_1086043957033455071h5"><br>
Regards,<br>
<br>
Richard Duivenvoorde<br>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" rel="noreferrer" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></div></div></blockquote></div><br></div>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" rel="noreferrer" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></blockquote></div>
</div>
</blockquote></div>