When I tried to use OpenSeesPy, the environment construction method differs depending on the OS, it can not be used depending on the Python version, or even if it can be used, the VS Code interpreter does not interpret the OpenSeesPy method. I had a hard time before I started. Therefore, I thought of a way to easily build an environment regardless of them.
OpenSees is an abbreviation for Open System for Earthquake Engineering Simulation, which is an open source framework used for structural analysis of structures and ground during earthquakes. OpenSeesPy is an interpreter for using it in Python.
Docker is a tool that allows you to build the same environment in different environments by container virtualization. If you describe the construction method in a file, it will create and execute not only the OS but also the installation of the specified version of Python and other libraries with docker. With Dockern.
Docker Desktop https://www.docker.com/products/docker-desktop
VS Code https://code.visualstudio.com/
Remote Development (installed in VS Code) https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack
Docker prepares a file named Dockerfile and builds the environment based on it. This time, I prepared as follows. The main thing I'm doing is
# Dockerfile
FROM python:3.8
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN apt-get update
RUN apt-get install -y --no-install-recommends \
python3-dev \
python3-pip
ADD . /usr/src/app/
RUN pip install -r requirements.txt
CMD bash
As described in the Dockerfile, pip install -r requiremennts.txt
will install the package, so write the required package in advance. This time I want to start OpenSeesPy, so don't forget openseespy. (Well, it's no longer limited to OpenSeesPy)
# requrements.txt (example)
matplotlib==3.3.2
numpy==1.19.2
openseespy==3.2.2.5
pylint==2.6.0
Create some folders for Dockerfile and requirements.txt and put them in it.
Open it in VS Code and press the blue button at the bottom left of VS Code (see figure below). Then select "Remote-Containers: Open Folder in Container ..." and select the folder with the Dockerfile and requirements.txt to complete the environment construction!
I'd like to say that VS Code still doesn't understand the OpenSeesPy methods. After opening it, you should see a folder called .devcontainer and a file called devcontainer.json in it. Plus, add the following description and you're done!
# devcontainer.json
{
...
"settings": {
...
"python.linting.pylintArgs": ["--extension-pkg-whitelist=openseespy.opensees"] <-add to
},
"extensions": [
"ms-python.python" <-add to
]
}
I have already prepared the finished product, so I will replace it. (Cooking show style) https://github.com/kakemotokeita/openseespy-docker-vscode
Please use it if you like. I have included the ones I personally like, so please delete the ones you don't need.
Please kindly let me know if there are any mistakes or problems.
By the way, OpenSees can analyze the structure of a solid, but if you only want to analyze the vibration of a mass system, we created a package that can be used with simple settings. If you like, please use this as well. https://github.com/adc21/asva
Thank you.
Recommended Posts