3rd party APIs into pyp/pypv file



  • Hello PluginCafe! :)

    Is it possible to use 3rd part APIs, e.g. Google Drive API, inside C4D's python plugin?

    There is a pip install code on Google Developers webpage:
    pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

    Can I simply install it directly inside pyp file or import it by utilizing Niklas' code?



  • Hi @merkvilson first of all pip and Niklas localimport module is completely two different things.

    • pip is a python module manager (similar to package manager in unix). This means once it's installed to a python binary, it will be able to manage other modules, download them, install them with all their dependencies and update them and so on.
    • localimport is a python module that let you manage import in a local way while in Cinema 4D by default is global. For more information please read how the import function works in python.
      Meaning if you add a module named xyz to the sys.path from your plugin A and from plugin B you try to import another module named xyz, it will load the one from plugin A (the first one register).

    Now how to install pip?

    1. Downloads https://bootstrap.pypa.io/get-pip.py.
    2. Downloads the c4dpy version matching your Cinema 4D version.
    3. Moves c4dpy and get-pip.py in the Cinema 4D folder.
    4. Opens a shell to the Cinema 4D folder:
      • Window: Type cmd in the top path and press Enter.
      • Mac: Open a new shell, then with cd navigate to your Cinema 4D folder. (You can drag and drop the path).
    5. Runs this command line c4dpy get-pip.py. This will execute the get-pip script which will, download and install the pip module.
    6. Now you can start to play with pip c4dpy -m pip install numpy. c4dpy allow to runs any module with the -m argument see c4dpy commandline. in this case I asked to pip to download and install numpy but any other 3rd party compatible with pip can be downloaded and used.

    With that's said we do not provide support for 3rd party modules, so if it does not work with Cinema 4D Python environment, we can't help you.

    Cheers,
    Maxime.



  • thanks for the answer Maxim from Maxon

    I was following this url from Niklas, but I guessed it was a bit old :-)

    Also it is important to add to the env path this directory :
    C:\Program Files\MAXON\Cinema 4D R20\resource\modules\python\libs\win64\python27.vs2008.framework\Scripts
    which is the place where the get-pip.py have installed the new exec.

    It has perfectly installed numpy-1.16.2

    Question : do we need absolutely c4dpy.exe ? (as I managed to run during my previous test with the python.exe)



  • No you don't necessary need c4dpy, it's just more convenient and easy to find for everyone and for all future releases.



  • @m_adam Just a little addition on macOS you need to put: c4dpy/Contents/MacOS/c4dpy get-pip.py into the terminal, to link to the real executable. the simple c4dpy gives command not found.

    Cheers,
    Lasse


Log in to reply