I have an error about smart_text after installing django-admin-charts - django-admin

I want to have charts in the admin panel,
I installed the django-admin-charts package,
Which said add these to settings.py
INSTALLED_APPS = (
'admin_tools_stats', # this must be BEFORE 'admin_tools' and 'django.contrib.admin'
'django_nvd3',
)
But after adding it, it gives this error:
ImportError: cannot import name 'smart_text' from 'django.utils.encoding' (E: \ test1 \ venv1 \ lib \ site-packages \ django \ utils \ encoding.py)
I searched but didn't find much about smart_text!
Maybe it has a problem with Django version 4 or Python version 3.10.3?

This is because django-admin-charts needs smart_text and in django 4 smart_text is removed from the utils/encoding so the better way to resolve this issue is to add this code in your settings.py file
import django
from django.utils.encoding import smart_str
django.utils.encoding.smart_text = smart_str

I digged around a little and the problem seems to be the Django version. smart_text function is not present in the django/utils/encoding.py file. I downgraded from 4.0.2 to 3.2.13, set PyMemcacheCache as the default cache in settings.py and it works. In my case downgrading is not acceptable as Django. 3.2.13 doesn't support redis cache, but it might help you. Let's hope that django-admin-charts will add suport for Django 4.0.

I got this error when we switched from Django 2.2 to Django 4 version.
There were a library which was not upgraded. I found this out by searching the usage of "django.utils.encoding import smart_text" statement under the project scope.
The issue resolved once I upgraded the django-wkhtmltopdf library from 3.3.0 to 3.4.0.
Check for any dependent libraries and upgrade as above to fix the issue.

Related

Globally installed Phalcon PHP devtools do not work on Windows 10, Why?

I installed Phalcon PHP as described in https://docs.phalcon.io/3.4/en/webserver-wamp.
In this case the URL reads 3.4 because it applies alike for versions 4 and 5.
The WAMP server version is 3.2.6 configured with PHP 8.0.13
Everything was fine so far, so I continued installing the developer tools using composer as described in https://docs.phalcon.io/5.0/en/devtools.
Composer was installed globally and so were the developer tools, but when I type "phalcon" in the command window, the following error is shown:
C:\>phalcon
Fatal error: Uncaught Error: Class "Phalcon\Script" not found in C:\Users\Joachim\AppData\Roaming\Composer\vendor\phalcon\devtools\phalcon.php:38
Stack trace:
#0 {main}
thrown in C:\Users\Joachim\AppData\Roaming\Composer\vendor\phalcon\devtools\phalcon.php on line 38
C:\>
PSR and Phalcon extensions were successfully installed and I can see them in the WAMP Localhost page.
The Path environment variable contains the path to phalcon, composer, wamp, etc, nothing is missing as far as I can see.
Have anyone dealt with this error?
What could be the problem?
I'm a bit late answering this, but in case anyone else stumbles across it via Google the problem is that some namespaces have been altered between Phalcon4 and Phalcon5. I believe Phalcon\Config is one of those classes.
Until the devtools have been updated for Phalcon5, you'll either need to build the scaffolding manually, or copy an old Phalcon 3 or 4 project and update the namespaces.
The perils of using alpha/beta releases, unfortunately.
you didn't mention which phalcon version but since you are using php 8 the only version supporting php 8 is phalcon 5
your issue is most likely in your php.ini for the cli since wamp uses different files for apache and cli.
to fix the issue first remove the devtools package you installed globally then edit the cli php.ini in [wampDir]\bin\php\php8.0.13\php.ini and include psr and phalcon and install the devtools again using composer
you can also download the phar file here and test it in the cli
php phalcon.phar

pydrake is not available for installation anymore through google colab?

I have been using a google colab template for iterative LQR that uses the Pydrake, however, it seems like the code repository is removed and I can't reinstall it on google Colab:
try:
import pydrake
import underactuated
except ImportError:
!curl -s https://raw.githubusercontent.com/RussTedrake/underactuated/master/scripts/setup/jupyter_setup.py > jupyter_setup.py
from jupyter_setup import setup_underactuated
setup_underactuated()
# Setup matplotlib backend (to notebook, if possible, or inline).
from underactuated.jupyter import setup_matplotlib_backend
plt_is_interactive = setup_matplotlib_backend()
File "/content/jupyter_setup.py", line 1
404: Not Found
^
SyntaxError: invalid syntax
I tried clicking this link https://raw.githubusercontent.com/RussTedrake/underactuated/master/scripts/setup/jupyter_setup.py, and the page is not found... everything was working fine yesterday
Sorry. You're correct... I updated it this morning, and don't have a good deprecation policy in place on that repo, and this setup script is two versions ago. The path you want is https://raw.githubusercontent.com/RussTedrake/underactuated/master/setup/jupyter_setup.py
(remove the script from the directory). But if you look at that file, you'll see that even that is pointing to an updated setup script which you might want to point to.
This is actually all good news... we are on the path to a much better solution. You can now just pip install drake on colab (see the drake installation guide). Once I land the pip install underactuated (probably in time for my Spring offering of the class), then all of that nasty setup will be gone.

