安装Rust/Cargo是否影响Python包安装?geopandas安装报错求助
问题描述
我两天前下载并配置了Rust和Cargo,已经能在终端编写并运行一些基础程序,确认它们工作正常。今天我尝试在VSCode中用
pip install geopandas安装geopandas时,却不断遇到以下错误:Collecting geopandas Using cached geopandas-1.0.1-py3-none-any.whl (323 kB) Requirement already satisfied: numpy>=1.22 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from geopandas) (1.24.2) Requirement already satisfied: packaging in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from geopandas) (23.0) Requirement already satisfied: pandas>=1.4.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from geopandas) (2.2.1) Collecting pyproj>=3.3.0 Using cached pyproj-3.7.0.tar.gz (225 kB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [1 lines of output] proj executable not found. Please set the PROJ_DIR variable. For more information see: https://pyproj4.github.io/pyproj/stable/installation.html [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip. [notice] A new release of pip available: 22.3.1 -> 24.3.1 [notice] To update, run: pip install --upgrade pip我尝试过升级pip和setuptools,但都没用。因为是在装完Rust后才第一次遇到这个问题,所以怀疑和Rust有关。求帮助!
编辑:升级pip和setuptools后还是报同样的错;卸载Rust + Cargo后再装pyproj,问题依然存在,完全搞不懂哪里出问题了
问题分析与解决方案
别担心,这个问题和Rust/Cargo完全无关!你卸载Rust后依然报错的情况也验证了这点——只是时间上的巧合让你误以为是Rust的锅。
真正的错误根源是:geopandas依赖的pyproj包需要依赖一个叫PROJ的地理空间底层库,而你的系统里还没安装这个库,也没告诉pyproj它的位置,所以才会报proj executable not found的错误。
下面给你几个靠谱的解决办法,按省心程度排序:
方法1:用Conda安装(最推荐,自动处理所有依赖)
如果你有conda环境(比如Anaconda/Miniconda),直接用conda装geopandas,它会自动把PROJ、pyproj、geopandas以及所有相关依赖都配置好,不用手动折腾:
conda install geopandas
方法2:用Homebrew先装PROJ,再用pip安装
从你的Python路径看你用的是macOS,如果你装了Homebrew,先安装PROJ:
brew install proj
安装完成后,临时设置环境变量让pyproj找到PROJ的位置,再装geopandas:
export PROJ_DIR=$(brew --prefix proj) pip install geopandas
如果想永久生效,可以把export PROJ_DIR=$(brew --prefix proj)这句话添加到你的shell配置文件里(比如~/.zshrc或~/.bash_profile),然后执行source ~/.zshrc(对应你的配置文件)让配置生效,之后再装就不用每次设置环境变量了。
方法3:手动下载PROJ预编译包
如果没装Homebrew,可以去PROJ官网下载对应macOS的预编译压缩包,解压到某个目录(比如/usr/local/proj),然后设置环境变量再安装:
export PROJ_DIR=/usr/local/proj pip install geopandas
备注:内容来源于stack exchange,提问作者brinsz

