SQLobject installed but IMDbPY fail - python

I tried using SQLobject from IMDbPY and Python said the driver didn't work- I'm running PostgreSQL 9.2.
C:\Users\dom\AppData\Roaming\Python\Scripts>python imdbpy2sql.py -d /imdb -u 'postgres://sid:asdf#host/imdb'
Traceback (most recent call last):
File "imdbpy2sql.py", line 501, in <module>
conn = setConnection(URI, DB_TABLES)
File "C:\Users\dom\AppData\Roaming\Python\Python27\site-packages\imdb\parser\sql\objectadapter.py", line 185, in setConnection
conn = connectionForURI(uri, **kw)
File "C:\Users\dom\AppData\Roaming\Python\Python27\site-packages\sqlobject\dbconnection.py", line 1004, in connectionForURI
connCls = self.dbConnectionForScheme(scheme)
File "C:\Users\dom\AppData\Roaming\Python\Python27\site-packages\sqlobject\dbconnection.py", line 1021, in dbConnectionForScheme
% (scheme, ', '.join(self.schemeBuilders.keys())))
AssertionError: No SQLObject driver exists for 'postgres (only sqlite, sapdb, postgresql, firebird, maxdb, rdbhost, sybase, interbase, psycopg, mysql, mssql, postgres)
I tried installing it again and activepython says it's already installed: –
C:\Users\dom\AppData\Roaming\Python\Scripts>pypm install sqlobject
skipping "sqlobject"; already installed at "%APPDATA%\Python" (2.7)
Any ideas on making imdbpy2sql.py/SQLobject work?

Use the DB URI without quotes (!).

Late, but from the imdb2py docs:
[OTHER REQUIRED MODULES]
Obviously SQLObject and SQLAlchemy can access databases only through other
specific modules/packages, that you need to have installed (e.g.:
'mysql-python' for MySQL, 'psycopg' for PostgreSQL, and so on).
Did you try installing those?

Related

How to fix 'SyntaxError: invalid syntax' when setting database section of configuration?

I followed the Docs of trytond and want to set the database of trytond the existing mysql database, but it never succeeded.
This is the another question I thought similar but not the same on stack overflow.
I got error when I execute this command
trytond -c <config_file> -d <database name> --all
I'm not sure whether the problem has relation with installing process, so the following list my installation step:
1. From the main page of tryton
2. Execute $ pip install trytond
That's all.
I added a session
[database]
uri = mysql://user:pass#localhost:3306/
And changed the default database from
self.set('database', 'uri',
os.environ.get('TRYTOND_DATABASE_URI', 'sqlite://'))
to
self.set('database', 'uri',
os.environ.get('TRYTOND_DATABASE_URI', 'mysql://user:pass#localhost:3306/'))
These lines of code are used to config the database as my understanding.
This was the result when executing.
Traceback (most recent call last):
File "/Users/chenxiangjun/anaconda3/envs/env/bin/trytond-admin", line 13, in <module>
from trytond.config import config
File "/Users/chenxiangjun/anaconda3/envs/env/lib/python3.6/site-packages/trytond/config.py", line 14
uri = mysql://user:pass#localhost:3306/
^
SyntaxError: invalid syntax
I changed the error line from
[database]
uri = mysql://user:pass#localhost:3306/
to
[database]
uri = 'mysql://user:pass#localhost:3306/'
I got this error
Traceback (most recent call last):
File "/Users/chenxiangjun/anaconda3/envs/env/bin/trytond-admin", line 13, in <module>
from trytond.config import config
File "/Users/chenxiangjun/anaconda3/envs/env/lib/python3.6/site-packages/trytond/config.py", line 13, in <module>
[database]
NameError: name 'database' is not defined
Is anyone know how to solve this problem or has the same experience?
This is the first time I setup an ERP.
The error is because you included some syntax error when modifying the python source file. You should not modify this file but set the value on your configuration file.
The configuration file is not created by default so you should create one manually. This is a text file and can be placed anywhere on your computer, just ensure that the user running trytond has enought rights to read it.
Here is a sample one for your configuration:
[database]
uri = mysql://user:pass#localhost:3306/
Once you've create this file you should execute the server with:
trytond -c
BTW: MYSQL backend is not supported since version 4.8, so if you are using a newer version you should consider using sqlite or Postgresql.

