Psycopg2: psycopg2.connect() in Python has no result - python

I want to connect to a PostgreSQL database in python with Psycopg2, but when I run the connecting command, I get no results and no errors, and I can't get what's the problem.
Here is what I have in my terminal:
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> conn = psycopg2.connect("host=192.20.0.4 port=5432 user=mary
password=123456 dbname=reports")
It stops in this step, it doesn't go to the next line so that I can run any other commands, and doesn't print any errors or results, what should I do? what is the problem?

Related

Python logging module platform differences: OSX vs. Linux

Can anyone help me understand why python's logging module creates a StreamHandler on import, but only on some distributions? weird.. (note: happens on any python3)
On Mac
Python 3.5.6 (default, Dec 19 2019, 14:59:39)
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.8)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.getLogger().handlers
[<logging.StreamHandler object at 0x108fc2630>]
Linux:
Python 3.7.4 (default, Jan 3 2020, 19:27:19)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.getLogger().handlers
[]
>>>
I can't seem to find any explanation about this behavior difference!
EDIT:
A bit more investigation suggests that some module installed in the virtualenv is causing this behavior mismatch. I created a fresh one with the same python interpreter and no handler gets made. I'm trying to investigate which module seems to cause this.
This isn't actually a platform difference, but was a result of an installed library.
I filed the issue upstream https://github.com/stuaxo/vext/issues/63

vagrant/ansible: ImportError: No module named site

I am trying to start a vagrant vm and provision it using its ansible provisioner;
config.vm.provision "ansible" do |ansible|
ansible.limit = "all"
ansible.compatibility_mode = "2.0"
ansible.playbook = "ansible/install.yml"
end
the box is ubuntu/xenial64
Provisioning fails as follows:
==> default: Running provisioner: ansible...
default: Running ansible-playbook...
ImportError: No module named site
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
Host is Ubuntu 16.04.05 with ansible 2.7.0
I even tried to run a shell provisioner that installs python-minimal on the guest before executing ansible, but with no luck.
edit: in the mean time, on my controller:
/home/pkara/Desktop
$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>>
/home/pkara/Desktop
$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>>

Save Interactive Python (using script)

I would like to save the input and the output of a Python session when providing the input as a file.
In interactive mode, I would type a command of expressions and get their evaluation, as shown:
Python 2.7.11 (default, Mar 8 2016, 18:01:39)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> abs(3)
3
>>> abs(-3)
3
The text above is my desired output.
When I write these two expressions in p.py:
abs(3)
abs(-3)
and execute python p.py, I don't get any output, which is fine because Python runs in non-iteractive mode. If I execute python -i < p.py, I just get the output, not the input.
So, I dediced to use the script command.
However, with script, I get different results in MacOs and Linux (and none of them save what I would like).
If I execute script -q output.txt python -i <p.py on MacOs, file output.txtcontains
abs(-3)
abs(3)
Python 2.7.11 (default, Mar 8 2016, 18:01:39)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> abs(-3)
3
>>> abs(3)
3
which is the desired output but with the input of p.py preppended to it.
If I execute script -q output.txt -c "python -i <p.py" on Linux, file output.txt contains
Python 2.7.3 (default, Jun 22 2015, 19:33:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 3
>>> 3
which is far from I would like.
In brief:
How could I save a file that reproduces the interactive Python session when redirecting input to it?
Additionally,
Why do the MacOs and Linux implementations of script work so differently?

How come I cannot run satchmo_check?

I'm stuck on step 1 of test and install the data here: http://www.satchmoproject.com/docs/dev/settings.html
When I try to run the command, I get the following error:
(pyweb27)user#mint ~/Documents/workspace/python/site $ python manage.py satchmo_check
Unknown command: 'satchmo_check'
Type 'manage.py help' for usage.
I do have satchmo installed:
(pyweb27)user#mint ~/Documents/workspace/python/site $ python
Python 2.7.5+ (default, Sep 19 2013, 13:48:49)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django; import satchmo_store;
>>> satchmo_store.get_version()
'0.9.3-pre hg-2553:76b7dccafc76'
Am I doing something wrong? How can I resolve this?

libsvm on linux - how to add path

I downloaded the tar file for libsvm, navigated to the python directory and ran the make command. This words and when I run python inside that same directory,
import svm
works just fine. But not in any other directory. What can I do to make this library accessible from any where? I know it has some thing to do with copying the path some where, but not sure since I'm a newbie at linux.
what linux distro are you on? on my Ubunto I just:
$ sudo apt-get install python-libsvm
...
$ python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import svm
>>>
$ cd /tmp
$ python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import svm
>>>

Categories