AttributeError: /usr/lib/ogdi/libgdal.so: undefined symbol: GDALVersionInfo - python-2.7

I have setup the database using geodjango documentation and when I am doing
python manage.py sqlall world
I am getting this error:
OSError: /home/nishant-un/local/lib/libgdal.so: cannot open shared object file: No such file or directory
And when I
locate libgdal.so
I found it in:
/usr/lib/ogdi/libgdal.so
So I changed the GeoDjango Settings:
GDAL_LIBRARY_PATH = '/home/nishant-un/local/lib/libgdal.so'
to
GDAL_LIBRARY_PATH = '/usr/lib/ogdi/libgdal.so'
Then When I do python manage.py sqlall world again:
I get the error as:
AttributeError: /usr/lib/ogdi/libgdal.so: undefined symbol: GDALVersionInfo
Does anyone has Any idea why am I getting this error .. ?
`

Okay I got the answer, I Uncommented the two lines in the settings.py and it started working.
# GEOS_LIBRARY_PATH = '/usr/lib/libgeos_c.so.1'
# GDAL_LIBRARY_PATH = '/usr/lib/ogdi/libgdal.so'

Related

IsADirectoryError: [Errno 21] Is a directory: '/app' when deploying on Heroku

I've been having trouble deploying my Flask app on Heroku. My current problem is Heroku can't locate the files in my static folder. After trying suggestions on SO, I am now getting this error:
with open(file_dir, encoding="utf-8") as f:
IsADirectoryError: [Errno 21] Is a directory: '/app'
Here's one of the suggestions I found to help Heroku find the encouragement.txt file:
# Absolute path to the file
file_dir = os.path.dirname(os.path.abspath('encouragement.txt'))
# Absolute path to this file's root directory
parent_dir = os.path.join(file_dir, os.pardir)
app_dir = os.path.join(parent_dir, '/app')
The '/app' was added because one of the posts mentioned that Heroku had an app directory as the parent directory, so instead of 'static/encouragement.txt', it would be 'app/static/encouragement.txt'. The same error was given with and without joining '/app'.
Here's where the error came from:
#app.route("/")
def index():
# Read data from the file as str
with open(file_dir, encoding="utf-8") as f:
messages = f.read()
I tried using heroku bash command to check the file system structure and confirm the app directory but the command executed and returned blank.
My files are organized as follow:
MyProject
> static
> encouragement.txt
app.py
Not sure if it's needed, but I'm using windows. Thank you.
Update:
I tried adding index.php and composer.json as a couple tutorials suggested. They didn't work for the txt files; not sure if they helped with the other static files though. Not the best solution, but I ended up just copying and pasting all the txt content to my app.py.
I ran into this issue today after doing a bit of "clean-up" to my environment variables/configs. The issue is you're trying to open a directory itself as if it were a file, which causes the error. I recommend the answer in this article (as shown).
import os
# path to your file
file_name = r'/app/static/encouragement.txt'
print(os.path.isfile(file_name))
with open(file_name, 'r', encoding='utf-8') as f:
lines = f.readlines()
print(lines)

Python manage.py command showing ImportError

When hit the command python manage.py makemigrations,
I am getting the import error.
The error is like this
**ImportError : Module 'Backend.apps'does not contain a 'BackendConfigrest_framework'class. Choices are : 'BackendConfig'**
In your settings.py, change line where your "Backend" application is under the INSTALLED_APP variable from:
'Backend.apps.BackendConfigrest_framework'
to:
'Backend.apps.BackendConfig',
'rest_framework',

django-user-accounts : no such table: account_passwordhistory

There are a lot of django-related posts with "no such table" error but none are coming from django-user-accounts module.
I am getting this error
sqlite3.OperationalError: no such table: account_passwordhistory
, and here are the steps:
Installed django-user-accounts:
$ pip install django-user-accounts
Collecting django-user-accounts
Downloading https://files.pythonhosted.org/packages/0c/4f/40f76395324d98b7f8717aad7e08ad6f86ba2714eb956be6070e0402988c/django_user_accounts-2.0.3-py2.py3-none-any.whl (106kB)
100% |████████████████████████████████| 112kB 2.8MB/s
.
.
.
Installing collected packages: django-appconf, django-user-accounts
Successfully installed django-appconf-1.0.2 django-user-accounts-2.0.3
in settings.py added
INSTALLED_APPS = [ . . .
'django.contrib.sites',
'account' ]
SITE_ID = 1
MIDDLEWARE = [
.
.
.
'account.middleware.ExpiredPasswordMiddleware',
]
ACCOUNT_PASSWORD_USE_HISTORY = True
ACCOUNT_PASSWORD_EXPIRY = 60 # number of seconds
restarted server and ran : $ python manage.py user_password_history
I got:
Traceback (most recent call last):
File "/Users/ipozdnya/miniconda3/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params)
File "/Users/someuser/miniconda3/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: account_passwordhistory
I realize that account_passwordhistory did not get created at the time of install or some other step. $ python manage.py makemigrations states that No changes detected. Nothing in this doc tells me what to do about it: http://blog.pinaxproject.com/2016/11/22/how-configure-password-expiration-for-your-site/
Thanks
Ok, my problem was that I trusted the output of $ python manage.py makemigrations
that stated that No changes detected. However, when I did run $ python manage.py migrate, it applied a new migration for account_passwordhistory and account_passwordexpire tables just fine:
Applying account.0003_passwordexpiry_passwordhistory... OK
And the tables are in the DB.
Setting my password to expire in 1 second (python manage.py user_password_expiry my_user_name --expire 1) however did not have any effect on the site functionality, but that's a different issue.

createsuperuser invalid syntax in Django

I ran into a problem while going through my first Django tutorial.
I didn't create an initial superuser account during syncdb and I'm now trying to create it programmatically. The problem is that I'm getting an invalid syntax error when I run the command:
>>> django-admin.py createsuperuser
File "<stdin>", line 1
django-admin.py createsuperuser
^
SyntaxError: invalid syntax
I am running Django through Python tools for Visual Studio 2010.
Both 'django.contrib.auth' and 'django.contrib.admin' are enabled in settings.py.
Here is the tutorial that I'm following.
Looks like you are running the command in the django shell. You need to run this command in the command prompt/terminal instead.
Demo
(_env)k#dev:~/workspace/prj krav 48 $ ./manage.py shell
In [1]: manage.py createsuperuser
------------------------------------------------------------
File "<ipython console>", line 1
manage.py createsuperuser
^
SyntaxError: invalid syntax
Continued..
In [2]: exit()
Do you really want to exit ([y]/n)? y
(_env)k#dev:~/workspace/prj krav 48 $ ./manage.py createsuperuser
Username:

cannot install django-filebrowser app

I did exactly as it says here: http://readthedocs.org/docs/django-filebrowser/en/latest/quickstart.html#quickstart (only used easy_install instead of pip)
it seems that I get an import error when trying to connect to admin interface:
Request Method: GET
Request URL: http://localhost:8000/admin/
Django Version: 1.3
Exception Type: ImportError
Exception Value:
No module named sites
Exception Location: c:\workspace\expedeat\..\expedeat\urls.py in <module>, line 5
Python Executable: c:\Tools\Python26\python.exe
Python Version: 2.6.4
the import the exception comes from is: from filebrowser.sites import site in urls.py
Also testing filebrowser fails with this message:
Creating test database for alias 'default'...
.......F......
======================================================================
FAIL: test_directory (filebrowser.tests.settings.SettingsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "c:\Tools\Python26\lib\site-packages\django_filebrowser-3.3.0-py2.6.egg\filebrowser\tests\set
tings.py", line 29, in test_directory
self.assertEqual(os.path.exists(os.path.join(MEDIA_ROOT,DIRECTORY)), 1)
AssertionError: False != 1
----------------------------------------------------------------------
Ran 14 tests in 0.008s
FAILED (failures=1)
Destroying test database for alias 'default'...
I must be doing something wrong. Any help would be appreciated.
the sites.py module does not exist in version you are using, so the error message is correct.
the installation doc you are using is for version 3.4. The pip install is 3.3. The difference being in the urls.py
3.4
from filebrowser.sites import site
urlpatterns = patterns('',
url(r'^admin/filebrowser/', include(site.urls)),
)
3.3
urlpatterns = patterns('',
(r'^admin/filebrowser/', include('filebrowser.urls')),
)
The test fails because it's looking for a non-existing directory.
To find out what directory it's looking for, do the following:
% python ./manage.py shell
>>> from django.conf import settings
>>> import filebrowser.settings
>>> filebrowser.settings.MEDIA_ROOT
'/srv/repositories/project/media'
>>> filebrowser.settings.DIRECTORY
'uploads/'
Based on the output, you know what directory it's looking for, /srv/repositories/project/media/uploads in this example. Create the directory and you should be one step further on your way.
Using the "FILEBROWSER_" prefix, you can supply configuration for the filebrowser app.
I use the following in my settings.py :
FILEBROWSER_DIRECTORY = MEDIA_ROOT