Installing GDAL Python binding in Ubuntu to use as standalone module - python

I am trying to export a GeoTiff with Blender using the Blender Python API (based on Python 3), so I've decided to install GDAL on Ubuntu (14.04). What I would like is to get the module as a standalone folder that I could put in the modules directory of Blender (/home/user/.config/blender/2.73/scripts/modules).
The thing is I've run through several different problems trying to install GDAL. I've tried to install from source (for GDAL 2.0.0) here : Official PyPi Gdal
I ran sudo apt-get install libgdal-dev gdal-bin (I list it here because it may be important)
When I am in the extracted GDAL folder, using python setup.py build & python setup.py install, the library installs to /usr/local/lib/python2.7/dist-packages/osgeo. However, when I run python from command line, running from osgeo import osr returns ImportError: No module named _gdal
Following GDAL via pip , I used pip (pip install GDAL) to install the library, and the folder it went to was /usr/lib/python3/dist-packages/osgeo (using pip show ...). Again, running python3 and trying to import results in the same error. Of course, when I copy-paste each folder in the blender module directory, I get the same error in the Blender Python console.
So I decided to compile the sources using ./configure --with-python & make & make install in the source folder. I then copied the folder GDAL-x.x.x/build/lib.linux-x86_64-3.4/osgeo to the blender modules directory and got this time the error when importing : ImportError: /home/yvesu/.config/blender/2.73/scripts/modules/osgeo/_gdal.so: undefined symbol: _Py_ZeroStruct.
Trying to compile with python3 using python3 setup.py build returns the error error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
EDIT 1:
I think I've found the solution : I went to the directory swig/python (not found in a GDAL-1.11.0 folder but gdal-1.11.0 fodler, can't remember where I downloaded it from), ran python3 setup.py build & python3 setup.py install and could finally find the folder in /usr/local/lib/python3.4/dist-packages/GDAL-1.11.0-py3.4-linux-x86_64.egg/osgeo. When I put this osgeo folder oni the Blender modules directory, I was able to import osgeo in Blender. I will report if anything went wrong.
I think I've listed all my attempts at installing GDAL on Ubuntu. Can anyone point me in the right direction? Do you think it is even possible to install it as a standalone module, or do I need linked libraries through LD_LIBRARY_PATH?

Here is the solution I've found :
Download Gdal sources (v2.0.0 is the current stable release) from ftp://ftp.remotesensing.org/gdal/2.0.0/ or http://download.osgeo.org/gdal/2.0.0/ and untar
Go to the directory gdal2.0.0/swig/python
Run python3 setup.py build & python3 setup.py install
Finally find the module folder in, on Ubuntu : /usr/local/lib/python3.4/dist-packages/GDAL-2.0.0-py3.4-linux-x86_64.egg/osgeo
I can now use it in Blender (copying in the modules directory)

Related

Package installed but doesn't import package

For some odd reason no matter which package I install when I go to import it doesn't know what package I'm talking about. I am very certain this is a Visual Studio Code error but if not I am also using Linux.
When I pip install the package pyttsx3 this is what I get in the Terminal:
Collecting pyttsx3
Downloading https://files.pythonhosted.org/packages/24/4e/580726c73272344d3e74b7aaffae55ff6b6450061fbecb8cc6e112531c02/pyttsx3-2.7.tar.gz
Building wheels for collected packages: pyttsx3
Running setup.py bdist_wheel for pyttsx3 ... done
Stored in directory: /home/secretlloyd/.cache/pip/wheels/a2/8a/fe/11112aca9c89142c3a404bc67ef3393a7ad530da26639a05d4
Successfully built pyttsx3
Installing collected packages: pyttsx3
Successfully installed pyttsx3-2.7
But when I run a example I get this error:
Traceback (most recent call last):
File "/home/secretlloyd/Visual Studio Code/Python/Finished/Text Colors/finished.py", line 1, in <module>
import pyttsx3
ModuleNotFoundError: No module named 'pyttsx3'
You can use an virtual environment to install your libs. If you do that, each project will have its own scoped libs without affect your global libs.
How to use the virtual environment?
Enter the root folder of your project and then run the following commands on the bash:
$ py -m venv .env
$ source .env/Scripts/activate
After that you'll notice your bash will have a prefix like that (.env). Then you should install your libs:
(.env) $ pip install pyttsx3
In order to deactivate the virtual environment just run the following command:
(.env) $ deactivate
Setup VS Code Intellisense for Virtual Environment
If you're using VSCode you can set the correct python interpreter after setting up a virtual environment. Just follow the steps:
Open VSCode in your project
Press F1
Type: > python: select interpreter
Click on Enter path or find an existing interpreter
Click on Find
The navigate to .env > Scripts > python
3 possible cases:
The same thing happened to me when I did not notice I was using two Pythons at the same time one 2.7 and another one 3.6. Make sure to know where is your package being installed to the Python modules folder you really want to store it or in another one you did not know existed.
Your PATH might not be configured correctly, check out either if you are using Windows or Linux if your PATH variables are configured correctly. You can reset your configuration if you wish. (link= How to reload .bashrc settings without logging out and back in again?)
For some packages/libraries of Python the way of importing the library is different from the name you import it on your .py file. For example: You can install OpenCV library by [pip install OpenCV] but when importing it in a file you have to write [import cv2].
I hope you find this information helpful for your problem.

