Numpy Revisited for R18 (Simple)



  • On 22/04/2017 at 08:07, xxxxxxxx wrote:

    After reviewing the thread "Installing numpy", circa January 2016, and clicking on a few dead links, I wanted to test the waters with a new numpy related thread for 2017 and C4D R18.
    Is there a quick, drag and drop, method to add the numpy functionality into C4D for non-developers?  Perhaps a current, step-by-step recipe with current download links?  Something a Python laymen could follow?
    I suspect there are other C4D users like me, who don't have compilers and such, but would love to take advantage of the numpy commands in our python scripts if it would not be too hard to add them.
    Thank you for any guidance on this topic!
    Thom



  • On 23/04/2017 at 01:45, xxxxxxxx wrote:

    Hi Thom,

    what dead links have you found? As far as I can tell, you can still find the Python modules I compiled
    under the link in my blog post: https://www.niklasrosenstein.com/2015/04/python-binaries-for-cinema-4d/

    (Note: I updated the link just now not because it wasn't working but because I wanted to restructure
    the directories on my server anyway and did that just now).

    There's numpy 1.10.4 for Windows and numpy 1.11.0 for mac OS.

    Cheers,
    Niklas

    PS: You need the py2.7 versions for R15+.



  • On 23/04/2017 at 20:25, xxxxxxxx wrote:

    Hey Niklas,

    Thanks for the reply.  Some links worked, some did not and various posts were just a bit confusing for me, being relatively new to this and somewhat cautious.

    I downloaded the numpy files you provide in the link above.  I'm on windows 10.  Heading over to your blog entry I see a reference to command-line tools.  This brings me to my first question, is the windows command line interface (or other native Win10 utility) good enough?

    STEP 1:  I'm also not quite sure what the "win64 Python distribution of Cinema 4D" is.  I do have the path C:\Program Files\MAXON\CINEMA 4D R18\resource\modules\python\Python.win64.framework\python.exe on my computer.  Is this directory "Python.win64.framework" and its contents the distribution?  If so, would the contents already contain the materials I need or is it still necessary for me to download and install the  setuptools?

    STEP 2: Poking around in the Python.win64.framework/libs/python27 directory I see 18 *.lib files.  In the Python.win64.framework/include/python2.7 directory I see 92 *.h files.  When you say to move the contents up one level, do you mean to move up the python27 and python2.7 directories up into the Python.win64.framework/libs directory or only the files (the .lib and .h files) themselves (without the respective parent directories) ?

    I'll ask step three questions tomorrow.  Thanks for breaking this down a bit for me and those who might follow.

    Thom

    ** _
    _**



  • On 24/04/2017 at 19:26, xxxxxxxx wrote:

    I'm currently stuck at step 1.  I can't execute the "call "%PY%" setup.py install" from the powershell app.  I played around with VS 2015 looking for a way to push it through but alas, I'm no programmer -- heck, I'm working on learning Python for C4D :-)

    How would a non-programmer install the setuptools??

    I'll keep scratching around but I'm all ears.

    Thom



  • On 25/04/2017 at 06:29, xxxxxxxx wrote:

    Hi Thom, sorry for the late reply.

    The Windows command-line utility is good enough. I've never used PowerShell, I use Bash from
    Git for Windows in a Cmder terminal.

    My blog post says "The packages can be installed to your Cinema 4D preferences under
    library/python/packages/{os}.". You can open the preferences folder by opening the C4D 
    preferences (Ctrl+E) and then press the "Open Preferences Folder..." at the bottom.

    You should unpack the NumPy binaries into the library/python/packages/win64 direcotry. Make sure that
    you do not include an eventually created directory, so that there exists a file win64/numpy/__init__.py.

    That should be all you need to "import numpy".

    About setuptools, you can switch to the Python.win64.framework directory that you mentioned and use
    the python.exe there. I recommend using this script (also below), but you must keep in mind that
    installing packages via Pip or easy_install will install them into Python.win64.framework and not into
    your C4D preferences folder.

    Also, when you want to use any third party modules in a Cinema 4D plugin, you should either provide
    instructions how to install the required packages or distribute them with your plugin, but that is a whole
    other story how to do it correctly.

    https://plugincafe.maxon.net/topic/8229/10727_best-practice-for-imports

    # Copyright (c) 2017 Niklas Rosenstein
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy
    # of this software and associated documentation files (the "Software"), to deal
    # in the Software without restriction, including without limitation the rights
    # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    # copies of the Software, and to permit persons to whom the Software is
    # furnished to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in
    # all copies or substantial portions of the Software.
    #
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    # THE SOFTWARE.
      
    import os
    import urllib2
    import shlex
      
    def get_pip() :
      url = 'https://bootstrap.pypa.io/get-pip.py'
      scope = {'__file__': url, '__name__': '__main__'}
      code = urllib2.urlopen(url).read()
      exec(compile(code, url, 'exec'), scope)
      
    def main() :
      try:
        import pip
      except ImportError:
        try:
          get_pip()
        except SystemExit as exc:
          if exc.code != 0: raise
        import pip
      
      while True:
        command = shlex.split(raw_input('$ pip '))
        if command == ['exit']: break
        pip.main(command)
      
    if __name__ == '__main__':
      main()
    

    Cheers,
    Niklas



  • On 25/04/2017 at 15:33, xxxxxxxx wrote:

    Progress is being made.  I think I have the numpy file in the right place now.  However, I can't seem to run your script.  I tried to run it from the Script Manager in C4D but it does not seem to like that. Was there another tool I should use to execute the script?

    How do I tell python.exe in our Python.win64.framework directory to run your script?  Doesn't it need to be running, with a kernel or something?  Sorry, I know I'm a bit dense on this.  Appreciate your patience.

    I think we are almost there. I have the Cmder tool now and see that it has three modes, is one of those what I need?

    Thom



  • On 30/04/2017 at 16:31, xxxxxxxx wrote:

    All right, I got it (pending further testing).

    I could not get the script provided by Niklas to work.  Not sure why, I tried messing with it but twas a no go.

    Instead, I manually downloaded the setup files into my Python.win64.framework directory rather than mess with the pip (pip script) approach.

    I also had to download and install the six.py files.

    Once all the packages contents were placed in the directory (not as sub-directories) I could then run the "python setup.py install" command w/admin privileges from Cmdr after navigating to the Python.win64.framework directory.  Again, all the files need to be there and you need to execute the command from there as well.

    Afterwards, I moved the python2.7 directory contents upward one level so the files were directly under the include and libs directories.  Then deleting the old python27 folders (now empty).

    Thanks and happy hunting.

    Thom



  • On 04/05/2017 at 08:07, xxxxxxxx wrote:

    Hello Thom,

    great to hear that you got it working.
    The process you describe in your last post is how I created the pre-built binaries.

    Maybe you did something not quite right when you tried to install the downloaded binaries? I've added
    some additional information and screenshots here:

    http://dlc.niklasrosenstein.com/portfolio/popular-python-c-extension-binaries-for-cinema4d/

    When I downloaded numpy-1.10.4, unpacked it and placed it into the library directory, it works fine for me.

    Cheers,
    Niklas


Log in to reply