php-cs-fixer stopped working after php 7.3 update

I'm using Homebrew to manage both of them and they are up to date.
~ $ brew --version
Homebrew 1.8.4
Homebrew/homebrew-core (git revision a166; last commit 2018-12-08)
~ $ php --version
PHP 7.3.0 (cli) (built: Dec 7 2018 11:00:11) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.0, Copyright (c) 1999-2018, by Zend Technologies
~ $ php-cs-fixer --version
PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 7.2.*.
~ $ brew upgrade php-cs-fixer
Error: php-cs-fixer 2.13.1 already installed
This happens when I try to use php-cs-fixer
~ $ php-cs-fixer fix file.php
PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 7.2.*.
So, I downloaded php#7.2 and php-cs-fixer.phar to test and it works that way.
~ $ /usr/local/Cellar/php#7.2/7.2.13/bin/php /Users/aaronk/php-cs-fixer.phar fix file.php
Loaded config default from "/Users/aaronk/.php_cs".
Using cache file ".php_cs.cache".
Paths from configuration file have been overridden by paths provided as command arguments.
1) file.php
Fixed all files in 0.014 seconds, 10.000 MB memory used
~ $
So my question is, how do I get homebrew's php-cs-fixer to work?
Is homebrew doing something wrong here?
(p.s. is there a tag for php7.3)
As said by godbout, PHP-CS-Fixer does not yes support PHP 7.3. You can track the GitHub issue [Meta] PHP 7.3 support #3697, to follow the evolution of the situation. According to this issue, the following changes in PHP 7.3 still need to be adressed:
Flexible Heredoc and Nowdoc Syntaxes
list() Reference Assignment
instanceof now allows literals as the first operand, in which case the result is always false.
Allow a trailing comma in function calls
hrtime function has been added
is_countable function shall be handled as all other native functions
The current version "friendsofphp/php-cs-fixer": "^2.14" now supports php 7.3. You could upgrade it and it should work fine.
Nothing to do with Homebrew. It's php-cs-fixer itself that doesn't support PHP7.3. You would get the same issue through composer, with unmet dependencies.
The mentioned issues isn't related to the PH PC Fixer code, rather to it's features. It's clear missuse of composer.json, where are dependencies, not features.
PHP CS Fixer works fine on PHP 7.3, see this PR.
This command allows you to install it on PHP 7.3:
composer update --ignore-platform-reqs
Let me know if you came across any troubles.
To clarify - PHP CS Fixer being run under PHP 7.3 may fix code written using syntax up to PHP 7.2. But if one would run tool on code written in 7.3, eg is_null($foo, ) (trailing comma), then behavior of fixer is not stable (producing null === $foo, - still, with trailing comma), which is an issue.

Admin Interface setup impossible following neo4django manual

I am following the Neo4django manual: http://neo4django.readthedocs.org/en/latest/auth.html
and trying to setup Admin's interface. I am working under Mac OS X.
Before I started setting up this interface, I had my server running and everything worked. After I made the indicated changes, the server stopped with the error: Error: No module named contenttypes.
If I disable the contettypes line, I get the error Error: No module named admin.
In my settings.py file:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'polls',
'mysite',
'neo4django.admin',
'neo4django.contenttypes',
)
In urls.py:
from django.conf.urls import patterns, include, url
from neo4django import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
)
In admin.py:
from neo4django import admin
from .models import Person
class PersonAdmin(admin.ModelAdmin):
pass
admin.site.register(Person, PersonAdmin)
Could please someone give me correct instructions for setting up the admin's page?
I suggest you throw away the entire tutorial for the moment and install neo4django with pip install -e git+https://github.com/scholrly/neo4django/#egg=neo4django. Also check the github https://github.com/scholrly/neo4django and when installing Django, don't install the latest version but the 1.5.4 version with pip install django==1.5.4
Also, install the 1.9.4 version of neo4j and not the 2.0 version.
If for any reason you find neo4django a bit complicated or not mature enough then you can try the py2neo library (not an ORM) or neomodel (https://github.com/robinedwards/neomodel)

Project skeleton created by django-admin

So, Im learning django from djangobook.com and a bit confused about the project skeleton created by the following command.
django-admin.py startproject mysite
This creates the following tree.
mysite
- manage.py
- mysite
- init
- settings
- urls
- views
But the book says it should create the tree below:
mysite/
init.py
manage.py
settings.py
urls.py
I'm using Python 2.7.3 on Windows 7 pro 64 bit. Django version is 1.4.
The book is teaching using Django ver 1.1. I suspect the difference in project skeleton is due to the newer version of django that Im using.
So is it because of the newer version? If so, why was this change made in django?
TIA.
Right, the project layout has changed since Django 1.4.
You will get more information about the reasons on this page:
https://docs.djangoproject.com/en/1.4/releases/1.4/#updated-default-project-layout-and-manage-py
I would also recommend to do at least the official tutorial from the website which is up to date:
https://docs.djangoproject.com/en/1.4/intro/tutorial01/
They explain the project layout.

Resources