How to solve error while launching scrapy shell? - python-2.7

when i executed scrapy shell 'https://scrapy.org' the following error occured, i followed the instructions from the scrapy documentation https://doc.scrapy.org/en/latest/topics/shell.html#launch-the-shell
Traceback (most recent call last):
File "/usr/local/bin/scrapy", line 11, in <module>
sys.exit(execute())
File "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py", line 150, in execute
_run_print_help(parser, _run_command, cmd, args, opts)
File "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py", line 90, in _run_print_help
func(*a, **kw)
File "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py", line 157, in _run_command
cmd.run(args, opts)
File "/usr/local/lib/python2.7/dist-packages/scrapy/commands/shell.py", line 65, in run
crawler = self.crawler_process._create_crawler(spidercls)
File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 203, in _create_crawler
return Crawler(spidercls, self.settings)
File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 55, in __init__
self.extensions = ExtensionManager.from_crawler(self)
File "/usr/local/lib/python2.7/dist-packages/scrapy/middleware.py", line 58, in from_crawler
return cls.from_settings(crawler.settings, crawler)
File "/usr/local/lib/python2.7/dist-packages/scrapy/middleware.py", line 34, in from_settings
mwcls = load_object(clspath)
File "/usr/local/lib/python2.7/dist-packages/scrapy/utils/misc.py", line 44, in load_object
mod = import_module(module)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/scrapy/extensions/memusage.py", line 16, in <module>
from scrapy.mail import MailSender
File "/usr/local/lib/python2.7/dist-packages/scrapy/mail.py", line 25, in <module>
from twisted.internet import defer, reactor, ssl
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/ssl.py", line 230, in <module>
from twisted.internet._sslverify import (
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/_sslverify.py", line 15, in <module>
from OpenSSL._util import lib as pyOpenSSLlib
ImportError: No module named _util

It's a problem in scrapy installation. Maybe this can help:
sudo pip install pyopenssl --user --upgrade

Related

pkg_resources.DistributionNotFound: Django==1.8.3 in Django 1.9

I use Django 1.9 after updating of Django 1.8, and when i type command
django-admin runserver
I got this one error:
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2749, in <module>
working_set = WorkingSet._build_master()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 446, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 459, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 628, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: Django==1.8.3
And then I try to type this one command:
django-admin.py runserver
I got this one error:
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 195, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 39, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 16, in <module>
from django.db.migrations.executor import MigrationExecutor
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 7, in <module>
from .loader import MigrationLoader
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 12, in <module>
class MigrationRecorder(object):
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 26, in MigrationRecorder
class Migration(models.Model):
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 27, in Migration
app = models.CharField(max_length=255)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1072, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 166, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I try uninstall and install Django. But i still have this errors. Hope somebody can help me with it. Thanks
You shouldn't normally use django-admin, except when you do django-admin startproject.
After you have created the project, it is easier to use manage.py to run the dev server, because it takes care of setting the path and settings module for you.
./manage.py runserver
See the docs for more information.
Maybe you used another python version? It is python 2.7 now, and it seems you don't installed django properly for python2.7. You can try
python3 manage.py runserver
for using python3 in ubuntu (it is installed by default and accessibler with python3), or try to define how to run it with another python version.

Geodjango Installation Error: the procedure could not be found

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
399, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 242,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 280,
in execute
translation.activate('en-us')
File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", lin
e 130, in activate
return _trans.activate(language)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 188, in activate
_active.value = translation(language)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 159, in _fetch
app = import_module(appname)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in im
port_module
__import__(name)
File "C:\Python27\lib\site-packages\django\contrib\admin\__init__.py", line 6,
in <module>
from django.contrib.admin.sites import AdminSite, site
File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py", line 4, in
<module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "C:\Python27\lib\site-packages\django\contrib\admin\forms.py", line 6, in
<module>
from django.contrib.auth.forms import AuthenticationForm
File "C:\Python27\lib\site-packages\django\contrib\auth\forms.py", line 17, in
<module>
from django.contrib.auth.models import User
File "C:\Python27\lib\site-packages\django\contrib\auth\models.py", line 48, i
n <module>
class Permission(models.Model):
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 96, in __n
ew__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 264, in ad
d_to_class
value.contribute_to_class(cls, name)
File "C:\Python27\lib\site-packages\django\db\models\options.py", line 124, in
contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length(
))
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 34, in __geta
ttr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 198, in __getite
m__
backend = load_backend(db['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\utils.py", line 113, in load_bac
kend
return import_module('%s.base' % backend_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in im
port_module
__import__(name)
File "C:\Python27\lib\site-packages\django\contrib\gis\db\backends\postgis\bas
e.py", line 4, in <module>
from django.contrib.gis.db.backends.postgis.introspection import PostGISIntr
ospection
File "C:\Python27\lib\site-packages\django\contrib\gis\db\backends\postgis\int
rospection.py", line 2, in <module>
from django.contrib.gis.gdal import OGRGeomType
File "C:\Python27\lib\site-packages\django\contrib\gis\gdal\__init__.py", line
41, in <module>
from django.contrib.gis.gdal.driver import Driver
File "C:\Python27\lib\site-packages\django\contrib\gis\gdal\driver.py", line 5
, in <module>
from django.contrib.gis.gdal.prototypes import ds as capi
File "C:\Python27\lib\site-packages\django\contrib\gis\gdal\prototypes\ds.py",
line 8, in <module>
from django.contrib.gis.gdal.libgdal import lgdal
File "C:\Python27\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line
47, in <module>
lgdal = CDLL(lib_path)
File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 127] The specified procedure could not be found
I tried installing my app in another laptop but it throws an error in which I haven't encounter before. What causes it? Any help?
I followed the installation guide, installed all in 32-bit version.
After running the geodjango.bat file from the installation guide the above error occurs.
Error after running the command: python manage.py runserver
Check out the answer here
OSGEO4W has upgraded to GDAL 1.11, but QGIS 2.2 not; causing the version conflict. The dll should have the same date as the GDAL exe files.
[...]
If you don't need ECW support, you could simply delete or move the dll.

Django to desktop app with pyinstaller

I'm trying to convert a django project into a desktop app.
I've downloaded the developer version of pyinstaller: github/pyinstaller/pyinstaller.
hookutils.py is modified as stated here: http://www.pyinstaller.org/ticket/754 in order for pyinstaller to find my root directory: Django root directory c:\Workspace\mysite\mysite
The project I'm trying to compile is the initial project gotten after running: django-admin.py startproject mysite, so no apps created yet.
When following the steps as described on pyinstaller (http://www.pyinstaller.org/wiki/Recipe/DjangoApplication) I get some errors when trying to run the server (
.\dist\mysite\mysite.exe runserver localhost:8080):
c:\Workspace\compiled>.\dist\mysite\mysite.exe runserver
Traceback (most recent call last):
File "<string>", line 11, in <module>
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management", line 453, in execute_from_command_line
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management", line 392, in execute
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management", line 263, in fetch_command
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management", line 109, in get_commands
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.conf", line 53, in __getattr__
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.conf", line 49, in _setup
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.conf", line 71, in _configure_logging
File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.log", line 6, in <module>
File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.views.debug", line 11, in <module>
File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.http", line 1, in <module>
File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.http.cookie", line 5, in <module>
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.six", line 84, in __get__
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.six", line 103, in _resolve
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.six", line 74, in _import_module
ImportError: No module named Cookie
If I then import Cookie in manage.py then, another error appears:
Unhandled exception in thread started by <bound method Command.inner_run of <django.core.management.commands.runserver.Command object at 0x02D86CF0>>
Traceback (most recent call last):
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management.commands.runserver", line 92, in inner_run
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management.base", line 280, in validate
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management.validation", line 35, in get_validation_errors
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.db.models.loading", line 166, in get_app_errors
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.db.models.loading", line 75, in _populate
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.db.models.loading", line 96, in load_app
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.importlib", line 35, in import_module
File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.contrib.auth.models", line 18, in <module>
File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.contrib.auth.hashers", line 8, in <module>
File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.test", line 6, in <module>
File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.test.testcases", line 35, in <module>
ImportError: cannot import name _doctest
I have tried to import doctest, but it doesn't help.
Using python 2.7.4 and django 1.5.1
Edit:
So by adding django.test and HTMLParser to the manage.py, I got it to work:
import os
import sys
import Cookie
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "OTA.settings")
from django.core.management import execute_from_command_line
import django.test
import HTMLParser
execute_from_command_line(sys.argv)
Django imports local doctest module. Maybe try import django.test?
Also from the PyInstaller docs about including additional modules:
You can give additional files on the PyInstaller command line.
You can give additional import paths on the command line.
You can edit the myscript.spec file that PyInstaller writes the first time you run
it for your script. In the spec file you can tell PyInstaller about code and data files that are unique to your script.
You can write "hook" files that inform PyInstaller of hidden imports. If you "hook" imports for a package that other users might also use, you can contribute your hook file to PyInstaller.
I also recommend py2exe, if PyInstaller won't meet Your needs.

Python 2.7 Django/MySQL issue

I was using Django with Python 2.7 on Windows 7 and I installed XAMPP and used the PHPMyAdmin MySQL included with it to create a database to use in Django, but when I went and used the "python manage.py syncdb" command, I got this error:
Traceback (most recent call last):
File "iFriends\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 443, in execute_from
_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 261, in fetch_comman
d
klass = load_command_class(app_name, subcommand)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 69, in load_command_
class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 8, in <module
>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "C:\Python27\lib\site-packages\django\core\management\sql.py", line 6, in <module>
from django.db import models
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\utils.py", line 24, in load_backend
return import_module('.base', backend_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 16, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
I have checked the host, username, password and those are correct, I really want to use Django so if anyone can help me on this, that would be great.
You need to install mysql lib for windows.
http://www.codegood.com/archives/4
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
http://www.codegood.com/archives/129
You require a dependency
easy_install mysql-python

Django MongoDB problem

my django app run with mysql, but when i try with mongodb then show thie error
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/home/abdullah/django-trunk/django/core/management/__init__.py", line 442, in execute_manager
utility.execute()
File "/home/abdullah/django-trunk/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/abdullah/django-trunk/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/abdullah/django-trunk/django/core/management/base.py", line 209, in execute
translation.activate('en-us')
File "/home/abdullah/django-trunk/django/utils/translation/__init__.py", line 106, in activate
return _trans.activate(language)
File "/home/abdullah/django-trunk/django/utils/translation/trans_real.py", line 191, in activate
_active.value = translation(language)
File "/home/abdullah/django-trunk/django/utils/translation/trans_real.py", line 180, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/abdullah/django-trunk/django/utils/translation/trans_real.py", line 157, in _fetch
app = import_module(appname)
File "/home/abdullah/django-trunk/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/abdullah/django-trunk/django/contrib/admin/__init__.py", line 3, in <module>
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "/home/abdullah/django-trunk/django/contrib/admin/helpers.py", line 2, in <module>
from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
File "/home/abdullah/django-trunk/django/contrib/admin/util.py", line 1, in <module>
from django.db import models
File "/home/abdullah/django-trunk/django/db/__init__.py", line 27, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/home/abdullah/django-trunk/django/db/utils.py", line 82, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "/usr/local/lib/python2.6/dist-packages/django_mongodb_engine-0.4.0-py2.6.egg/django_mongodb_engine/base.py", line 87, in __init__
self.ops = DatabaseOperations(self)
File "/usr/local/lib/python2.6/dist-packages/djangotoolbox-0.9.2-py2.6.egg/djangotoolbox/db/base.py", line 28, in __init__
super(NonrelDatabaseOperations, self).__init__()
TypeError: __init__() takes exactly 2 arguments (1 given)
** I have installed all necessary module installed, but when i want to runserver then show this message
I managed to fix the same error by using these packages on github:
https://github.com/django-nonrel/django-nonrel
https://github.com/django-nonrel/djangotoolbox
instead of the ones recommended on Django-Mongodb's setup page. Also, make sure to use the master branch of each, so as to not run into compatibility problems. If you're using pip, you can either pip install each of the following lines separately, or put them into your version of a requirements.txt file for your project:
git+https://github.com/django-nonrel/django-nonrel#master
git+https://github.com/django-nonrel/djangotoolbox#master
git+https://github.com/django-nonrel/mongodb-engine#master
And then run
pip install -r requirements.txt