GeoDjango GDAL_ERROR when uplading .shp - django

Try to parse a .shp in django shell:
from django.contrib.gis.gdal import DataSource
ds = DataSource('/Users/.../Downloads/Iceland.shp')
get:
GDAL_ERROR 4: Unable to open /Users/.../Downloads/Iceland.shx or /Users/.../Downloads/Iceland.SHX.
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/.../lib/python2.7/site-packages/django/contrib/gis/gdal/datasource.py", line 78, in __init__
raise GDALException('Could not open the datasource at "%s"' % ds_input)
GDALException: Could not open the datasource at "/Users/.../Downloads/Iceland.shp"
File exists, chmod is 755, .shx file is correct (tested in online services).
Then I try to test .kml file and it works
OS: Mac OS X 10.10.5

You are missing "Iceland.shx" file. It should be in the same archive as Iceland.shp. Just put it in the same directory. I've tried this files: http://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2/gis-files/iceland-shapefile and catch same error.
If it will not help, there some other options how to debug:
Check the mandatory .shx, .shp and .dbf files are in the same directory.
Check no other programs have the shapefile open (and locked).
Open the shapefile in QGIS/ArcGIS and validate geometry.
Try another shapefile

I need to add that I have the same error when I tried to run the command:
python manage.py ogrinspect /map/data/points.shp BuildingFootprints --srid=4326 --mapping --multi
And the error was generated because of a backslash before the map, so it passed when I run:
python manage.py ogrinspect map/data/points.shp BuildingFootprints --srid=4326 --mapping --multi
When I was looking for my solution I found this question, which is answered. Anyway, I wanted to post this answer for those people who came here like I do a few min ago. Maybe someone help.

python manage.py ogrinspect map/data/points.shp BuildingFootprints --srid=4326 --mapping --multi
Ensure your data is located in the folder... map/data/points.shp BuildingFootprints

Related

neovim: no module named __future__

When I try to open certain python files in neovim, I get an error:
"pool.py" 667L, 25276C
function provider#python#Call[9]..remote#host#Require[10]..provider#pythonx#Require, line 15
Vim(if):ch 1 was closed by the client
Traceback (most recent call last):
File "/home/user/.pyenv/versions/neovim2/lib/python2.7/site.py", line 67, in <module>
import os
File "./os.py", line 44, in <module>
from __future__ import absolute_import
ImportError: No module named __future__
Failed to load python host. You can try to see what happened by starting nvim with $NVIM_PYTHON_LOG_FILE set and opening the generated log file. Also
, the host stderr is available in messages.
Press ENTER or type command to continue
This happens any time I open a python file in a directory that contains an os.py or os.pyc file. It looks like neovim is trying to import the local os.py file instead of the one in the virtualenv.
What can I do about this?
EDIT: turns out it's not when I open a file in the same directory as an os.py file, it's when I open a file anywhere while the current working directory has an os.py file. Basically, it looks like python is checking the local directory for imports before checking the python libs.
I figured it out. The problem was with my $PYTHONPATH. I had in my .bashrc file this:
export PYTHONPATH="$PYTHONPATH:~/.local/lib/python"
The problem was that, when that line is executed, $PYTHONPATH is empty, leading to the string starting with a :. I'm not 100% sure why, but that resulted in python checking the local directory for a module BEFORE checking the python libraries.
I changed it to
if [ -z "$PYTHONPATH" ]; then
export PYTHONPATH="~/.local/lib/python"
else
export PYTHONPATH="$PYTHONPATH:~/.local/lib/python"
fi
And now it works.

Installing python lib pymqi for MQ

I am trying to setup python pyqmi. I installed it for python 2.7. Post this when I do "import pymqi" and run it, I see error as-
Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\pymqi.py", line 104, in
import pymqe, CMQC, CMQCFC, CMQXC
ImportError: DLL load failed: The specified module could not be found.
I checked all the directory but did not find any python file called pymqe.py. Though I see a decrypted file of same as pymqe.pyd
Can someone please help me understanding what is going wrong here?

