Thanks, But it does not work in MacOS
Thanks & Regards Shiva Reddy K. Scientist/Engineer 'SC' Indian Institute of Remote Sensing, Indian Space Research Organisation Department of Space 4-Kalidas Road Dehradun mobile: 8791806093 On Sun, Jul 8, 2018 at 11:12 AM Axel Andersson <axel.n.c.anders...@gmail.com> wrote: > Hi, > > I added this to my code just 3 days ago :) > > 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') > > > 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. > > I tried calling sys.executable first, instead of sys.exec_prefix + > '/python', which resulted in a new qgis window started :) > > Axel > > On 7 July 2018 at 14:23, Richard Duivenvoorde <rdmaili...@duif.net> wrote: > >> On 07/07/2018 01:26 PM, shiva reddy wrote: >> > Thanks, >> > In OS X following works: >> > subprocess.call(['pip3','install','pyxform']) >> > >> > Does same works works for Ubuntu/linux also? >> > >> > for windows, I am assuming 'python' refers to python 3 inside QGIS3. >> >> Yep: >> >> import subprocess >> subprocess.call(['pip3','install','pyxform','--user']) >> >> works too. >> >> But as said, not sure if all distro's call the python3 pip: pip3 (and/or >> python3). I still would be afraid to force a specific version of a >> module, as I would be afraid to override some excisting one. >> I do like your solution though, the libs end up in my user site-packages >> dir: >> /home/richard/.local/lib/python3.5/site-packages >> >> >> Ah: http://zetcode.com/lang/python/introspection/ >> >>> import sys >> >>> sys.executable >> '/usr/bin/python3' >> >> gives you your actual python exe... >> >> I wonder if you can create an venv from within QGIS in the subprocess way. >> Mmm, this works (from within QGIS): >> >> >>> import sys >> >>> py_exe = sys.executable >> >>> venv_path = >> '/home/richard/.local/share/QGIS/QGIS3/profiles/default/venv' >> >>> subprocess.call([py_exe,'-m','venv', venv_path]) >> >> Had to install python3-venv though: >> sudo apt-get install python3-venv >> >> sourcing it does not work with me: >> >> >>> subprocess.call(['source', venv_path+'/bin/activate']) >> FileNotFoundError: [Errno 2] No such file or directory: 'source' >> >> Now somebody with more knowledge of the different python-path/lib-dir's >> should come in, to tell us if this is usable after activating that venv... >> >> Not sure if this would work with the already running python interpreter >> in QGIS... >> >> Idea's? >> >> Regards, >> >> Richard Duivenvoorde >> _______________________________________________ >> QGIS-Developer mailing list >> QGIS-Developer@lists.osgeo.org >> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer >> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer >> > >
_______________________________________________ QGIS-Developer mailing list QGIS-Developer@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer