Reputation: 272
I'm getting 'module' object has no attribute 'Vector3'
error in my simple python code.
This is rightAngle.py
file
import meep as mp
import math
cell = mp.Vector3(16, 8, 0)
geometry = [mp.Bloack(mp.Vector3(1e20, 1, 1e20),
center = mp.Vector3(0, 0),
material = mp.Medium(epsilon = 12))]
sources = [mp.Source(mp.ContinuousSource(frequency = 0.15),
component = mp.Ez,
center = mp.Vector3(-7, 0))]
pml_layers = [mp.PML(1.0)]
resolution = 10
Compling using:
python rightAngle.py >& rightAngle.out
And getting this output:
Traceback (most recent call last):
File "rightAngle.py", line 4, in <module>
cell = mp.Vector3(16, 8, 0)
AttributeError: 'module' object has no attribute 'Vector3'
All I'm doing is copy and pasting given code from this fairly reliable source but getting error in Vector3
object.
Python version:
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
I don't know what I'm missing?
Meep Documentation: https://meep.readthedocs.io/en/latest/Python_Tutorials/Basics/
Upvotes: 1
Views: 2766
Reputation: 51
My environment script is below but I won't go into great detail here. My plan is to create a git repository based on my current working setup and make that public on Github which will force me to organize the whole setup and make it useful for others.
The following script allows me to run Meep with python3 without Anaconda3. This way you can use the latest packages and git source to build Meep, Open MPI and supporting libraries. My home directory is replaced by
#!/bin/bash
export MPI_PROJ=/home/<USER>/projects/mpi
export MPI_BASE=/usr/local/mpi/openmpi/base
export MPI_411=$MPI_BASE/411
#
# CRITICAL ENVARS - THESE MUST BE SET AS FOLLOWS FOR THE EXISTING MEEP, MPB AND OPENMPI 4.1.1
#
export LD_LIBRARY_PATH="/usr/local/mpi/meep/latest/lib:/usr/local/mpi/openmpi/base/411/bin:/home/fraser/.local/bin:/usr/local/bin:/usr/bin:/opt/bin:/bin:/sbin:/home/fraser/projects/mpi/bin"
export CFLAGS="-I/usr/local/mpi/meep/latest/include -I/usr/local/mpi/mpb/latest/include -I/usr/include/python3.8"
export PKG_CONFIG_PATH="/usr/local/mpi/meep/latest/lib/pkgconfig:/usr/local/mpi/openmpi/base/411/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/local/mpi/meep/latest/lib/pkgconfig"
export LDFLAGS="-L/usr/local/mpi/openmpi/base/411/lib -L/usr/local/mpi/meep/latest/lib -lmpi -lmpb"
export PYTHONPATH="/home/fraser/.local/lib/python3.8/site-packages:/usr/lib/python3.8:/usr/local/mpi/meep/latest/lib/python3.8/site-packages:/usr/local/lib/python3.8/dist-packages"
export PATH=/home/fraser/projects/mpi/bin:/usr/local/mpi/meep/latest/bin:/usr/local/mpi/openmpi/base/411/bin:/home/fraser/.local/bin:/usr/local/bin:/usr/bin:/opt/bin:/bin:/sbin
Open MPI 4.1.1 was built many times first to get it right on 3 real machines and 2 virtual machines. In the end all 3 Centos 8 Stream installations ran mpi flawlessly together. Two ubuntu 21 machines (one real, one vm) were able to run mpi together flawlessly. Centos 8 machines would talk to Ubuntu 21 machines. I could not copy the mpi installation between Ubuntu 21 and Centos 8 Stream due to glibc version differences.
Then moved on to Meep which required all the libraries listed in their "Building Meep From Source" documentation page. Some were not available from Mint 20 repos and had to be built from source. Build scripts were created to run configure for each one in order to record the options used.
Meep required specific builds of harminv, fftw3, guile, swig, hdf5. Other libraries were installed from the mint 20 package repositories using apt.
Meep was also built multiple times because my envrionment was to set right to run Meep from a location other than /usr/local. It took some tinkering to get the above environment variables close enough. They may need some tweaking for your purposes.
An intermediate update - I was able to duplicate my success on Mint20 Linux on Centos 8 Stream. Will gather all the working parts into a git repo and document the little details that nobody seems to post on here on StackOverflow or even on the Github issues! For example, export PY3=1 BEFORE RUNNING AUTOGEN in the swig git clone. Otherwise it wants to use python 2!
Another issue is: Save your clone as git-meep for example. Then copy that to meep. Then work on meep. If you use configure/make/make test/make install more than 5 times or any code or environment changes don't get noticed delete the meep tree. Make sure you save any environment-setting or configure-running scripts before deleting.
Copy the git-meep to meep and run autogen.sh again before running any environment-setting scripts. Then run those then run any scripts that run configure and/or make.
My configure scripts strictly run configure. Then I run make/make check/make install by hand, in case something fails to build.
There are more strange things to do that make this work.
Will post back here when the github repository is online.
Upvotes: 0
Reputation: 11
Got the same problem while trying to use it on Ubuntu 16.04.
What worked for me was installing Anaconda for python 2.7 and create their recommended environment using:
conda create -n mp -c chogan -c defaults -c conda-forge pymeep
No Vector3 problem after that.
Upvotes: 1