Adding libraries to django nonrel

I've a project in Django which I'm trying to port to Django-nonrel so that I can upload it to Google app Engine. I've installed django-nonrel and other required libraries by going through the http://djangoappengine.readthedocs.org/en/latest/installation.html
namely: django-nonrel
djangoappengine
djangotoolbox
django-autoload
django-dbindexer
that is by downloading their zip files and placing them in my app directory.
So, my app directory is:
>
<app>/autoload
<app>/dbindexer
<app>/django
<app>/djangoappengine
<app>/djangotoolbox
I also have django in my project directory and have started the project by:
PYTHONPATH=. python django/bin/django-admin.py startproject \
--name=app.yaml --template=djangoappengine/conf/project_template app
If I am adding an external library with pip and adding it to the INSTALLED_APPS of my app's settings.py , it is not recognised by my django-nonrel which is pretty obvious considering the fact that django-nonrel is not installed on my system. It gives me the following error
Traceback (most recent call last):
File "/usr/local/google_appengine/google/appengine/tools/devappserver2/module.py", line 1390, in _warmup
request_type=instance.READY_REQUEST)
File "/usr/local/google_appengine/google/appengine/tools/devappserver2/module.py", line 884, in _handle_request
environ, wrapped_start_response)
File "/usr/local/google_appengine/google/appengine/tools/devappserver2/request_rewriter.py", line 314, in _rewriter_middleware
response_body = iter(application(environ, wrapped_start_response))
File "/usr/local/google_appengine/google/appengine/tools/devappserver2/module.py", line 1297, in _handle_script_request
request_type)
File "/usr/local/google_appengine/google/appengine/tools/devappserver2/module.py", line 1262, in _handle_instance_request
request_type)
File "/usr/local/google_appengine/google/appengine/tools/devappserver2/instance.py", line 371, in handle
raise CannotAcceptRequests('Instance has been quit')
CannotAcceptRequests: Instance has been quit
(nonrel)apurva#apurva-HP-ProBook-6470b:~/project/flogin$ python manage.py runserver
INFO 2015-08-11 16:06:54,606 sdk_update_checker.py:229] Checking for updates to the SDK.
INFO 2015-08-11 16:06:55,511 sdk_update_checker.py:257] The SDK is up to date.
INFO 2015-08-11 16:06:55,633 api_server.py:205] Starting API server at: http://localhost:60055
INFO 2015-08-11 16:06:55,847 dispatcher.py:197] Starting module "default" running at: http://127.0.0.1:8080
INFO 2015-08-11 16:06:55,847 admin_server.py:118] Starting admin server at: http://localhost:8000
INFO 2015-08-11 16:06:58,966 __init__.py:52] Validating models...
ERROR 2015-08-11 16:06:59,045 wsgi.py:263]
Traceback (most recent call last):
File "/usr/local/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/usr/local/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/usr/local/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject
__import__(cumulative_path)
File "/home/apurva/project/flogin/djangoappengine/main/__init__.py", line 66, in <module>
validate_models()
File "/home/apurva/project/flogin/djangoappengine/main/__init__.py", line 55, in validate_models
num_errors = get_validation_errors(s, None)
File "/home/apurva/project/flogin/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/home/apurva/project/flogin/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/home/apurva/project/flogin/django/db/models/loading.py", line 75, in _populate
self.load_app(app_name, True)
File "/home/apurva/project/flogin/django/db/models/loading.py", line 97, in load_app
app_module = import_module(app_name)
File "/home/apurva/project/flogin/django/utils/importlib.py", line 42, in import_module
__import__(name)
ImportError: No module named oauth2_provider
However, I'm unsure on how to add external libraries to my project. So that my django-nonrel recognises it. I've also tried google's documentation on how to this i.e.
Adding Third-party Packages to the Application
You can add any third-party library to your application, as long as it
is implemented in "pure Python" (no C extensions) and otherwise
functions in the App Engine runtime environment. The easiest way to
manage this is with a ./lib directory.
Create a directory named lib in your application root directory:
mkdir lib To tell your app how to find libraries in this directory,
create (or modify) a file named appengine_config.py in the root of
your project, then add these lines:
from google.appengine.ext import vendor
£ Add any libraries installed in the "lib" folder. vendor.add('lib') Use pip with the -t lib flag to install libraries in this directory:
$ pip install -t lib gcloud Note: pip version 6.0.0 or higher is
required for vendor to work properly.
Tip: the appengine_config.py above assumes that the current working
directory is where the lib folder is located. In some cases, such as
unit tests, the current working directory can be different. To avoid
errors, you can explicity pass in the full path to the lib folder
using
vendor.add(os.path.join(os.path.dirname(os.path.realpath(file)),
'lib'))
didn't work either.
So I had a very similar dilemma. Here is how I solved it:
Followed Google's instructions noted above, using pip and a ./lib directory. Make sure you have an updated version of pip:
sudo pip install --upgrade pip
Then, because of pkg_resources issues, I did this:
pip install -t lib setuptools
That was necessary, I am just not sure if that was the right place to install setuptools or not. It certainly worked, though.
Then, I launched the local development server like this, in the project directory:
PYTHONPATH=lib ./manage.py runserver
I hope that works for you!

