Install GDAL on Python 2.7 on a Amazon Linux virtu

2020-06-28 04:48发布

I have a t2.micro Amazon Linux instance running.

Python 2.7.12 is pre-installed already. I would like to install GDAL with the Python.

I have got gcc c++ and numpy installed.

None of the following commands worked for me:

sudo yum install gdal-devel

sudo yum install gdal

sudo yum install python-gdal

They all resulted in a following message saying.

No package {PACKAGE_NAME} available.
Error: Nothing to do

I cannot run apt-get on a Amazon Linux instance.

Also none of the relevant SO posts worked for me either.

I also ran

sudo easy_install GDAL

and this gave a MemoryError as below:

Searching for GDAL
Reading https://pypi.python.org/simple/GDAL/
Best match: GDAL 2.2.1
Downloading https://pypi.python.org/packages/f2/c3/1cadfcae9a4330c3a68c41e3bc96a5d228883eec6ea3e2fc6321165b863c/GDAL-2.2.1.tar.gz#md5=4d78446b1053825a2d15b70730288b0f
Processing GDAL-2.2.1.tar.gz
Writing /tmp/easy_install-1VNr7G/GDAL-2.2.1/setup.cfg
Running GDAL-2.2.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-1VNr7G/GDAL-2.2.1/egg-dist-tmp-q1jQCi
Traceback (most recent call last):
  File "/usr/bin/easy_install", line 9, in <module>
    load_entry_point('setuptools==12.2', 'console_scripts', 'easy_install-2.7')()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 2297, in main
    distclass=DistributionWithoutHelpCommands, **kw
  File "/usr/lib64/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib64/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 393, in run
    self.easy_install(spec, not self.no_deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 642, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 672, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 857, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1085, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1071, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 240, in run_setup
    raise
  File "/usr/lib64/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 193, in setup_context
    yield
  File "/usr/lib64/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 152, in save_modules
    yield saved
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 126, in __exit__
    self._saved = UnpickleableException.dump(type, exc)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 110, in dump
    return cls.dump(cls, cls(repr(exc)))
MemoryError

3条回答
霸刀☆藐视天下
2楼-- · 2020-06-28 05:12

I followed this link on my EC2 instance (m4.large) which has Amazon Linux and python 2.7. It worked perfectly for me (I changed Gdal 2.0.0 to 2.2.0). Just make sure you have all the dependencies (ie numpy and libgdal). Let me know if you have any questions!

查看更多
太酷不给撩
3楼-- · 2020-06-28 05:13

Its in the EPEL respository. Try this:

sudo yum-config-manager --enable epel
sudo yum install gdal-python
sudo yum -y update
sudo yum -y install make automake gcc gcc-c++ libcurl-devel proj-devel geos-devel
cd /tmp
curl -L http://download.osgeo.org/gdal/2.0.0/gdal-2.0.0.tar.gz | tar zxf -
cd gdal-2.0.0/
./configure --prefix=/usr/local --with-python
make -j4
sudo make install
sudo easy_install GDAL
export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
sudo ldconfig

I was able to get this to work on a fresh t2.micro running amazon linux. The final export needs to be made permanent in bash script or the relevant place depending on your needs.

Following this I was able to from osgeo import gdal

You can make clean in the /tmp/gdal-2.0.0 folder to free up some space when done.

Warn - Build took a long time on a t2.micro

查看更多
够拽才男人
4楼-- · 2020-06-28 05:34

Nix package manager worked for me:

curl https://nixos.org/nix/install | sh
. /home/ec2-user/.nix-profile/etc/profile.d/nix.sh
nix-env -i gdal
查看更多
登录 后发表回答