[library file] vpm.py problem in python 3

50 views
Skip to first unread message

Xiao Guo

unread,
Jan 25, 2018, 1:07:52 AM1/25/18
to comphys
Dear all,

when I dealing with chapter 6 to solve PDE, I face a problem in python 3.

it requires linecolor to be a vector, when I change to use string = line(x, u0, z, vp.vector(1,1,1),0.05)  to feed in, it give an following error:

AttributeError: use object methods to change its shape

I don't know how to fix it in python 3. 

Below is original code in vpm.py
class line:
    """ create a line by connecting points x[], y[], z[].
        optionally, specify line color and thickness """
    def __init__(self, x, y, z, linecolor=(1,1,1), thick = .05):
        self.line = vp.curve(color=linecolor, radius=thick)
        self.move(x, y, z)

    def move(self, x, y, z):        # update line
        self.line.pos = np.column_stack((x, y, z))


Below is the error info. : 
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-2c6b16e40197> in <module>()
----> 1 string = line(x, u0, z, vp.vector(1,1,1),0.05)

<ipython-input-8-308e4cbb654b> in __init__(self, x, y, z, linecolor, thick)
      4     def __init__(self, x, y, z, linecolor=(1,1,1), thick = .05):
      5         self.line = vp.curve(color=linecolor, radius=thick)
----> 6         self.move(x, y, z)
      7 
      8     def move(self, x, y, z):        # update line

<ipython-input-8-308e4cbb654b> in move(self, x, y, z)
      7 
      8     def move(self, x, y, z):        # update line
----> 9         self.line.pos = np.column_stack((x, y, z))

~\Anaconda3\lib\site-packages\vpython\vpython.py in pos(self, val)
   1940     @pos.setter
   1941     def pos(self,val):
-> 1942         raise AttributeError('use object methods to change its shape')
   1943 
   1944     # def __del__(self):

AttributeError: use object methods to change its shape

Anyone could help figure the problem? I'm new to python. Thanks in advance!

Jay Wang

unread,
Jan 25, 2018, 9:34:47 AM1/25/18
to comphys
It seems you were running Program_6.4_waves.py within Anaconda.
If so, you should use the Jupyter notebook version, Program_6.4_waves.ipynb.
http://www.faculty.umassd.edu/j.wang/book/prog/ch06/Program_6.4_waves.ipynb

The reason for the error is because waves.py uses classical VPython, but Anaconda
supports only Jupyter vpython.In short, do the following:
(1) Install Jupyter vpython if you have not done so: Open an Anaconda prompt, enter "pip install vpython"
(2) Download the vpynb.py library file to your program folder: http://www.faculty.umassd.edu/j.wang/book/libs/vpmnb.py
(3)  Upload Program_6.4_waves.ipynb within Jupyter, and it should work.
More info about installation and Jupyter vpython can be found here:
http://www.faculty.umassd.edu/j.wang/book/install/install.htm
http://www.faculty.umassd.edu/j.wang/book/prog/prognb.htm
Reply all
Reply to author
Forward
0 new messages