Python - Numpy

Python - Numpy

Anonymous
Not applicable
4,147 Views
5 Replies
Message 1 of 6

Python - Numpy

Anonymous
Not applicable

Hi All,

 

I am using pyrevit to create some plugins for revit, so I am using python not CSharp or ....

I want to import numpy package.

At first it was giving me this error that "no module named numpy". So I found out that IronPython is not compatible with CPython packages. 

In order to use numpy you have to use CPython and in order to that you need to put one line of code at the begining of your script which is:

#! python3

 

When I add this line not only it doesn't recognize numpy, but it also doesn't recognize __revit__ and .... anymore, it does recognize some other things like (math or winform or array, os and ...)

Any help would be much appreciated.

 

Thanks,

Dave

 

Accepted solutions (1)
4,148 Views
5 Replies
Replies (5)
Message 2 of 6

Kevin.Lawson.PE
Advocate
Advocate

Hi Dave,  I spent some time trying to get Numpy to work but didn't have any luck.  My understanding is that IronPython (which is based on python 2.7) was built to be compatible with the .Net framework.  Because the Revit API is based on the .Net framework you must use IronPython.  The problem with Numpy is that it dropped support for Python 2.x.   I tried to get an older version of Numpy (that still supported 2.x) to work, but after a bunch of dead ends I decided it was easier to rewrite the few Numpy functions I needed.  

 

-Kevin Lawson, PE
www.rippleengineeringsoftware.com
Revit heating and cooling load calculations in one click!
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks for the reply Klawson. One of the developers of pyrevit sent me this link yesterday, I believe it can be very helpful so I am posting it here as well (whatever the issue is, it is not working for me but maybe it will come handy for people who are trying to use numpy or ...):

https://www.notion.so/Create-Your-First-CPython-Command-b8a7718c554645d1a18454c0b363e3c9

 

0 Likes
Message 4 of 6

Anonymous
Not applicable
Accepted solution

Hi All,

 

Finally I have found a solution so I am sharing it here for people who wants to use numpy and scipy with pyrevit.

Developers of pyrevit have added a new engine to it which is CPython engine (previously it was just IronPython).

with this new feature, pyrevit is compatible with numpy and scipy, here is a link to a video showing the steps that should be taken:

https://youtu.be/PbdhVJRfca0

 

I just want to point out that it didn't work for me with executable version of python, so I uninstalled my python and downloaded the embedded version (X64 bit). Again python 3.8 didn't work for me, I changed it to 3.7 and it worked.

Well if you don't know how to setup the embedded version, have a look at the link below:

https://dev.to/fpim/setting-up-python-s-windows-embeddable-distribution-properly-1081 

After following the steps written in the above link, just make sure to check if python has been installed or not (open command promote, write python, if it shows the python and its version then its fine, if not, address the location of the python folder that you extracted, as an environment variable.)

 

I had also some issues with installing pip,

And that's it!

 

 

 

 

 

Message 5 of 6

bdschust18
Participant
Participant

Thank you for your post, but I still find this all confusing.  I am use to downloading Anaconda and calling it a day.  I have several questions, which I hope someone can help me out. 

 

1).  What is the PYTHONPATH variable suppose to be in this example, C:\python or C:\python\python37.zip.  

 

2).   If the pyRevit installation includes the CPYTHON folders (such as C:\...CPY385\python38.zip), why not just point the PYTHONPATH to C:\....pyRevit-Master\bin\engines\CPY385 or C:\....pyRevit-Master\bin\engines\CPY38\python38.zip (after extracting and renaming)

 

3) Pip still did not seem to install properly for me because I get the error " 'pip' is not recognized as an internal or external command, operable program or batch file." in the command prompt after I create the Scripts folder and type cd C:\python\Scripts, then pip install ....

 

4).  After going through this process, is pyRevit now using the Python engine located in C:\python or in C:\....pyRevit-Master\bin\engines\CPY385?

 

5).  Same question if I download and use Spyder because the Spyder folder also includes a version of Python.  How do I point Spyder to this new version of python.  Shouldn't the PROJECTPATH take care of that?

 

I am clearing missing something with all of this.  Any help would be greatly appreciated.  Thanks in advance.   

 

 

0 Likes
Message 6 of 6

bdschust18
Participant
Participant

I was able to install PIP, and then proceeded to install NumPy.  I still have the PYTHONPATH questions above, and when I run a test script  containing 

 

#! python3

 

import numpy as np

print('This is frustrating')

 

I get the error, "No module named 'numpy' ".  If I comment out the "import numpy as np", then I get the "This is frustrating" string.   

0 Likes