Cannot create virtualenv in python 2.7

I'm trying to create a virtualenv with the following command:
$ virtualenv env --distribute
and I am getting the following message:
...Installing pip...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 8, in <module>
load_entry_point('virtualenv==1.8.2', 'console_scripts', 'virtualenv')()
File "/Library/Python/2.7/site-packages/virtualenv.py", line 942, in main
never_download=options.never_download)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 1054, in create_environment
install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 655, in install_pip
filter_stdout=_filter_setup)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 1020, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/nigelra/Thero...blog/venv/bin/python -x /Users/nigelra/Thero...env/bin/easy_install /Library/Python/2.7/...ort/pip-1.2.1.tar.gz failed with error code 2
I'm not particularly adept at reading OSX error messages. Would someone be willing to lend their knowledge to solve this problem?
For anyone else who gets error code 2 in the future here is how I dealt with it.
I never figured out which problem made the fix (there were a lot of problems) but I can outline the steps I took to cleaning up my computer.
I followed this guide to setting up my Python environment "right" http://docs.python-guide.org/en/latest/starting/install/osx/
I encounter a ton of errors when I did $ brew doctor
I laboriously got rid of every warning and error using google as my guide.
Many of the folder permissions had to be changed.
Eventually I was able to set up a virtualenv after a re installation of most everything.
Hope this helps anyone who encounters the same mess I did.

Django App Engine can't find antlr3 module

I'm trying to set up a Django app to run on GAE, and am using the on_production_server test to choose between dev vs. production settings in settings.py.
However, when I run
python manage.py runserver
I get:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
import settings
File "/home/guillaume/myproject/settings.py", line 10, in <module>
from djangoappengine.utils import on_production_server, have_appserver
File "/home/guillaume/myproject/djangoappengine/utils.py", line 18, in <module>
'Error was: %s' % e)
Exception: Could not get appid. Is your app.yaml file missing?
Error was: No module named antlr3
I tried adding the following to settings.py:
import sys
sys.path.append('/usr/local/google_appengine/lib/')
And this line to the very end of .profile:
PATH="$PATH:/usr/local/google_appengine/"
But neither gets rid of the error. I'm really new to working with paths so I'm kind of fumbling around blindly here. Can anyone help?
Python2.5v or 2.7v?
And what about GAE SDK version?
Did you try this?
Saw this question while having the same problem. Solved it by installing antlr 3.1.1 python runtime from Here.