Installing Rtree from libspacialindex to use .clip() in geopandas - python-3.x

I am attempting to install rtree on my macOS machine running python3.7.7. In the geopandas documentation, it indicates that macos installs ddo not include "binary wheels" (not sure what this means honestly) for rtree.
I followed the instructions on the website https://libspatialindex.org/#download and installed the packages using cmake. When I go to my terminal in VScode and run the command
python3 -m pip install rtree rtree is downloaded, but it fails to install yielding the error message:
ERROR: Command errored out with exit status 1:
command: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/12/k00m0tq55399_9bk2svm9zjw0000gn/T/pip-install-ebn0ioj4/rtree/setup.py'"'"'; __file__='"'"'/private/var/folders/12/k00m0tq55399_9bk2svm9zjw0000gn/T/pip-install-ebn0ioj4/rtree/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/12/k00m0tq55399_9bk2svm9zjw0000gn/T/pip-install-ebn0ioj4/rtree/pip-egg-info
cwd: /private/var/folders/12/k00m0tq55399_9bk2svm9zjw0000gn/T/pip-install-ebn0ioj4/rtree/
Complete output (15 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/12/k00m0tq55399_9bk2svm9zjw0000gn/T/pip-install-ebn0ioj4/rtree/setup.py", line 3, in <module>
import rtree
File "/private/var/folders/12/k00m0tq55399_9bk2svm9zjw0000gn/T/pip-install-ebn0ioj4/rtree/rtree/__init__.py", line 1, in <module>
from .index import Rtree
File "/private/var/folders/12/k00m0tq55399_9bk2svm9zjw0000gn/T/pip-install-ebn0ioj4/rtree/rtree/index.py", line 6, in <module>
from . import core
File "/private/var/folders/12/k00m0tq55399_9bk2svm9zjw0000gn/T/pip-install-ebn0ioj4/rtree/rtree/core.py", line 143, in <module>
rt.Error_GetLastErrorNum.restype = ctypes.c_int
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py", line 377, in __getattr__
func = self.__getitem__(name)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py", line 382, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, Error_GetLastErrorNum): symbol not found
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Steps taken to resolve:
- installed postgresql via homebrew as suggested by previous answers to similar questions
I installed the libspacialindex stuff in the same directory as my project. Is this where the problem is? Am I missing some crucial package needed for this?
Any help is greatly appreciated, let me know if you require more info.

First install spatialindex via brew, then rtree via pip:
brew install spatialindex
pip install rtree

Related

cannot import name '_jsonl' from partially initialized module 'jsonl'

I am trying to install the python jsonl module on an Ubuntu system. Tried on two different computers and get the same exact error:
pip install jsonl
Collecting jsonl
Downloading jsonl-1.6.tar.gz (9.0 kB)
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-5lw5f9ew/jsonl/setup.py'"'"'; __file__='"'"'/tmp/pip-install-5lw5f9ew/jsonl/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-5lw5f9ew/jsonl/pip-egg-info cwd: /tmp/pip-install-5lw5f9ew/jsonl/
Complete output (7 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-5lw5f9ew/jsonl/setup.py", line 5, in <module>
import jsonl
File "/tmp/pip-install-5lw5f9ew/jsonl/jsonl/__init__.py", line 19, in <module>
from jsonl import _jsonl as jsonl
ImportError: cannot import name '_jsonl' from partially initialized module 'jsonl' (most likely due to a circular import) (/tmp/pip-install-5lw5f9ew/jsonl/jsonl/__init__.py)
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Any ides on how to fix this? As the same exact error occurs on two systems, I'm thinking it's a config error on my part, but no idea on how to resolve. Thanks!
jsonl, the latest version 1.6 was released in 2014. I can install it with Python 2.7 but not with Python 3. The bottom line: it's an outdated abandoned project, forget it.
Another problem: it requires simplejson but doesn't declare it as a dependency.

Pip3 can't install "empy" for python 3.8.6 (No matching distribution found for empy)

I was trying to install empy with pip3 install empy command inside a virtual environment created with python 3.8.6 on my ubuntu 18.04 pc but got the following main error:
ERROR: Could not find a version that satisfies the requirement empy (from versions: 3.3.2, 3.3.4)
ERROR: No matching distribution found for empy
I also installed "libffi-dev" using sudo apt-get install libffi-dev to prevent the error ModuleNotFoundError: No module named '_ctypes' but still the error persists and remains unchanged.
Full error as in the terminal:
(py3venv) expert-bot#expert-nx:~/python3_ws$ pip3 install empy
Collecting empy
Using cached empy-3.3.4.tar.gz (62 kB)
Preparing metadata (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/expert-bot/python3_ws/py3venv/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-04mt1wt_/empy_f5b8490ded264bce82e92de860ffaccf/setup.py'"'"'; file__='"'"'/tmp/pip-install-04mt1wt_/empy_f5b8490ded264bce82e92de860ffaccf/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-vx6cf784
cwd: /tmp/pip-install-04mt1wt_/empy_f5b8490ded264bce82e92de860ffaccf/
Complete output (13 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/expert-bot/python3_ws/py3venv/lib/python3.8/site-packages/setuptools/__init__.py", line 18, in <module>
from setuptools.dist import Distribution
File "/home/expert-bot/python3_ws/py3venv/lib/python3.8/site-packages/_virtualenv.py", line 89, in exec_module
old(module)
File "/home/expert-bot/python3_ws/py3venv/lib/python3.8/site-packages/setuptools/dist.py", line 37, in <module>
from setuptools import windows_support
File "/home/expert-bot/python3_ws/py3venv/lib/python3.8/site-packages/setuptools/windows_support.py", line 2, in <module>
import ctypes
File "/usr/local/lib/python3.8/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/3b/95/88ed47cb7da88569a78b7d6fb9420298df7e99997810c844a924d96d3c08/empy-3.3.4.tar.gz#sha256=73ac49785b601479df4ea18a7c79bc1304a8a7c34c02b9472cf1206ae88f01b3 (from https://pypi.org/simple/empy/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Using cached empy-3.3.2.tar.gz (138 kB)
Preparing metadata (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/expert-bot/python3_ws/py3venv/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-04mt1wt_/empy_104fd15b7f9e408eb4a702d46fe5de03/setup.py'"'"'; file__='"'"'/tmp/pip-install-04mt1wt_/empy_104fd15b7f9e408eb4a702d46fe5de03/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-_fwmqok0
cwd: /tmp/pip-install-04mt1wt_/empy_104fd15b7f9e408eb4a702d46fe5de03/
Complete output (13 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/expert-bot/python3_ws/py3venv/lib/python3.8/site-packages/setuptools/__init__.py", line 18, in <module>
from setuptools.dist import Distribution
File "/home/expert-bot/python3_ws/py3venv/lib/python3.8/site-packages/_virtualenv.py", line 89, in exec_module
old(module)
File "/home/expert-bot/python3_ws/py3venv/lib/python3.8/site-packages/setuptools/dist.py", line 37, in <module>
from setuptools import windows_support
File "/home/expert-bot/python3_ws/py3venv/lib/python3.8/site-packages/setuptools/windows_support.py", line 2, in <module>
import ctypes
File "/usr/local/lib/python3.8/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
----------------------------------------
WARNING: Discarding
https://files.pythonhosted.org/packages/b7/56/72a285d257c7791616960493a04f14c05ca1bf7a83dd208485cf991563bd/empy-3.3.2.tar.gz#sha256=99f016af2770c48ab57a65df7aae251360dc69a1514c15851458a71d4ddfea9c (from https://pypi.org/simple/empy/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement empy (from versions: 3.3.2, 3.3.4)
ERROR: No matching distribution found for empy
What is the possible solution to this problem ?
It looks like your Python is missing the _ctypes module, but I think empy will install after that. I believe _ctypes (which depend on libffi) is build into Python at the time of installing Python itself. If you've installed Python yourself and then installed libffi, try reinstalling Python. It will even write in the terminal what "optional" modules it builds, and here _ctypes should be among them.
Oh and if the Python configure script has a hard time finding libffi, supply --with-system-ffi as well as adding the libffi include directory to CPPFLAGS, and the libffi lib directory to LDFLAGS and LD_LIBRARY_PATH, e.g.
export CPPFLAGS="-I/path/to/libffi/include ${CPPFLAGS}"
export LDFLAGS="-L/path/to/libffi/lib -Wl,-rpath=/path/to/libffi/lib ${LDFLAGS}"
export LD_LIBRARY_PATH="/path/to/libffi/lib:${LD_LIBRARY_PATH}"
./configure --with-system-ffi ...

Fresh install Python 3.9.0 or any other way to fix No module named '_ctypes' error

Since installing to Python 3.9.0, I am unable to install any libraries to my virtualenv. When trying to install libraries via pip for example I get:
$ pip3 install -r requirements.txt
Collecting anaconda==0.0.1.1
Using cached anaconda-0.0.1.1.tar.gz (726 bytes)
ERROR: Command errored out with exit status 1:
command: /home/jack/dev/37/env/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-01fhtisu/anaconda/setup.py'"'"'; __file__='"'"'/tmp/pip-install-01fhtisu/anaconda/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-b71dl332
cwd: /tmp/pip-install-01fhtisu/anaconda/
Complete output (11 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/jack/dev/37/env/lib/python3.9/site-packages/setuptools/__init__.py", line 23, in <module>
from setuptools.dist import Distribution
File "/home/jack/dev/37/env/lib/python3.9/site-packages/setuptools/dist.py", line 34, in <module>
from setuptools import windows_support
File "/home/jack/dev/37/env/lib/python3.9/site-packages/setuptools/windows_support.py", line 2, in <module>
import ctypes
File "/usr/local/lib/python3.9/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
I have seen in a few places that this should be fixed by installing libffi-dev then reinstalling python. Here for example: Python3: ImportError: No module named '_ctypes' when using Value from module multiprocessing
What is the best way to go about doing this? I am on Ubuntu 20.04 and running python -V outside of a virtualenv reuturns Python 3.9.0.
To prevent this happening in the future is it generally recommended to only ever install newer versions on python (or any other language) in a venv and not on the system itself?
Many thanks.

Cannot install modules using pip - it gives an error

I uninstalled Python 3.8 and then installed Python 3.9.
Now, when I try to install any module using pip:
pip install pygame
It shows this error:
ERROR: Command errored out with exit status 1:
command: 'c:\users\acer\appdata\local\programs\python\python39\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Acer\\AppData\\Local\\Temp\\pip-install-s3fy0toj\\pygame\\setup.py'"'"'; __file__='"'"'C:\\Users\\Acer\\AppData\\Local\\Temp\\pip-install-s3fy0toj\\pygame\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Acer\AppData\Local\Temp\pip-pip-egg-info-lgmfm8yh'
cwd: C:\Users\Acer\AppData\Local\Temp\pip-install-s3fy0toj\pygame\
Complete output (17 lines):
WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
Using WINDOWS configuration...
Download prebuilts to "prebuilt_downloads" and copy to "./prebuilt-x64"? [Y/n]Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Acer\AppData\Local\Temp\pip-install-s3fy0toj\pygame\setup.py", line 194, in <module>
buildconfig.config.main(AUTO_CONFIG)
File "C:\Users\Acer\AppData\Local\Temp\pip-install-s3fy0toj\pygame\buildconfig\config.py", line 210, in main
deps = CFG.main(**kwds)
File "C:\Users\Acer\AppData\Local\Temp\pip-install-s3fy0toj\pygame\buildconfig\config_win.py", line 576, in main
and download_win_prebuilt.ask(**download_kwargs):
File "C:\Users\Acer\AppData\Local\Temp\pip-install-s3fy0toj\pygame\buildconfig\download_win_prebuilt.py", line 302, in ask
reply = raw_input(
EOFError: EOF when reading a line
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
I tried uninstalling and installing Python again, but still no luck. I had no problem like this when I was using Python 3.8
When I tried installing Django, it worked but then I tried installing Pandas and it did not work.
Please help.
I think there are some compatibility issues with python3.9.
For more information,you can check this link.
https://github.com/pygame/pygame/issues/2145

ERROR: Command errored out with exit status 1 with sudo pip3.8 install websocket,

like i put on the title when i put pip install websockets to install on a rasberry pi, like said on this website https://pypi.org/project/websockets/ it puts this error
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting websocket
Using cached https://www.piwheels.org/simple/websocket/websocket-0.2.1-py3-none-any.whl (191 kB)
Collecting greenlet
Using cached greenlet-0.4.16.tar.gz (60 kB)
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-1r2o5cjv/greenlet/setup.py'"'"'; __file__='"'"'/tmp/pip-install-1r2o5cjv/greenlet/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-u9pmz3n4
cwd: /tmp/pip-install-1r2o5cjv/greenlet/
Complete output (11 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/setuptools/__init__.py", line 19, in <module>
from setuptools.dist import Distribution
File "/usr/local/lib/python3.8/site-packages/setuptools/dist.py", line 34, in <module>
from setuptools import windows_support
File "/usr/local/lib/python3.8/site-packages/setuptools/windows_support.py", line 2, in <module>
import ctypes
File "/usr/local/lib/python3.8/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
versions
-pip 20.1.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
-Python 3.8.0
i've tried (this text had been had after the post had been published) :
this link Python3: ImportError: No module named '_ctypes' when using Value from module multiprocessing
and
Try the following command :
python3.8 -m pip install ctypes
and then try the same installation procedure you did.
Hope this helps!

Resources