This is a test to try to connect netlogo with postgresql through python
For run this project you need to install:
-
virtualenvTo run this project you must to have install virtualenv. More information here
-
psycopg2: This python plugin help to connect python with postgresql
With pip:
pip install psycopg2
More information here
-
sbt: It's a build tool for scala, java an more. Is necessary that you have installing Java 1.8 or later. More information here
-
python extension: It's a netlogo extension to connect netlogo with python. Please follow the steps that are describe there. More information here
-
configparser It's an anaconda library. If you want to install it you could use anaconda navigator in the section environment and in the search field put something as configparser.
This applitacion can insert data in postgres through python using the python extension. I created a python configuration with multiple files achieving connect python with postgres.
-
If you are using virtualenv or an anaconda environment you first should power on the environment. Remember that that environment should be configured in python 3.
-
Please run the command
pip install -r requeriments.txt
-
Please download
python extension
and configured like the author describe. -
Please copy
database.ini.example
todatabase.ini
and put your host, database, user and password postgresql. -
Run netlogo from environment. For example, in mac you could run this command:
open /Applications/NetLogo\ 6.0.3/NetLogo\ 6.0.3.app/
- Inside in netlogo, in the command line you could run this instruction:
> conection
And you should see something like:
observer> conection
[('host', 'localhost'), ('database', 'netlogo'), ('user', 'postgres'), ('password', 'your_password_postgres')]
Conectando con postgres ...
Versión de Postgresql:
('PostgreSQL 9.4.10 on x86_64-apple-darwin, compiled by i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00), 64-bit',)
Conexion cerrada
- If you want to send an especific instruction you can change the 10 line in this project. Also I adde in
connection.py
to the functioninsert()
aCOMMIT
by default. You can change it if you preffer.
Try to change the line 10 in this project. Also you could change the connection file.
If you have ideas about how this works, I receive suggestions to better this project.
(models in the NetLogo Models Library and elsewhere which are of related interest)