I'm trying to install skytools in order to migrate a DB to an Amazon RDS, but I'm getting an error

Setup Details:
1x EC2 running Ubuntu 14.04 with Postgres 9.3,
1x RDS running Postgres 9.3
I am trying to move a postgres database that I have on an EC2 onto an RDS. I am using Londiste, which is recommended by AWS for migrating databases with minimal downtime. Specifically, I am using Londiste/Skytools 2.1.13, because Londiste3 requires superuser privileges on both systems.
I have tried installing Skytools both via the zip from their website and via apt-get (both 2.1.13). I have installed what I believe to be all of the dependencies: postgres,libpq-dev, postgresql-server-dev-9.3, pip, and psycopg2.
Regardless, whenever I try to use any skytools commands, I get the following error:
Traceback (most recent call last):
File "/usr/local/bin/pgqadm.py", line 9, in
from pgq.ticker import SmartTicker File "/usr/local/lib/python2.7/dist-packages/pgq/init.py", line 6, in
import pgq.consumer File "/usr/local/lib/python2.7/dist-packages/pgq/consumer.py", line 6,
in
from pgq.baseconsumer import BaseConsumer, BaseBatchWalker File "/usr/local/lib/python2.7/dist-packages/pgq/baseconsumer.py", line 75,
in
class BaseConsumer(skytools.DBScript): File "/usr/local/lib/python2.7/dist-packages/skytools/apipkg.py", line 114,
in __makeattr
result = importobj(modpath, attrname) File "/usr/local/lib/python2.7/dist-packages/skytools/apipkg.py", line 37,
in importobj
module = import(modpath, None, None, ['doc']) File "/usr/local/lib/python2.7/dist-packages/skytools/scripting.py", line
23,
in
default_skylog = skytools.installer_config.skylog
AttributeError: 'module' object has no attribute 'skylog'
Am I missing a dependency? (Skylog seems to be a part of skytools, so I've concluded it's not that.) Has anyone else hit this issue? (There don't seem to be any google results with this error.) Thanks!
tl;dr:
make sure you're running pgqadm.py that is in your local skytools-2.x.y installation directory, eg: ./python/pgqadm.py ticker.ini install
This can be a problem if you have previously installed Skytools 3.x, which may come up first in your PATH.
Background
I just ran into this same issue. I have the same use case (migrating pg->rds), and followed the same recommendation from the AWS documentation.
I had initially installed Skytools 3.x before noticing that it requires superuser privileges on the would-be replica. which pgqadm.py returns /usr/bin/pgqadm.py, which is an artifact of my abandoned Skytools 3.x installation.
I became suspicious of a version conflict when I went to the Skytools source repository looking for instances of skylog. The first result was here:
https://github.com/pgq/skytools-legacy/blob/11afc5210a92d4a2ccf701e4f92138488c31a3cb/python/skytools/installer_config.py.in
However, I realized that this repository is now tracking the latest 3.x release. I switched to the apparent 2.1.x branch, and skylog was nowhere to be found, as expected:
https://github.com/pgq/skytools-legacy/blob/skytools_2_1_stable/python/skytools/installer_config.py.in
Fully-qualifying the path to pgqadm.py resolves this issue in this case.

Installing MySQL for python/Django

I'm trying to use MySQL with django and right now the following isn't executing properly:
python manage.py syncdb
I also downloaded the Mysql-python interpreter and ran the following lines but still an error:
python setup.py build
sudo python setup.py install
Traceback (most recent call last):
File "setup.py", line 15, in <module>
metadata, options = get_config()
File "/Users/user/Downloads/MySQL-python-1.2.3/setup_posix.py", line 49, in get_config
libs = mysql_config("libs")
File "/Users/user/Downloads/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: /usr/local/bin/mysql_config not found
I think it's having trouble finding mysql_config, is there a way that I can point the setup to the file? Right now my setup.py is in ~/Downloads and mysql is in /usr/local/mysql/bin
It seems you may not have any of the MySQL client applications installed. If you are using Linux (and this varies from distribution to distribution), the package you will need to install on Ubuntu is "mysql-client".
From the path you show, I'm guessing you are running on Mac OS X (you really need to state what platform you are using and what version of Python you are running). However, if you are on Mac OS X, your best bet by far is to use a complete solution of installing compatible versions of Python, MySQL client libraries, MySQLdb, and Django by using one of the third-party open source package managers on OS X: MacPorts, homebrew, Fink, or others.
See, for example, the answer here.
The answer was to edit the site.cfg file so that it points to the mysql_config file in the /usr/local/mysql dir

Error when installing mysqldb

When installing mysqldb on mac osx 10.5:
sudo ../bin/python /Users/Awais/mysqlpython/setup.py install
I get the following error:
Traceback (most recent call last):
File "/Users/Awais/mysqlpython/setup.py", line 15, in <module>
metadata, options = get_config()
File "/Users/Awais/mysqlpython/setup_posix.py", line 32, in get_config
metadata, options = get_metadata_and_options()
File "/Users/Awais/mysqlpython/setup_common.py", line 7, in get_metadata_and_options metadata = dict(config.items('metadata'))
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ConfigParser.py", line 564, in items
raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'metadata'
It seems that you are installing MySQL for Python but you have to have MySQL installed first. So, first download the MySQL installer from http://dev.mysql.com/downloads/mysql/ and install it and then try installing MySQL for Python.
I am trying port an older Linux server RH EL 5 Workstation to CentOS 6.4 64-bit. One of the two things I have had to do -- because it had been a while since I had built a Python-based MySQL server -- was make sure mysql-devel was installed, and from the menu-software install, as well as MySQL-python was installed.
The advantage to installing MySQL-python this way that the CentOS 6.4 distribution matches MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 matches the version of MySQL installed 5.1.69.
Prior to this, I tried building and installing MySQL-python with no success. In a perfect world, I would figure out why, but, like many things, I am on a deadline, and this worked, and was also recommended in posts I read both on SO and elsewhere.

Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found

I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:
DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USER = 'postgres' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
The error I get when I run python manage.py syncdb is:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 362, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 221, in execute
self.validate()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/validation.py", line 22, in get_validation_errors
from django.db import models, connection
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/__init__.py", line 41, in <module>
backend = load_backend(settings.DATABASE_ENGINE)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/__init__.py", line 17, in load_backend
return import_module('.base', 'django.db.backends.%s' % backend_name)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 22, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
Please note, I am a complete beginner in this stuff. I am originally a PHP-guy and trying out Python for a small personal project. Do I need to "turn on" Postgres?
Also, when I sudo python manage.py runserver 8080
I get this error:
Validating models...
Unhandled exception in thread started by <function inner_run at 0x1242670>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/commands/runserver.py", line 48, in inner_run
self.validate(display_num_errors=True)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/validation.py", line 22, in get_validation_errors
from django.db import models, connection
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/__init__.py", line 41, in <module>
backend = load_backend(settings.DATABASE_ENGINE)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/__init__.py", line 17, in load_backend
return import_module('.base', 'django.db.backends.%s' % backend_name)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 22, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
Please guide me. Any reply will be appreciated.
Thanks,
Wenbert!
There seems to be a problem with your psycopg2 installation – Python does not find it. This is a Python installation problem, not a Django issue.
You can try to load it manually using the Python interpreter and see if it works:
$ python
>>> import psycopg2
If you get an ImportError exception, your installation is erroneous. To get a list of all directories Python looks for modules, use sys.path:
$ python
>>> import sys
>>> print sys.path
You can also add custom directories to Python's module search path by modifying the sys.path variable. Do this somewhere before the respective import statement(s):
import sys
sys.path.append("my-path")
# ...
import psycopg2
If you have pip installed, simply install the missing extension by running:
$ pip install psycopg2
For the record I got the same error for a different reason:
I had put
'ENGINE': 'django.db.backends.postgresql'
instead of
'ENGINE': 'django.db.backends.postgresql_psycopg2'
in settings.py
Follow the steps:
Install python libraries on your OS:
python-dev
libpq-dev
Execute the command to install the psycopg2 library:
easy_install psycopg2
source: http://initd.org/psycopg/install/
I realized I didn't have psycopg2 installed
aptitude install python-psycopg2
Worked like a charm
I had this issue recently after updating homebrew on OSX.
psycopg2 was already listed in my virtualenv.
I just reinstalled psycopg2 and it worked again:
pip install --force-reinstall psycopg2
Although you installed it, Python can apparently not find the module psycopg2. This is usually due to the module not being in Python's path. See if you can find a folder named psycopg2 in /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages. If it's not there, did MacPorts tell you where it put psycopg2? If you can locate it, just move it to the site-packages directory and you should be fine.
For me, psycopg2 was indeed installed, but not into the virtualenv in which Django was running. These two steps fixed it:
sudo apt-get build-dep python-psycopg2
sudo /opt/myenv/bin/pip install psycopg2
Yes Tim's answer works for me too.It works without prefix 'django.db.backends.' also. But remember to create database or schema you mentioned in settings.py:
DATABASE_NAME = 'your_db_name'
manually using your database client so when you run 'python manage.py syncdb' you don't get the same problem. I was stuck because i didn't create it manually. I got the same problem may be because I used buildout.
I got the same error, but it was because I was using python26 ./manage.py runserver when my virtualenv only had python and python2.6 executables (thus the system python26 was being used, which didn't have psycopg2 installed
Tim's answer worked for me too.
By default, settings.py shows options like 'postgresql_psycopg2', 'mysql', etc, without a package name. Prefixing with 'django.db.backends.' worked for me (for postgresql_psycopg2, at least).
I'm on Windows and had installed psycopg2, but the 64 bit version. So my fix was to download the 32 bit one from here then in PowerShell with my virtual environment activated, my fix was:
pip uninstall psycopg2
easy_install C:\WHEREVER_I_DOWNLOADED_IT\psycopg2-2.6.1.win32-py3.4-pg9.4.4-release.exe
(The Windows Python 3.4 installer automatically installs easy_install and pip, and pip is the easiest way to remove the package, even if originally installed using easy_install.)
THIS HAS HELPED ME:
I just added PostgreSQL bin path to ENV and it was able to fine the needed dll:
C:\Program Files (x86)\PostgreSQL\9.4\bin
https://groups.google.com/forum/#!topic/robotframework-users/qLq9KvHe1wE
same here, but maybe it was missed in current project, so I navigated to the main project directory and installed it.
pip install psycopg2
and it worked
You can get this error in heroku deployment with django postgresql as backend simply add psycopg2 to your requirements.txt file
This error also occurs when you forgot to activate your virtual environment.
Using Django 3.2.9 with Python 3.9.1, after pip3 install psycopg2, this is what I had to do in order to get the initial python manage.py migrate to work:
In my Django site's settings.py file, I added these lines to the top of the file (after the from pathlib import Path line):
import sys
sys.path.append('Users/MY_USER_NAME/Sites/SITE_NAME/env/lib/python3.9/site-packages')
Sorry... a ~/Sites/... path setting doesn't work (I tried), it needs to be an absolute, full path.
My Database settings are as follows:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'DATABASE_NAME',
'USER': os.getenv('PG_USER'),
'PASSWORD': os.getenv('PG_PASS'),
'PORT': '5432',
'USE_TZ': True,
}
}
Once I added the two lines to the top of the settings.py file, the migration ran successfully :)
For the module not found errors, usually a good
pip install module_name
Will solve the problem. If it's not the case look for the binary of the module you are trying to install. Install the binary then install the module again. Example for this case the module is
psycopg2
Binary is psychopg2-binary so
Install them like this
pip install psycopg2-binary
pip install psycopg2

Categories

Resources