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?
- Downloads https://bootstrap.pypa.io/get-pip.py.
- Downloads the
c4dpy
[URL-REMOVED] version matching your Cinema 4D version. (Already included in R21) - Moves c4dpy and get-pip.py in the Cinema 4D folder.
- 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).
- Window: Type
- Runs this command line
c4dpy get-pip.py
. This will execute the get-pip script which will, download and install the pip module. - 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.
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
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 simplec4dpy
givescommand not found
.Cheers,
Lasse -
Hi,
this doesn't seem to work anymore../c4dpy.app/Contents/MacOS/c4dpy -m pip install numpy Collecting numpy Downloading numpy-1.19.4.zip (7.3 MB) (null) |ββββββββββββββββββββββββββββββββ| 7.3 MB 5.3 MB/s (null) (null) Installing build dependencies ... (null)error ERROR: Command errored out with exit status 2: command: '/Applications/Maxon Cinema 4D R23/./c4dpy.app/Contents/MacOS/c4dpy' '/Applications/Maxon Cinema 4D R23/resource/modules/python/libs/python37.macos.framework/lib/python3.7/site-packages/pip' install --ignore-installed --no-user --prefix /private/tmp/pip-build-env-7f2h5t11/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools<49.2.0' 'wheel<=0.35.1' 'Cython>=0.29.21,<3.0' cwd: None Complete output (1 lines): /Applications/Maxon Cinema 4D R23/./c4dpy.app/Contents/MacOS/c4dpy: can't open file 'pip': is a directory (file:///Applications/Maxon Cinema 4D R23/resource/modules/python/libs/python37.macos.framework/lib/python3.7/site-packages/pip) ---------------------------------------- ERROR: Command errored out with exit status 2: '/Applications/Maxon Cinema 4D R23/./c4dpy.app/Contents/MacOS/c4dpy' '/Applications/Maxon Cinema 4D R23/resource/modules/python/libs/python37.macos.framework/lib/python3.7/site-packages/pip' install --ignore-installed --no-user --prefix /private/tmp/pip-build-env-7f2h5t11/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools<49.2.0' 'wheel<=0.35.1' 'Cython>=0.29.21,<3.0' Check the logs for full command output. [1] 48826 segmentation fault sudo ./c4dpy.app/Contents/MacOS/c4dpy -m pip install numpy
-