django-scarface not working in python 2.7 - python

My OS is OSX El Capitan.
Versions:
Python 2.7.10
Django 1.9.2
Django-Scarface 3.0
After I install scarface and add it to the installed apps, it gives this error and i can't run my application.
Unhandled exception in thread started by <function wrapper at 0x1043dbe60>
Traceback (most recent call last):
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/scarface/models.py", line 7, in <module>
from scarface.platform_strategy import get_strategies
File "/Users/mcagataybarin/molocate-dev/env/lib/python2.7/site-packages/scarface/platform_strategy.py", line 38
class PlatformStrategy(metaclass=ABCMeta):
^
SyntaxError: invalid syntax
After I've search for this error, I think that reason is my python version.
Still I'm not sure, therefore I'm asking to you.
Is there any way to fix this? If the reason is really my Python version, how can i update my python version without damaging my code and everything?

The problem is related to metaclass syntax change in Python 3.x (https://docs.python.org/3/whatsnew/3.0.html?highlight=metaclass#changed-syntax), django-scarface is 3.x oriented. I solved the problem (with Python 2.7.x) changing in platform_strategy.py (Line 38) to this:
class PlatformStrategy():
__metaclass__ = ABCMeta
I submitted a pull request in github project: https://github.com/dreipol/django-scarface/pull/11

In the packaging instructions Python 2.7 is supported https://github.com/dreipol/django-scarface/blob/master/setup.py#L30.
You could run the package tests https://github.com/dreipol/django-scarface/blob/master/scarface/tests.py inside a virtualenv with Python 2.7.10 to see if they pass. If they don't then there's nothing wrong with your code. If they do pass then the problem might not be in the package itself.

Related

How to fix "NotImplementedError" when trying to run Hydrogen in Atom [duplicate]

This question already has answers here:
Jupyter Notebook with Python 3.8 - NotImplementedError
(4 answers)
Closed 3 years ago.
I am trying to run Hydrogen on Atom, but I am getting an error message that ends with "NotImplementedError" in the asyncio python lib.
I have Python3 installed on a Windows 10 machine, and I have the ipython kernel installed with jupyter.
I am getting the following error message, and I am not sure where to start to fix the problem.
Traceback (most recent call last): File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 192, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\site-packages\ipykernel_launcher.py", line 16, in app.launch_new_instance() File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\site-packages\traitlets\config\application.py", line 657, in launch_instance app.initialize(argv) File "", line 2, in initialize File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error return method(app, *args, **kwargs) File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\site-packages\ipykernel\kernelapp.py", line 469, in initialize self.init_sockets() File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\site-packages\ipykernel\kernelapp.py", line 259, in init_sockets self.init_iopub(context) File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\site-packages\ipykernel\kernelapp.py", line 267, in init_iopub self.iopub_thread = IOPubThread(self.iopub_socket, pipe=True) File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\site-packages\ipykernel\iostream.py", line 68, in init self._setup_pipe_in() File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\site-packages\ipykernel\iostream.py", line 141, in _setup_pipe_in self._pipe_in = ZMQStream(pipe_in, self.io_loop) File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\site-packages\zmq\eventloop\zmqstream.py", line 120, in init self._init_io_state() File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\site-packages\zmq\eventloop\zmqstream.py", line 541, in _init_io_state self.io_loop.add_handler(self.socket, self._handle_events, self.io_loop.READ) File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\site-packages\tornado\platform\asyncio.py", line 79, in add_handler self.asyncio_loop.add_reader( File "C:\Users\chels\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 498, in add_reader raise NotImplementedError NotImplementedError
The exception comes from Tornado invoking the asyncio event loop method add_reader which is not supported on Windows.
The Tornado documentation states the following about platforms:
Platforms: Tornado should run on any Unix-like platform, although for the best performance and scalability only Linux (with epoll) and BSD (with kqueue) are recommended for production deployment (even though Mac OS X is derived from BSD and supports kqueue, its networking performance is generally poor so it is recommended only for development use). Tornado will also run on Windows, although this configuration is not officially supported and is recommended only for development use. Without reworking Tornado IOLoop interface, it’s not possible to add a native Tornado Windows IOLoop implementation or leverage Windows’ IOCP support from frameworks like AsyncIO or Twisted.
The last sentence means that the asyncio part of Tornado does not yet work on Windows.
You can roll back to Python 3.7, or you can edit Tornado to work on 3.8.
Find the tornado / platform / asyncio.py file and add the following code:
import sys
if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
From here.
You need to add this at C:\Users\username\AppData\Local\Programs\Python\Python38\Lib\site-packages\tornado\platform
import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # python-3.8.0a4

Fabric on Python3 Errors out- ImportError: cannot import name 'isMappingType'

I got the following error when I was executing my project that calls fabfile.py. I use a simple subprocess.Popen() to call the fabric task. I am on Python 3.5.1.
File ".bootstrap/_pex/pex.py", line 367, in execute
File ".bootstrap/_pex/pex.py", line 293, in _wrap_coverage
File ".bootstrap/_pex/pex.py", line 325, in _wrap_profiling
File ".bootstrap/_pex/pex.py", line 410, in _execute
File ".bootstrap/_pex/pex.py", line 468, in execute_entry
File ".bootstrap/_pex/pex.py", line 482, in execute_pkg_resources
File ".bootstrap/pkg_resources/__init__.py", line 2297, in resolve
File "/root/.pex/install/Fabric-1.8.3-py3-none-any.whl.ce45adfdb68b47d81b8a5f6b262ce685c93dfc0b/Fabric-1.8.3-py3-none-any.whl/fabric/main.py", line 12, in <module>
from operator import isMappingType
ImportError: cannot import name 'isMappingType'
I've seen many people getting this error, and answers like fabric does not support Python3. But I think that's old news.
Right now, Fabric has Python3 compatibility (specifically, they now
support 2.7 and 3,4+)
Can anyone tell me why is that I'm facing this error even now?
You are using old version of Fabric 1.8.3,
Fabric (2+) has Python 3 compatibility (now support 2.7 and 3.4+)
Therefore, kindly upgrade to the latest version of Fabric Module, considering the upgrade documentation http://docs.fabfile.org/en/latest/upgrading.html

How can I build Pinry (Python/Django Pinterest Clone) using PyCharm?

Before I get started please excuse the complete newbie question (request for dummy steps). I recently started learning Python and the Django framework using tools like Codecademy and Pluralsight and was hoping to dig into this by running Pinry (a Pinterest clone) using PyCharm, my IDE of choice for Python and work on modifying it with what I've learned so far to see what happens. Unfortunately, I download the latest version of Pinry and when I try to run it in PyCharm on my local machine I get all sorts of errors.
Here are the steps I take:
Python, Django, PyCharm are all installed and configured.
Download a new copy of Pinry and open the directory in PyCharm
Click on Run - Edit Configuration
Click on the + button to add a new configuration and check Run browse, select the Python interpreter (with Django) and click on Fix to enable Django support for the project
In the Project - Django settings, add the Django project root, settings and manage script
Finally hit alt/option + R and runserver to get the app started
At this point I would expect the package to run but instead I get the list of errors below.
Has anyone had any success in running Pinry in PyCharm without making any code modifications? I am just not sure if these are issues with the package or if its settings in PyCharm that need to be modified to make this work. Any insights?
THANK YOU!
File "/Applications/PyCharm.app/helpers/pycharm/django_manage.py", line 23, in <module>
run_module(manage_file, None, '__main__', True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 176, in run_module
fname, loader, pkg_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/Users/hussein/Desktop/pinry-master/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 279, in execute
saved_locale = translation.get_language()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 154, in get_language
return _trans.get_language()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 52, in __getattr__
if settings.USE_I18N:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 151, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
In PyCharm "Project settings/Django" specify "settings/development.py" in "settings" field.

Python Django "ImportError: No module named hashcompat"

I'm learning python + Django by reading 《beginning django e-commerce》, after I have installed django-db-log, when running $python manage.py runserver, there is a problem.
Unhandled exception in thread started by <function wrapper at 0x02C28DB0>
Traceback (most recent call last):
File "D:\Python27\lib\site-packages\django\utils\autoreload.py", line 93, in wrapper fn(*args, **kwargs)
File "D:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 92, in inner_run self.validate(display_num_errors=True)
File "D:\Python27\lib\site-packages\django\core\management\base.py", line 308, in validate num_errors = get_validation_errors(s, app)
File "D:\Python27\lib\site-packages\django\core\management\validation.py", line 34, in get_validation_errors for (app_name, error) in get_app_errors().items():
File "D:\Python27\lib\site-packages\django\db\models\loading.py", line 166, in get_app_errors self._populate() File "D:\Python27\lib\site-packages\django\db\models\loading.py", line 75, in _populate self.load_app(app_name)
File "D:\Python27\lib\site-packages\django\db\models\loading.py", line 96, in load_app models = import_module('.models', app_name)
File "D:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module __import__(name)
File "build\bdist.win32\egg\djangodblog\models.py", line 9, in <module>
File "build\bdist.win32\egg\djangodblog\manager.py", line 23, in <module>
File "build\bdist.win32\egg\djangodblog\helpers.py", line 5, in <module>
ImportError: No module named hashcompat
You are referring to an outdated manual. Module hashcompat was removed in Django 1.6, as you can read here.
Either install an older Django version (1.5 or previous) or get a more recent textbook. You can also manually fix your code by using Python builtins as advised in the removal notice, but for a beginner can be sort of a hassle :)
I solved it using hashlib. I just added:
try:
from hashlib import sha1 as sha_constructor
except ImportError:
from django.utils.hashcompat import sha_constructor
hashcompat is already deprecated in django 1.6, it is better to use hashlib instead
If you are still following that, the django version used in the book is 1.1 and if you are using higher version of django, then try removing the djangodblog from the app list in the setting.py file. It should work.

Getting 32/64-bit architecture error in Aptana when launching Django project

Like most other Mac/MySQL users with current versions of OS X, I went through the normal issues of getting Python, MySQL and MySQLdb (MySQL-Python) playing nicely together. That has been working for some time, but I'd like to use Aptana for debugging my work Django projects and when I try running either the debugger or running a project, I'm getting the dreaded "mach-o" error.
The interesting thing is that I've configured Aptana to use the same python I'm using (confirmed with a "which python" both within and outside of Aptana), and I've confirmed that the python that's being invoked by Aptana is 32-bit as it should be (same as system terminal reports). Also, when I use the Terminal in Aptana, using the interactive python shell I'm able to successfully 'import MySQLdb'. So I'm stumped.
Under arguments I'm adding this to program arguments per instructions:
runserver 8081 --noreload
But that shouldn't affect anything AFAIK. I'm at a loss of what to do next. Here is the error that Aptana is throwing when I try to launch:
pydev debugger: starting
Validating models...
Traceback (most recent call last):
File "/Applications/Aptana Studio 3/plugins/org.python.pydev_2.6.0.2012062515/pysrc/pydevd.py", line 1392, in <module>
debugger.run(setup['file'], None, None)
File "/Applications/Aptana Studio 3/plugins/org.python.pydev_2.6.0.2012062515/pysrc/pydevd.py", line 1085, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "/Users/my/path/project/manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 67, in handle
self.run(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 78, in run
self.inner_run(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 28, in get_validation_errors
from django.db import models, connection
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 78, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 33, in load_backend
return import_module('.base', backend_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 14, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): no suitable image found. Did find:
/Library/Python/2.7/site-packages/_mysql.so: mach-o, but wrong architecture
Any ideas?
Take a look at: How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions on ways to configure Python to run in 32 bits (VERSIONER_PYTHON_PREFER_32_BIT environment variable seems a good choice).
Or maybe:
Troubles with PyDev and external libraries in OS X

Categories