I cannot import a python submodule after successful installation of the module

I am trying to install the python submodule ANCA in my mac, for which I have run the following:
pip install git+https://github.com/acadev/anca.git
getting the following:
.
.
.
Installing collected packages: anca
Running setup.py install for anca ... done
Successfully installed anca-0.1.5
I have miniconda installed in my computer, and I have checked that the module and its files and dependencies are correctly located in /usr/local/miniconda2/lib/python2.7/site-packages/anca
When I import anca in my notebook it does not give me any error, but if I try to import a submodule it gives me the following error:
from anca import IterativeMeansAlign
ImportError: cannot import name IterativeMeansAlign
It is the same with other submodules, but all of them are apparently well installed with all their files.
I have also tried to install the package using Git:
git clone https://github.com/acadev/anca.git
sudo python setup.py install
with the same result.
Note: 'locate' is not able to locate the module anca unlike the rest of the python modules although I can see all the files in the right location. It is the first time this happens to me.
Thanks a lot for your help,
any suggestion will be very appreciated.

Python-Asurv Installation

When I try to install python-asurv using setup.py, (typing "path"\python "path"\setup.py install in the command prompt), I get the following error:
building extension "twokm" sources target build\src.win32-2.7\twokmmodule.c does not exist: Assuming twokmmodule.c was generated with "build_src --inplace" command. error: '.\\twokmmodule.c' missing`
I am on windows 7 64bit with 32bit python2.7
In the zip file that I downloaded, there is setup.py, asurv.py, asurv.pyc, two licences, a readme, and twokm.pyf and twokm.f, which I think are in fortran format (don't know anything about fortran). The README just says type python setup.py install.
I think that for the twokm.pyf and twokm.f files I need to use f2py to convert them to .py files, am I right?
How can I install python-asurv?
Make sure you have installed numpy at it is dependency of python-asurv
Do pip install numpy and then Do python setup.py install in the directory you have downloaded.

Building Healpy library - can not find cfitsio library

I am trying to build a Python library Healpy. My first try was to use pip. After typing:
>pip install --user healpy
i got result:
>checking if library 'cfitsio' is installed
>error: No such file or directory
After that i tried to build library on my own - i downloded the sources and builded cfitsio using commands:
>/.configure
>make
>make install
after doing that i got a libcfitsio.a file, pkg-config folder with .pc file and some .h files in include folder. But after typing:
> python setup.py install
i got the same error. I got the same error after building lib in Windows. Did anyone have similar problem ? I would be very greateful for any suggestions.
As mentioned in the healpy INSTALL documentation you must specify the PKG_CONFIG_PATH environment variable if you want to use external cfitsio or healpix modules:
PKG_CONFIG_PATH=/path/to/local/lib/pkgconfig
Note: adapt with your own path obtain from the cfitsio compilation process!
Then you shall be able to run the compilation of healpy...

Installing (build) matplotlib in mac osx lion

I installed pynum and scipy (on osx Lion with python 2.7), but when I tried to build matplotlib
git clone https://github.com/matplotlib/matplotlib.git
cd matplotlib
python setup.py build
python setup.py install
I've got these errors:
/System/Library/Frameworks/ApplicationServices.framework/Frameworks/ATS.framework/Headers/ATSTypes.h:242: error: declaration for parameter ‘FMFontDirectoryFilter’ but no such parameter
src/_macosx.m:5912: error: expected ‘{’ at end of input
lipo: can't open input file: /var/folders/qw/pr2f7vq91b3c3ngkxrrqplm8zkv09r/T//ccAgEklo.out (No such file or directory)
error: command 'llvm-gcc-4.2' failed with exit status 1
Could somebody please tell me what is the problem?
P.S.
At first I tried to install it in this way:
pip install -e git+https://github.com/matplotlib/matplotlib#egg=matplotlib-dev
but it does not worked for me
I always find this process more painful than it should be, but I've done it a few times now and I believe that these steps should get you set up:
Get Xcode 4.3.2, it's required for some of the later steps.
Download the latest version of python for OSX from python.org
Grab the Scipy superpack.
Uninstall any previous versions of numpy/matplotlib/scipy that you currently have. That includes doing cd /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ and moving any numpy/matplotlib/scipy directories or eggs into a temp directory.
cd ~/Downloads(or wherever you downloaded the superpack script to) and run sh install_superpack.sh. Answer no to the question are you installing from a repository cloned to this machine or you'll be confused about why the script keeps failing.
That should be it! You should now be able to boot up the python console and import numpy, scipy, matplotlib.

Categories