Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search

Installing numpy

Page  12>
Author
Message
  Topic Search Topic Search
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Topic: Installing numpy
    Posted: 2016 Jan 21 at 12:24pm
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)

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
Back to Top
Ilya View Drop Down
Member
Member
Avatar

Joined: 2009 Nov 04
Location: Russia
Online Status: Offline
Posts: 245
Direct Link To This Post Posted: 2016 Jan 21 at 1:09pm
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 http://www.plugincafe.com/forum/forum_posts.asp?TID=11994&PID=47477#47477




Edited by Ilya - 2016 Jan 21 at 6:44pm
(sorry for my English)
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2016 Jan 21 at 3:09pm
Hey Pim,

are you using R17 or an older version?
Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2016 Jan 22 at 12:21am
Hi Niklas, I am using R17.

Edited by pgrooff - 2016 Jan 22 at 12:22am
Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2016 Jan 22 at 12:36am
Originally posted by Ilya

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 http://www.plugincafe.com/forum/forum_posts.asp?TID=11994&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
Back to Top
Ilya View Drop Down
Member
Member
Avatar

Joined: 2009 Nov 04
Location: Russia
Online Status: Offline
Posts: 245
Direct Link To This Post Posted: 2016 Jan 22 at 1:51am
if use vs and r17 - read this - http://www.plugincafe.com/forum/forum_posts.asp?TID=11917
alternative for windows OS - mingw64 compiler, if you compile by it, *.pyd or dll of numpy contet will loaded
(sorry for my English)
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2016 Jan 22 at 3:54am
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
Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2016 Jan 22 at 7:46am
Originally posted by NiklasR

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


Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2016 Jan 22 at 8:28am
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).


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


Edited by NiklasR - 2016 Jan 22 at 8:28am
Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2016 Jan 22 at 8:34am
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.


Edited by pgrooff - 2016 Jan 22 at 8:37am
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2016 Jan 22 at 9:15am
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 pgrooff

PS I do not see 1.4.11 in the Google Drive.
localimport is on GitHub, not Google Drive. :) 


Edited by NiklasR - 2016 Jan 22 at 9:20am
Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2016 Jan 22 at 11:48am
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 
Back to Top
Ilya View Drop Down
Member
Member
Avatar

Joined: 2009 Nov 04
Location: Russia
Online Status: Offline
Posts: 245
Direct Link To This Post Posted: 2016 Jan 22 at 7:33pm
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


Edited by Ilya - 2016 Jan 22 at 7:35pm
(sorry for my English)
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2016 Jan 23 at 1:01am
@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.




Edited by NiklasR - 2016 Jan 23 at 1:01am
Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2016 Jan 23 at 10:03am
Great, I am going to try it.

Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2016 Jan 25 at 4:18am
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


Edited by pgrooff - 2016 Jan 25 at 5:06am
Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2016 Jan 25 at 5:10am
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


Edited by pgrooff - 2016 Jan 25 at 5:39am
Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2016 Jan 26 at 3:30am
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.


Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2016 Jan 26 at 4:19am
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:\temp
The I gave the command:
c:\temp\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.

Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2016 Jan 26 at 5:47am
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:\temp\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
Back to Top
Page  12>

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.109 seconds.