I'm using os x , I tried to run the project that I installed from Github
https://github.com/cfpb/idea-box
but there is error says : ImportError: No module named comments
maybe I miss something but since I'm newbie in Django I can't figure it out
Django comments are deprecated in latest version. You can either install older django version (such as 1.5).
Or the better solution is to install comments from external repository like so:
pip install django-contrib-comments
and then change all imports like this:
from django.contrib.comments.models import Comment # old
from django_comments.models import Comment # new
Sources:
Django's docs
Another question
Related
I have an error while trying to use django-modeltranslation 0.18.3 in Django 2.2.
Here's the end of the traceback:
[...]
from django.db.models.utils import create_namedtuple_class
ImportError: cannot import name 'create_namedtuple_class' from 'django.db.models.utils' (/home/me/project/.venv/lib/python3.10/site-packages/django/db/models/utils.py)
I can't figure what's wrong with modeltranslations and with django. I recreated a clean venv, nothing works.
Their CHANGELOG does not mention it, but they started using some code relative to django >= 3 in v0.18.3. Version 0.18.2 is the last one that supports django 2.2.
It's the first time I work with django rest and Django Oauth toolkit
I'm following this tutorial
oauth2-with-django-rest-framework
But when I run python manage.py migrate I get the following error:
ImportError: Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: No module named ext.rest_framework.
What is going wrong ? is there another module I should install ?
my virtual environment contains :
certifi==2017.4.17
chardet==3.0.4
Django==1.11.2
django-extensions==1.8.1
django-oauth-toolkit==1.0.0
djangorestframework==3.6.3
idna==2.5
oauthlib==2.0.2
pytz==2017.2
requests==2.18.1
six==1.10.0
Unidecode==0.4.21
urllib3==1.21.1
It looks like oath2_provider.ext has been moved to oauth_provider.contrib. You could try installing an older version of django-oauth-toolkit, or try changing the value in DEFAULT_AUTHENTICATION_CLASSES from:
'oauth2_provider.ext.rest_framework.OAuth2Authentication',
to:
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
Note that the tutorial is a couple of years old, you might find other problems like this.
I was facing same issue. In my setting file DEFAULT_AUTHENTICATION_CLASSES was already
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
I just installed older version as #Alasdair ask. My issue resolved. thanks
I created an Odoo Module in Python using the Python library ujson.
I installed this library on my development server manually with pip install ujson.
Now I want to install the Module on my live server. Can I somehow tell the Odoo Module to install the ujson library when it is installed? So I just have to add the Module to my addons path and install it via the Odoo Web Interface?
Another reason to have this automated would be if I like to share my custom module, so others don't have to install the library manually on their server.
Any suggestions how to configure my Module that way? Or should I just include the library's directory in my module?
You should try-except the import to handle problems on odoo server start:
try:
from external_dependency import ClassA
except ImportError:
pass
And for other users of your module, extend the external_dependencies in your module manifest (v9 and less: __openerp__.py; v10+: __manifest__.py), which will prompt a warning on installation:
"external_dependencies": {
'python': ['external_dependency']
},
Big thanks goes to Ivan and his Blog
Thank you for your help, #Walid Mashal and #CZoellner, you both pointed me to the right direction.
I solved this task now with the following code added to the __init__.py of my module:
import pip
try:
import ujson
except ImportError:
print('\n There was no such module named -ujson- installed')
print('xxxxxxxxxxxxxxxx installing ujson xxxxxxxxxxxxxx')
pip.main(['install', 'ujson'])
In python file using the following command, you can install it (it works for odoo only). Eg: Here I am going to install xlsxwriter
try:
import xlsxwriter
except:
os.system("pip install xlsxwriter")
import xlsxwriter
The following is the code that is used in odoo base module report in base addons inside report.py (odoo_root_folder/addons/report/models/report.py) to install wkhtmltopdf.
from openerp.tools.misc import find_in_path
import subprocess
def _get_wkhtmltopdf_bin():
return find_in_path('wkhtmltopdf')
try:
process = subprocess.Popen([_get_wkhtmltopdf_bin(), '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except (OSError, IOError):
_logger.info('You need Wkhtmltopdf to print a pdf version of the reports.')
basically you need to find some python code that will run the library and install it and include that code in one of you .py files, and that should do it.
Wondering which restructured package most of you use in django 1.5+?
from django.contrib.markup.templatetags.markup import restructuredtext
Returns:
ImportError ...
No module named markup.templatetags.markup
https://docs.djangoproject.com/en/1.6/releases/1.5-alpha-1/#django-utils-markup
Yes the django.utils.markup was deprecated in 1.5 and removed in 1.6. The Python implementation of the reStructuredText markup lives in the docutils package. That is the implementation that Django <= 1.5 used.
The easiest way to install docutils is using pip:
pip install docutils
You can find the old django.utils.markup implementation in the 1.5.x branch on Djangos github repo:
https://github.com/django/django/blob/stable/1.5.x/django/contrib/markup/templatetags/markup.py#L76
This is an addon to the answer by #jbub:
When you have an old Django application and you want to continue using markup, follow these steps:
Delete django.contrib.markup from INSTALLED_APPS (in the file settings.py
Add a directory templatetags to your application
Copy the file markup.py from https://github.com/django/django/blob/stable/1.5.x/django/contrib/markup/templatetags/markup.py#L76 to templatetags
touch a file __init__.py in the templatetags directoy
Start over your webserver and see it working again.
Note that this procedure keeps your old application working. However, the deprecation of django.contrib.markup came for a reason: There were security concerns over possible cross-site scripting attacks using markdown. You are on your own to deal with this problem.
I'm trying to install celery with django and I'm get the following error:
from celery.task import sets
ImportError: cannot import name sets
How can I fix that?
Installing a newer version of celery might work. Or your install might not be complete.
But sets should be a part of celery.task.
Atleast, the latest docs indicate that this should be the case: http://ask.github.com/celery/reference/celery.task.sets.html
https://github.com/ask/celery/issues#issue/315
looks like an issue that has been reported.
You might be interested in these 2 pages of the #celery irc log
http://botland.oebfare.com/logger/celery/2011/3/4/2/
http://botland.oebfare.com/logger/celery/2011/3/4/3/