hourigan
We probably won't include rpy2 in the iolite installer because it is licensed under the GPL and we're not clear on the legality of including it in closed source software. Most of the python scientific computing packages are permissively licensed (MIT/BSD/etc.) but rpy2 went with the same license as R.
There are things you can do to make things easier though!
- Create a virtual environment external to iolite however you like. Create a file in the virtual environments site-packages folder called iolite.pth. In that file put the path to iolite's site-packages (e.g., C:\Program Files (x86)\iolite-software\iolite4\python3.8\site-packages).
- Now when you use that virtual environment it'll also have the iolite site-packages available.
- When you're in that virtual environment, install additional packages as you normally would.
- In iolite's preferences, go the the paths section, add a semi-colon followed by the path to the virtual environment's site-packages (e.g. C:\Users\japet.venv\iolite_test\Lib\site-packages). Save and restart iolite.
- Now the additional package you install in your virtual environment should be available in iolite and when using the virtual environment with another python editor/IDE it should pick up iolite's stuff.
Catches:
- The version of python you create the virtual environment with should match iolite's (i.e. 3.8).
- The python editor/IDE you use outside of iolite will not know about things available via iolite's python API because they are not normal site packages.
Finally, it is also possible to install packages via pip in iolite by invoking pip as a module in python. Here is a rough example of how that might work as a UI plugin:
# A python-based UI module for iolite 4 starts with some metadata
#/ Type: UI
#/ Name: Install package
#/ Description: Installs package using internal pip
#/ Authors: J. Petrus and B. Paul
#/ References:
#/ Version: 1.0
#/ Contact:
from iolite.QtGui import QAction, QInputDialog, QProgressBar, QWidget, QLabel, QTextBrowser, QVBoxLayout
from iolite.QtCore import QTemporaryDir, QSettings, QFile, Qt, QDir
import numpy as np
import pip
from distutils.dir_util import copy_tree
widget = None
def createUIElements():
action = QAction('Install package', ui)
action.triggered.connect(install_package)
ui.setAction(action)
ui.setMenuName(['Tools'])
def install_package():
global widget
name = QInputDialog.getText(None, 'Install package', 'Package name:')
if not name:
return
widget = QWidget()
widget.setAttribute(Qt.WA_DeleteOnClose)
widget.setLayout(QVBoxLayout())
label = QLabel(f'Trying to install {name}...', widget)
widget.layout().addWidget(label)
progress = QProgressBar(widget)
progress.setMaximum(0)
progress.setMinimum(0)
progress.setValue(0)
widget.layout().addWidget(progress)
textBrowser = QTextBrowser(widget)
widget.layout().addWidget(textBrowser)
textBrowser.setVisible(False)
widget.show()
tempDir = QTemporaryDir()
logFilePath = tempDir.path() + '/pip.log'
print(f'Using tempDir = {tempDir.path()}')
pipReturn = pip.main(['install', name, '--target', tempDir.path(), '--log', logFilePath])
pathOptions = QSettings().value('Paths/PythonPath').split(';')
pathOptions = [option for option in pathOptions if 'site-packages' in option]
if len(pathOptions) == 0:
raise RuntimeError('Could not find a suitable site-packages folder.')
elif len(pathOptions) == 1:
installPath = pathOptions[0]
else:
installPath = QInputDialog.getItem(None, 'Install package', 'Path', pathOptions)
print(f'Using installPath = {installPath}')
logFile = QFile(logFilePath)
logText = ''
if logFile.open(QFile.ReadOnly):
logText = str(logFile.readAll())
logFile.close()
if pipReturn == 0:
label.setText('Success!')
else:
label.setText('Something went wrong... :(')
logText = logText.replace('\\r\\n', '<br>')[2:-1]
textBrowser.setHtml(logText)
textBrowser.setVisible(True)
progress.setVisible(False)
if len(QDir(tempDir.path()).entryList()) > 1:
copy_tree(tempDir.path(), installPath)
I wrote this a long time ago and never quite finished it, but I did just use it to install rpy2 successfully here. I think with a bit of work, a script could be devised to automate downloading R (e.g. urllib), installing it (e.g. subprocess.run), installing rpy2 (see script above) and isoplotr (via rpy2)..
All the best,