Using VPython in PyCharm

My physics class requires me to use VPython to create models, etc. I love the idea of ​​including code in physics and VPython seems to be pretty good overall, but VPython really wants you to use VIDLE, their IDLE version, as your IDE.

I am trying to use it in my favorite Python development environment, PyCharm . If I run a script that uses VPython modules that I know work in VIDLE, I get an error:

ImportError: No module named visual

      

I can go to the PyCharm Project Interpreter page, where it appears I can add and remove modules, but I cannot figure out how. If I click the Add / Install Package button it finds a searchable list of available packages (from the PyPi database, right?), But VPython is not listed.

It looks like VPython consists of three modules called "vis", "visual" and "visual_common" and also installs other modules "numpy" (already installed), "FontTools", "Polygon" and "ttfquery".

Any ideas? Hope it's just something simple.

+3


source to share


2 answers


Unfortunately, you cannot install vpython as easily as regular python packages. This process is much more involved. If you want to develop with PyCharm you can still.

First of all, you need to install vpython on windows. This will most likely install itself as one of your main python install site packages.

Install it here -> http://vpython.org/contents/download_windows.html



After that, just select the python installation where vpython is installed.

If you want to create a virtualenv, do it with --system-site-packages

:

 $ virtualenv --help                                                                                         [12:51:06]
Usage: virtualenv [OPTIONS] DEST_DIR

Options:
  --version             show program version number and exit
  (...)
  --no-site-packages    DEPRECATED. Retained only for backward compatibility.
                        Not having access to global site-packages is now the
                        default behavior.
  --system-site-packages
                        Give the virtual environment access to the global
                        site-packages.
  (...)

      

+2


source


Now you can start vpython running in python3.4. Follow these steps:

Training

Download the four packages TTFQuery , FontTools and Polygon , vpython at http://www.lfd.uci.edu/~gohlke/pythonlibs/ in the same directory.

Installation

  • Run cmd
  • cd path/to/package_downloaded_directory

  • pip install packagename.whl

  • Find the file C:\Python34\lib\site-packages\vis\materials.py

  • Open the file in an editor, then go to line 70
  • Comment the two lines like this:
class raw_texture(cvisual.texture):
      def __init__(self, **kwargs):
          cvisual.texture.__init__(self)
#              for key, value in kwargs.items():
#                  self.__setattr__(key, value)

      



  1. Save changes

Note that when you use vpython for your script code, the first line should look like this:

from vis import *

Below is my example code

from vis import *  
sphere(pos=vector(0,0,0),radius=0.5,color=color.red)
arrow(pos=vector(0.5,0,0),axis=vector(1,0,0),color=color.green)

      

+2


source







All Articles