[DOCKER] Use OpenSeesPy regardless of OS or Python version

(motivation)

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.

About this article

What is OpenSees Py?

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.

What is Docker

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.

procedure

Things necessary

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

Prepare Dockerfile

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

  1. Python installation (version 3.8, including linux environment)
  2. Install pip
  3. Install the required packages for pypi
# 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

Prepare requirements.txt

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.

Dockern

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!

image.png

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
	]

}

Completed code

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

Use OpenSeesPy regardless of OS or Python version
Use data class for data storage of Python 3.7 or higher
Let's use the Python version of the Confluence API module.
Version upgrade of python Anaconda
Check OpenSSL version of python 2.6
[Python] Tuple version of prefecture pull-down
Proper use of Python visualization packages
pyenv-change the python version of virtualenv
Ideone> Python version: 3.5 (as of August 29, 2017)
Change the Python version of Homebrew
[Python Queue] Convenient use of Deque
[Python] Summary of how to use pandas
[Python] Use and and or when creating variables
About the virtual environment of python version 3.7
Connect a lot of Python or and and
[Python] Try pydash of the Python version of lodash
[Python2.7] Summary of how to use unittest
Non-logical operator usage of or in python
Summary of how to use Python list
[Python2.7] Summary of how to use subprocess
[Question] How to use plot_surface of python
Try the python version of emacs-org parser orgparse
[Python] How to use two types of type ()
Easy way to use Python 2.7 on Cent OS 6
Use the latest version of PyCharm on Ubuntu
Use multiple versions of python environment with pyenv
Summary of how to use MNIST in Python
A note about the python version of python virtualenv
Try the free version of Progate [Python I]
python development environment -use of pyenv and virtualenv-
Summary of studying Python to use AWS Lambda
Let's use different versions of SQLite3 from Python3!
Introduction of Python
Basics of Python ①
Basics of python ①
Python OS operation
Copy of python
PYTHON2.7 64bit version
My os (python)
Introduction of Python
"Linear regression" and "Probabilistic version of linear regression" in Python "Bayesian linear regression"
Beginners can use Python for web scraping (1) Improved version
I tried to summarize how to use matplotlib of python
Use urlparse.urljoin instead of os.path.join for Python URL joins
How to use Python Kivy ① ~ Basics of Kv Language ~
Let's use the open data of "Mamebus" in Python
A python regular expression, or a memo of a match object
[Python] Use the Face API of Microsoft Cognitive Services
Runtime version of Google App Engine / Python Standard Environment
EP 1 Know Which Version of Python You ’re Using.
Use python installed with Pyenv with Sublime REPL of Sublime Text 3
Version control of Node, Ruby and Python with anyenv
How to change python version of Notebook in Watson Studio (or Cloud Pak for Data)