I've set up a new project, and populated it with simple models. (Essentially I'm following the tut.)
When I run python manage.py shell on the command line, it works fine:
>python manage.py shell
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from mysite.myapp.models import School
>>> School.objects.all()
[]
Works great. Then, I try to do the same thing in Eclipse (using a Django project that is composed of the same files.)
Right click on mysite project >>
Django >> Shell with Django
environment
This is the output from the PyDev Console:
>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
C:\Python26\python.exe 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
>>>
>>> from django.core import management;import mysite.settings as settings;management.setup_environ(settings)
'path\\to\\mysite'
>>> from mysite.myapp.models import School
>>> School.objects.all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python26\lib\site-packages\django\db\models\query.py", line 68, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "C:\Python26\lib\site-packages\django\db\models\query.py", line 83, in __len__
self._result_cache.extend(list(self._iter))
File "C:\Python26\lib\site-packages\django\db\models\query.py", line 238, in iterator
for row in self.query.results_iter():
File "C:\Python26\lib\site-packages\django\db\models\sql\query.py", line 287, in results_iter
for rows in self.execute_sql(MULTI):
File "C:\Python26\lib\site-packages\django\db\models\sql\query.py", line 2368, in execute_sql
cursor = self.connection.cursor()
File "C:\Python26\lib\site-packages\django\db\backends\__init__.py", line 81, in cursor
cursor = self._cursor()
File "C:\Python26\lib\site-packages\django\db\backends\sqlite3\base.py", line 170, in _cursor
self.connection = Database.connect(**kwargs)
OperationalError: unable to open database file
What am I doing wrong here?
The error is about not being open the database file. So I'd guess that the path to the database in your settings.py is a relative path, and PyDev starts the shell with a different current directory than you normally use.
If this is the case, change the DATABASE_NAME setting to an absolute path and it should work.
Related
I have a python program that I want to run without the console popping up. Naturally I went for a .pyw file to hide the console. However I noticed that after converting the file to a .pyw file. It would crash immediately upon executing.
I have tried uninstalling and reinstalling python and Flask. I ran the program within the Python IDLE and was finally able to get an error readout. I then looked it up and the answer ended up being "you have to run it in py". However the file runs completely fine on my desktop but not on my laptop or any other device that I have tried when set to a .pyw. This is the error traceback:
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
=========== RESTART: C:\Users\emidd\OneDrive\Desktop\FlaskApp.pyw ===========
Traceback (most recent call last):
File "C:\Users\emidd\OneDrive\Desktop\FlaskApp.pyw", line 16, in <module>
app.run()
File "C:\Users\emidd\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 985, in run
cli.show_server_banner(self.env, self.debug, self.name, False)
File "C:\Users\emidd\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\cli.py", line 670, in show_server_banner
click.echo(message)
File "C:\Users\emidd\AppData\Local\Programs\Python\Python37\lib\site-packages\click\utils.py", line 218, in echo
file = _default_text_stdout()
File "C:\Users\emidd\AppData\Local\Programs\Python\Python37\lib\site-packages\click\_compat.py", line 675, in func
rv = wrapper_func()
File "C:\Users\emidd\AppData\Local\Programs\Python\Python37\lib\site-packages\click\_compat.py", line 436, in get_text_stdout
rv = _get_windows_console_stream(sys.stdout, encoding, errors)
File "C:\Users\emidd\AppData\Local\Programs\Python\Python37\lib\site-packages\click\_winconsole.py", line 295, in _get_windows_console_stream
func = _stream_factories.get(f.fileno())
io.UnsupportedOperation: fileno
I know that it can work because I have it running on my desktop, however I am not sure why it works on it but not my laptop. When it works, the readout on the IDLE is "running on http://127.0.0.1:5000/" if anyone could help me get this working with Pythonw that would be great. However it does technically work with normal python.
Try running it on the commandline, IDLE has different IO objects which can mess with it.
I'm having problems using NanoMsg. I was using default sockets before but then someone pointed out that this was a bad idea. So I searched to get a better package and found NanoMsg. When I tried importing I got this error:
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
================= RESTART: C:\Users\user\Desktop\Website.py =================
=============================== RESTART: Shell ===============================
>>> import nanomsg
Warning (from warnings module):
File "C:\Users\user\lib\site-packages\nanomsg_wrappers\__init__.py", line 22
"%s, performance may be affected!") % (default,))
UserWarning: Could not load the default wrapper for your platform: cpy, performance may be affected!
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import nanomsg
File "C:\Users\user\lib\site-packages\nanomsg\__init__.py", line 7, in <module>
from . import wrapper
File "C:\Users\user\lib\site-packages\nanomsg\wrapper.py", line 4, in <module>
_wrapper = _load_wrapper()
File "C:\Users\user\lib\site-packages\nanomsg_wrappers\__init__.py", line 23, in load_wrapper
return importlib.import_module('_nanomsg_ctypes')
File "C:\Users\user\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\user\lib\site-packages\_nanomsg_ctypes\__init__.py", line 10, in <module>
_lib = ctypes.windll.nanomsg
File "C:\Users\user\lib\ctypes\__init__.py", line 417, in __getattr__
dll = self._dlltype(name)
File "C:\Users\user\lib\ctypes\__init__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
>>>
Any solutions?
I have installed the new cloudera 5 manager by manual installation
wget http://archive.cloudera.com/cdh5/one-click-install/redhat/6/x86_64/cloudera-cdh-5-0.x86_64.rpm
rpm -ivh cloudera-cdh-5-0.x86_64.rpm
cd /etc/yum.repos.d/
wget http://archive.cloudera.com/cm5/redhat/6/x86_64/cm/cloudera-manager.repo
cd /usr/src
wget http://archive.cloudera.com/cm5/redhat/6/x86_64/cm/5/RPMS/x86_64/oracle-j2sdk1.7-1.7.0+update45-1.x86_64.rpm
rpm -ivh oracle-j2sdk1.7-1.7.0+update45-1.x86_64.rpm
yum -y install cloudera-manager-server cloudera-manager-server-db-2
/etc/init.d/cloudera-scm-server-db stop
/etc/init.d/cloudera-scm-server-db start
/etc/init.d/cloudera-scm-server stop
/etc/init.d/cloudera-scm-server start
I am using the python API to create the cluster...
http://cloudera.github.io/cm_api/docs/python-client/
however I am getting this error
[kshk#localhost ~]$ python
Python 2.7.5 (default, Nov 12 2013, 16:19:08)
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from cm_api.api_client import ApiResource
>>> import socket
>>> cm_host = "192.168.174.190"
>>> api = ApiResource(cm_host, username="admin", password="admin")
>>> cluster = api.create_cluster("clusterD", "CDH5")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/cm_api-6.0.1-py2.7.egg/cm_api/api_client.py", line 108, in create_cluster
return clusters.create_cluster(self, name, version)
File "/usr/lib/python2.7/site-packages/cm_api-6.0.1-py2.7.egg/cm_api/endpoints/clusters.py", line 34, in create_cluster
data=[apicluster])[0]
File "/usr/lib/python2.7/site-packages/cm_api-6.0.1-py2.7.egg/cm_api/endpoints/types.py", line 141, in call
return ApiList.from_json_dict(ret, method.im_self, ret_type)
File "/usr/lib/python2.7/site-packages/cm_api-6.0.1-py2.7.egg/cm_api/endpoints/types.py", line 419, in from_json_dict
items = [ attr.from_json(resource_root, x) for x in dic[ApiList.LIST_KEY] ]
File "/usr/lib/python2.7/site-packages/cm_api-6.0.1-py2.7.egg/cm_api/endpoints/types.py", line 97, in from_json
return self._atype.from_json_dict(data, resource_root)
File "/usr/lib/python2.7/site-packages/cm_api-6.0.1-py2.7.egg/cm_api/endpoints/types.py", line 286, in from_json_dict
obj._set_attrs(dic, allow_ro=True)
File "/usr/lib/python2.7/site-packages/cm_api-6.0.1-py2.7.egg/cm_api/endpoints/types.py", line 221, in _set_attrs
attr = self._check_attr(k, allow_ro)
File "/usr/lib/python2.7/site-packages/cm_api-6.0.1-py2.7.egg/cm_api/endpoints/types.py", line 234, in _check_attr
(name, self.__class__.__name__))
AttributeError: Invalid property fullVersion for class ApiCluster.
any ideas???
there was an issue with the python cloudera API, after four hours of this post; the API was updated and it works fine now...
I'm trying to install pyquery on Windows and I get the following error when I try to do selects like this d('p:first'). Everything else seems to be working. Any idea what am I missing? This issue happens only on my windows machine, on my MAC works fine.
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyquery import PyQuery as pq
>>> d = pq("<p></p>")
>>> d('p:first')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\pyquery-1.2.4-py2.7.egg\pyquery\pyquery.py
", line 237, in __call__
result = self.__class__(*args, parent=self, **kwargs)
File "C:\Python27\lib\site-packages\pyquery-1.2.4-py2.7.egg\pyquery\pyquery.py
", line 213, in __init__
xpath = self._css_to_xpath(selector)
File "C:\Python27\lib\site-packages\pyquery-1.2.4-py2.7.egg\pyquery\pyquery.py
", line 223, in _css_to_xpath
return self._translator.css_to_xpath(selector, prefix)
File "build\bdist.win32\egg\cssselect\xpath.py", line 188, in css_to_xpath
File "build\bdist.win32\egg\cssselect\xpath.py", line 188, in <genexpr>
File "build\bdist.win32\egg\cssselect\xpath.py", line 208, in selector_to_xpat
h
File "build\bdist.win32\egg\cssselect\xpath.py", line 230, in xpath
File "build\bdist.win32\egg\cssselect\xpath.py", line 272, in xpath_pseudo
File "C:\Python27\lib\site-packages\pyquery-1.2.4-py2.7.egg\pyquery\cssselectp
atch.py", line 19, in xpath_first_pseudo
xpath.add_post_condition('position() = 1')
AttributeError: 'XPathExpr' object has no attribute 'add_post_condition'
>>>
I had installed pyquery with "easy_install pyquery" and this was causing this error.
I removed it and then installed it from https://github.com/gawel/pyquery with python setup.py install and now it's working.
failed to run django for lack of sqlite? in fact sqlite is already install in my system.
(py1)[mirror#home ci]$ python manage.py runserver
Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x9ea3d8c>>
Traceback (most recent call last):
File "/home/mirror/build/py1/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/home/mirror/build/py1/lib/python2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/home/mirror/build/py1/lib/python2.7/site-packages/django/core/management/validation.py", line 23, in get_validation_errors
from django.db import models, connection
File "/home/mirror/build/py1/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/home/mirror/build/py1/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/mirror/build/py1/lib/python2.7/site-packages/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/mirror/build/py1/lib/python2.7/site-packages/django/db/utils.py", line 24, in load_backend
return import_module('.base', backend_name)
File "/home/mirror/build/py1/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/mirror/build/py1/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 31, in <module>
raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: **Error loading either pysqlite2 or sqlite3 modules** (tried in that order): No module named _sqlite3
the focus is that : Error loading either pysqlite2 or sqlite3 modules
evidence to show that sqlite is already installed:
(py1)[mirror#home ci]$ rpm -qa | grep sqlite
python-sqlite-1.1.7-1.2.1
sqlite-devel-3.3.6-5
sqlite-3.3.6-5
(py1)[mirror#home ci]$ python -V
Python 2.7.3
(py1)[mirror#home ci]$ python manage.py runserver
so, why python manage.py runserver failed?
Edit 1:
now i know that i haven't build sqlite modue:
(py1)[mirror#home Python-2.7.3]$ python
Python 2.7.3 (default, Sep 23 2012, 21:42:51)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/mirror/insp/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/home/mirror/insp/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
i find sqlite code is included by python source code, but how to build it?
[mirror#home Python-2.7.3]$ ls Modules/_s
_sqlite/ _sre.c _sre.o _ssl.c _struct.c
(py1)[mirror#home Python-2.7.3]$ ls Modules/_sqlite/
cache.c connection.h microprotocols.c module.h row.c statement.c util.h
cache.h cursor.c microprotocols.h prepare_protocol.c row.h statement.h
connection.c cursor.h module.c prepare_protocol.h sqlitecompat.h util.c
./configure --help | grep sqlite returns nothing....
(py1)[mirror#home Python-2.7.3]$ ./configure --help | grep sqlite
(py1)[mirror#home Python-2.7.3]$
You need to apt-get install libsqlite3-dev (on debian - sqlite-devel possibly elsewhere) and recompile python.