Installing numpy



  • On 21/01/2016 at 12:24, xxxxxxxx wrote:

    I tried installing numpy, but it does not work.
    Here is what I did:
    - I downloaded from Niklas Rosensteins website

    Python Binary packages for Cinema 4D (NumPy, Scipy, Cython)_<_h2_>_

    Google drive: numpy-1.92 and put it in folder d:/modules

    - I downloaded localimport from
    https://github.com/NiklasRosenstein/localimport
    and included it in my script

    - the rest of the script:

    def main() :
        with _localimport('d:/modules') :
            import numpy
        assert 'numpy' not in sys.modules
        
        gui.MessageDialog('Hello World!')
      
    if __name__=='__main__':
        main()
    

    - I got the following messages in the console:

    So, it seems as if numpy is found, but the dll is missing.

    Questions:
    - is a dll needed
    - if yes, how do I get (compile) the library?
    I thought that the binary from Niklas  would provide the dll?

    I am doing this in preparation for using / including the opencv library.

    -Pim



  • On 21/01/2016 at 13:09, xxxxxxxx wrote:

    Hello Pim
    if r17, I simply compile numpy v.192 with vs2013 and put numpy dir to USERDIR\library\python\packages\win64

    + forgot about such solution https://plugincafe.maxon.net/topic/9037/11994_strange-behavior-of-py-27-in-r17&PID=47477#47477



  • On 21/01/2016 at 15:09, xxxxxxxx wrote:

    Hey Pim,

    are you using R17 or an older version?



  • On 22/01/2016 at 00:21, xxxxxxxx wrote:

    Hi Niklas, I am using R17.



  • On 22/01/2016 at 00:36, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Hello Pim
    if r17, I simply compile numpy v.192 with vs2013 and put numpy dir to USERDIR\library\python\packages\win64

    + forgot about such solution https://plugincafe.maxon.net/topic/9037/11994_strange-behavior-of-py-27-in-r17&PID=47477#47477

    "I download compiled builds from http://www.lfd.uci.edu/~gohlke/pythonlibs"
    Do I have to recompile these compiled builds?

    If so, can I use vs2012 and the same setup as for cinema 4d plugins?

    -Pim



  • On 22/01/2016 at 01:51, xxxxxxxx wrote:

    if use vs and r17 - read this - https://plugincafe.maxon.net/topic/8977/11917_cinema-4d-r17-drops-c-api-legacy-support
    alternative for windows OS - mingw64 compiler, if you compile by it, *.pyd or dll of numpy contet will loaded



  • On 22/01/2016 at 03:54, xxxxxxxx wrote:

    I've compiled Py2.7 binaries that work with R17 for you yesterday. Look again in the Google Drive folder in numpy-1.10.4



  • On 22/01/2016 at 07:46, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    I've compiled Py2.7 binaries that work with R17 for you yesterday. Look again in the Google Drive folder in numpy-1.10.4

    Thanks for the R17 version.
    It is partly working (I might do something wrong) :
    Here is what I do in the script, after loading the class _localimport(object)

    def main() :
        with _localimport('d:/modules') :
            import numpy as np
        assert 'numpy' not in sys.modules
      
        print np.__version__
        print np.__git_revision__
        print (sys.version)
      
      
        x = np.array([1,2,3])
        print x
            
    if __name__=='__main__':
        main()
    

    The version (1.10.4), git version and sys.version are correctly printed.
    But the last line - print x - gives the following error message:

    -Pim



  • On 22/01/2016 at 08:28, xxxxxxxx wrote:

    Hey Pim,

    one one hand this is an limitation of doing local imports. I personally think that it's bad style, but some
    modules do some imports from functions, thus leading to a delayed import outside of the local import
    context. This is only problematic for relative imports or for imports of modules that are also in the
    local import context.

    You can actually re-use the local import context if you know your function is doing an import somewhere
    down its call hierarchy that would otherwise fail. Now there's the other hand, there is actually a bug that
    will not let you do this in localimport 1.4.10. It's fixed in 1.4.11 (that I have just added).

    See NiklasRosenstein/localimport#15.

    imp = _localimport('d:/modules') :
    with imp:
      import numpy
      
    arr = numpy.array([1, 2, 3])
    with imp:
      print(arr)
    

    Keep in mind that entering the local import context is a relatively costly  operation. Also note that it
    must not be done from a threaded context as it fuzzes with the global importer state.

    On a final note, for big extensions like numpy and libraries that pose problems as such, it might be best
    to provide the user with installation instructions and not use local import at all.

    Best,
    -Niklas



  • On 22/01/2016 at 08:34, xxxxxxxx wrote:

    Hey Niklas,

    Thanks for the explanation.
    Ok, so local import is not the best option.

    What is the best way not to use a local import?

    -Pim

    PS I do not see 1.4.11 in the Google Drive.



  • On 22/01/2016 at 09:15, xxxxxxxx wrote:

    Hey Pim,

    well the only alternative you go is to actually install the package to the Cinema 4D python package
    location in the preferences folder  Cinema 4D R17_BlablaPreferences/library/python/packages/win64/
    or update your PYTHONPATH  environment variable.

    If you're going to distribute your plugin, you'll have to tell users to download and install the numpy
    package to the preferences folder so the plugin can import it.

    Originally posted by xxxxxxxx

    PS I do not see 1.4.11 in the Google Drive.

    localimport is on GitHub, not Google Drive. :)



  • On 22/01/2016 at 11:48, xxxxxxxx wrote:

    Great, it is working now.

    And sorry, I did not read your post correctly.
    It is indeed on GitHub.

    Could you tell something on how to compile the numpy source, so it can be used by cinema 4d.
    And I know I am asking very much, but can you do something similar for the opencv library?

    -Pim



  • On 22/01/2016 at 19:33, xxxxxxxx wrote:

    Hello Niklas
    Thanks for works.

    Can i ask, are you using of craftr or build instructions at http://www.scipy.org/scipylib/building/windows.html

    Pim, take to look at main pages of py modules how to build them
    You are asking about opencv - http://docs.opencv.org/master/d5/de5/tutorial_py_setup_in_windows.html#gsc.tab=0



  • On 23/01/2016 at 01:01, xxxxxxxx wrote:

    @Pim I wrote myself a little blog entry to not forget how to compile that stuff in the future.
    See https://niklasrosenstein.com/2016/01/compile-python-c-extensions-for-cinema-4d-r17-windows/
    Maybe you can just follow the instructions for OpenCV.

    @Ilya I'm not using Craftr to compile the Python modules, just the setup.py  that is delivered with
    Python package. I wasn't able to compile SciPy on Windows the last time though.



  • On 23/01/2016 at 10:03, xxxxxxxx wrote:

    Great, I am going to try it.



  • On 25/01/2016 at 04:18, xxxxxxxx wrote:

    Some questions:
    1- do I need a python environment for the setuptools and for building?
    2- where in this process do I use visual studio?
    3- I have vs express 2012. I guess I must upgrade at least to 2013 for r17?
    4- I guess for a dll, a .h files is also needed, or some sort of file to indicate what is in the dll?

    Questions, questions, questions.
    I hope that you can help and that I can do something in return.

    -Pim



  • On 25/01/2016 at 05:10, xxxxxxxx wrote:

    Progress:

    Step 1. Install Setuptools
    I installed it using Powershell and the correct link to python:

    (Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | c:\python27\python -
    

    Looking at step 2, I now realize that cinema 4d has already a complete python environment.
    So, I have to install Setuptools, now using the cinema 4d python environment.

    I now understand better the sub steps in your blog:

    > set PY=C:\maxon\Cinema 4D R17\resources\modules\python\Python.win64.framework\python.exe
    > cd setuptools-19.4\
    > call "%PY%" setup.py install
    
    
    I change 1.1 to my own correct folder and executed it in windows cmd.
    I copied setuptools-19.6 (for me it is -6 and not -4) to the cinema python folder.
    
    
    I did step 1.2 so now the current folder is the setuptools-19.6 folder.
    I executed step 1.3 call "%PY%" setup.py install and there is goes wrong:
    The filename, directory name, or volume label syntax is incorrect.
    
    What am I doing wrong?
    -Pim
    


  • On 26/01/2016 at 03:30, xxxxxxxx wrote:

    Progress 2.

    I added python to the windows path.
    Started up cmd, went to to the folder C:\Program Files\MAXON\CINEMA 4D R17\resource\modules\python\Python.win64.framework\setuptools-19.6
    and gave the command:
    > python setup.py install

    "Finished processing dependencies for setuptools == 19.6"
    So everything seems ok.



  • On 26/01/2016 at 04:19, xxxxxxxx wrote:

    Progress 3.

    Step 2. Modify your Python include and libs folder
    The include and libs each contain a python27 subdirectory. 
    You need to move the contents of this directory one level up so they files are directly in the include/libs folder.

    Which folder should be moved one level up.
    libs to include or include to libs.

    Skip this one and I proceed to Step 3.

    Step 3. Build the Python Extension
    This example uses NumPy.  
    First, download the source code from GitHub or another mirror and unpack it. 
    After the package is built, a binary distribute will be created as a ZIP file.

    I downloaded Numpy and unzipped it to c: emp
    The I gave the command:
    c: emp\numpy-master\python setup.py install

    This gave the error message:
    RuntimeError: Running cythonize failed!

    Awaiting an answer, I go back to plan B: Install the binary.



  • On 26/01/2016 at 05:47, xxxxxxxx wrote:

    Progress 3.

    Installing the binary.
    - I downloaded pip and installed it using the get-pip.py script

    - from http://www.lfd.uci.edu/~gohlke/pythonlibs/
    I downloaded numpy-1.10.4+mkl-cp27-none-win_amd64.whl 
    Note: cp27 indicates it is for python 2.7

    Went to the folder where pip.exe is located and gave the command:
    pip install c: emp\numpy-1.10.4+mkl-cp27-none-win_amd64.whl

    Result: Successfully installed numpy-1.10.4

    - started python and said import numpy

    This gave the same result as described in this post.
    So, I need to recompile numpy.
    Back to square 1.

    -Pim


Log in to reply