如何在Jupyter中安装psqlparse Python包?安装报错求助
问题与解决方案:psqlparse 1.0rc7 安装失败
问题描述
在Jupyter中执行命令 pip install -U psqlparse==1.0rc7 安装psqlparse包时出现编译报错,询问是否可通过Jupyter或Conda完成安装,且本地已存有该包1.0rc7版本的文件及setup.py。
报错信息
Collecting psqlparse==1.0rc7 Using cached https://files.pythonhosted.org/packages/74/9e/b919842a2cfc27a212a98149c6449cedfbf388a370257af7504651925016/psqlparse-1.0rc7.tar.gz Requirement already satisfied, skipping upgrade: six in e:\anaconda\lib\site-packages (from psqlparse==1.0rc7) (1.12.0) Building wheels for collected packages: psqlparse Building wheel for psqlparse (setup.py): started Building wheel for psqlparse (setup.py): finished with status 'error' Complete output from command E:\Anaconda\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Soha\\AppData\\Local\\Temp\\pip-install-g1sf8ekh\\psqlparse\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\Soha\AppData\Local\Temp\pip-wheel-mla477je --python-tag cp37: E:\Anaconda\lib\site-packages\setuptools\dist.py:475: UserWarning: Normalizing '1.0-rc7' to '1.0rc7' normalized_version, running bdist_wheel running build running build_py creating build creating build\lib.win-amd64-3.7 creating build\lib.win-amd64-3.7\psqlparse copying psqlparse\exceptions.py -> build\lib.win-amd64-3.7\psqlparse copying psqlparse\__init__.py -> build\lib.win-amd64-3.7\psqlparse creating build\lib.win-amd64-3.7\psqlparse\nodes copying psqlparse\nodes\nodes.py -> build\lib.win-amd64-3.7\psqlparse\nodes copying psqlparse\nodes\parsenodes.py -> build\lib.win-amd64-3.7\psqlparse\nodes copying psqlparse\nodes\primnodes.py -> build\lib.win-amd64-3.7\psqlparse\nodes copying psqlparse\nodes\utils.py -> build\lib.win-amd64-3.7\psqlparse\nodes copying psqlparse\nodes\value.py -> build\lib.win-amd64-3.7\psqlparse\nodes copying psqlparse\nodes\__init__.py -> build\lib.win-amd64-3.7\psqlparse\nodes running build_ext error: [WinError 2] The system cannot find the file specified ---------------------------------------- Running setup.py clean for psqlparse Failed to build psqlparse Installing collected packages: psqlparse Running setup.py install for psqlparse: started Running setup.py install for psqlparse: finished with status 'error' Complete output from command E:\Anaconda\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Soha\\AppData\\Local\\Temp\\pip-install-g1sf8ekh\\psqlparse\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Soha\AppData\Local\Temp\pip-record-woylvw9h\install-record.txt --single-version-externally-managed --compile: E:\Anaconda\lib\site-packages\setuptools\dist.py:475: UserWarning: Normalizing '1.0-rc7' to '1.0rc7' normalized_version, running install running build running build_py creating build creating build\lib.win-amd64-3.7 creating build\lib.win-amd64-3.7\psqlparse copying psqlparse\exceptions.py -> build\lib.win-amd64-3.7\psqlparse copying psqlparse\__init__.py -> build\lib.win-amd64-3.7\psqlparse creating build\lib.win-amd64-3.7\psqlparse\nodes copying psqlparse\nodes\nodes.py -> build\lib.win-amd64-3.7\psqlparse\nodes copying psqlparse\nodes\parsenodes.py -> build\lib.win-amd64-3.7\psqlparse\nodes copying psqlparse\nodes\primnodes.py -> build\lib.win-amd64-3.7\psqlparse\nodes copying psqlparse\nodes\utils.py -> build\lib.win-amd64-3.7\psqlparse\nodes copying psqlparse\nodes\value.py -> build\lib.win-amd64-3.7\psqlparse\nodes copying psqlparse\nodes\__init__.py -> build\lib.win-amd64-3.7\psqlparse\nodes running build_ext error: [WinError 2] The system cannot find the file specified ---------------------------------------- Note: you may need to restart the kernel to use updated packages. Failed building wheel for psqlparse Command "E:\Anaconda\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Soha\\AppData\\Local\\Temp\\pip-install-g1sf8ekh\\psqlparse\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Soha\AppData\Local\Temp\pip-record-woylvw9h\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Soha\AppData\Local\Temp\pip-install-g1sf8ekh\psqlparse\
解决方案
1. 安装编译依赖(Windows环境)
psqlparse包含C扩展,需要编译工具才能完成安装。在Jupyter中执行以下命令安装Conda提供的编译套件:
!conda install -y conda-build m2w64-gcc
2. 利用本地文件安装
通过你已有的1.0rc7版本文件和setup.py,直接在Jupyter中执行本地安装:
- 先切换到包文件所在目录(示例路径为
D:\psqlparse-1.0rc7,请替换为你的实际路径):%cd D:\psqlparse-1.0rc7 - 执行pip本地安装:
!pip install . - 或使用Conda构建并安装:
!conda build . !conda install --use-local psqlparse
3. 验证安装结果
安装完成后重启Jupyter内核,执行以下命令确认安装成功:
import psqlparse print(psqlparse.__version__)
内容的提问来源于stack exchange,提问作者alireza
相关产品推荐
相关产品推荐

