I found packaging the pip module with the plugin wont work with p4pthon pip. This is due to the .pyd that comes with P4.py file needing to be in appData\Roaming. So subprocess would be the way forward. Using that approach has worked. Thanks @ross-g
Below shows code to check p4pthyon is present in Painter before my bespoke menu is built. If it’s not present to user, then it will be intsalled with pip.
import sys
import subprocess
class SubstancePainterP4_Setup:
"""
Description: Checks and installs p4python!
"""
@staticmethod
def install_p4python():
try:
__import__("P4")
except:
substance_exe_path = sys.executable # Get Substance Painter .exe path
substance_exe_name = substance_exe_path.split("/")[-1] # Get substance painter .exe name
python_exe = substance_exe_path.replace(substance_exe_name,
"resources/pythonsdk/python.exe")
subprocess.check_call([python_exe, "-m", "pip", "install", "p4python"],
creationflags=subprocess.CREATE_NEW_CONSOLE)
print("p4python installed!")
def start_plugin():
SubstancePainterP4_Setup.install_p4python()