安装Python包时出现的问题

5
请参见我的之前的问题(此处)。我已经花了一整天时间搜索我的问题,仍然遇到 pip 安装问题。这次我的错误信息略有不同。自上次发布以来我所做的内容:
  1. 确保在系统环境变量下添加了 C:\mysys64\mingw64\bin
  2. 编辑 VSCode 中的 c_cpp_properties.json 文件,具体地更改 "intelliSenseMode""windows-msvc-x64" 改为 "windows-gcc-x64"
  3. 重新检查 C:\msys64\mingw64\include\python3.9\Python.h 目录下的 Python.h 文件,以确保通过 #include <unistd.h> 的方式解决了错误。
  4. 重试 pip install Flask-SQLAlchemy 后,现在出现以下错误...

终端窗口输出

Using cached Flask_SQLAlchemy-2.5.1-py2.py3-none-any.whl (17 kB)
Collecting SQLAlchemy>=0.8.0
  Using cached SQLAlchemy-1.4.29.tar.gz (8.0 MB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: Flask>=0.10 in c:\msys64\mingw64\lib\python3.9\site-packages (from Flask-SQLAlchemy) (2.0.2)
Requirement already satisfied: itsdangerous>=2.0 in c:\msys64\mingw64\lib\python3.9\site-packages (from Flask>=0.10->Flask-SQLAlchemy) (2.0.1)
Requirement already satisfied: Jinja2>=3.0 in c:\msys64\mingw64\lib\python3.9\site-packages (from Flask>=0.10->Flask-SQLAlchemy) (3.0.3)
Requirement already satisfied: click>=7.1.2 in c:\msys64\mingw64\lib\python3.9\site-packages (from Flask>=0.10->Flask-SQLAlchemy) (8.0.3)
Requirement already satisfied: Werkzeug>=2.0 in c:\msys64\mingw64\lib\python3.9\site-packages (from Flask>=0.10->Flask-SQLAlchemy) (2.0.2)
Collecting greenlet!=0.4.17
  Using cached greenlet-1.1.2.tar.gz (91 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: colorama in c:\msys64\mingw64\lib\python3.9\site-packages (from click>=7.1.2->Flask>=0.10->Flask-SQLAlchemy) (0.4.4)
Requirement already satisfied: MarkupSafe>=2.0 in c:\msys64\mingw64\lib\python3.9\site-packages (from Jinja2>=3.0->Flask>=0.10->Flask-SQLAlchemy) (2.0.1)
Building wheels for collected packages: SQLAlchemy, greenlet
  Building wheel for SQLAlchemy (setup.py) ... done
  Created wheel for SQLAlchemy: filename=SQLAlchemy-1.4.29-cp39-cp39-win_amd64.whl size=1512539 sha256=80ef3cf51b84f92e8117a57097054fcb25807ebf7755115d7df299bacf17a09d
  Stored in directory: c:\users\t\appdata\local\pip\cache\wheels\6d\94\a6\8bdac6f92ce851f71a9fa62934a06cf2b654700b5f258242c7
  Building wheel for greenlet (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\msys64\mingw64\bin\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\t\\AppData\\Local\\Temp\\pip-install-p182wkp5\\greenlet_78bb1f8ef93a452d8f0a86edfe24f6dd\\setup.py'"'"'; __file__='"'"'C:\\Users\\t\\AppData\\Local\\Temp\\pip-install-p182wkp5\\greenlet_78bb1f8ef93a452d8f0a86edfe24f6dd\\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'"'"'))' bdist_wheel -d 'C:\Users\t\AppData\Local\Temp\pip-wheel-iwgszyll'
       cwd: C:\Users\t\AppData\Local\Temp\pip-install-p182wkp5\greenlet_78bb1f8ef93a452d8f0a86edfe24f6dd\
  Complete output (69 lines):

然后出现了一些其他的错误,就像这样

"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\msys64\mingw64\include -IC:\msys64\mingw64\include\python3.9 "-IC:\Program 
Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt" /Tcsrc/greenlet/greenlet.c /Fobuild\temp.win-amd64-3.9\Release\src/greenlet/greenlet.obj
  greenlet.c
  C:\msys64\mingw64\include\python3.9\Python.h(36): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory
  error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.30.30705\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
  ----------------------------------------
  ERROR: Failed building wheel for greenlet
  Running setup.py clean for greenlet
Successfully built SQLAlchemy
Failed to build greenlet
Installing collected packages: greenlet, SQLAlchemy, Flask-SQLAlchemy
    Running setup.py install for greenlet ... error
    ERROR: Command errored out with exit status 1:

然而,在我的Python.h文件中,#include <unistd.h>下再也没有波浪线的错误了。请注意,我不知道我在尝试修复它时在做什么。如果有解决方案,请告诉我。

2022.02.01更新:我已经卸载了Python版本3.9.7并安装了版本3.10.2。我已将pip更新到版本22.02.2并尝试了以下解决方案。下载了greenlet-1.1.2-cp310-cp310-win32.whlgreenlet-1.1.2-cp310-cp310-win_amd64.whl文件后,我进入我的下载文件夹并执行以下命令:

C:\Users\t\Downloads>C:\msys64\mingw64\bin\python.exe -m pip install greenlet-1.1.2-cp310-cp310-win_amd64.whl
ERROR: greenlet-1.1.2-cp310-cp310-win_amd64.whl is not a supported wheel on this platform.

C:\Users\t\Downloads>C:\msys64\mingw64\bin\python.exe -m pip install greenlet-1.1.2-cp310-cp310-win32.whl
ERROR: greenlet-1.1.2-cp310-cp310-win32.whl is not a supported wheel on this platform.

在那之后,我试着用pip install greenlet 直接安装greenlet,并得到了以下输出:

Building wheels for collected packages: greenlet
  Building wheel for greenlet (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
   exit code: 1
  ╰─> [69 lines of output]

并且往下

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for greenlet
  Running setup.py clean for greenlet
Failed to build greenlet
Installing collected packages: greenlet
  Running setup.py install for greenlet ... error
  error: subprocess-exited-with-error

  × Running setup.py install for greenlet did not run successfully.
   exit code: 1
  ╰─> [71 lines of output]

仍然在更深层次(希望这能为解决问题提供一些线索)

error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.30.30705\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> greenlet

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

说实话,你为什么不在只有pip install SQLAlchemy的情况下向我们展示你的错误呢?其他的Jinja、Flask等等只会增加噪音。 - JL Peyret
您可能需要使用-I-L标志来调整SQLAlchemy的pip安装命令。例如,对于Pygraphviz,文档提供了一个示例。您可能需要尝试几次,我不得不指向比我最初想到的更高的位置。 - JL Peyret
是的,抱歉,我想既然我不是专家,展示更多可能会更好。而且我浪费了时间更新Visual Studio而不是VSCode...无论如何,这就是我的进展。我遵循了这个指南。我运行了-m pip install --upgrade pip setuptools wheel并得到了这个警告:WARNING: The script wheel.exe is installed in 'C:\Users\t\AppData\Roaming\Python\Python39\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. - Duke3e33
这个警告信息是:WARNING: The scripts pip.exe, pip3.9.exe and pip3.exe are installed in 'C:\Users\t\AppData\Roaming\Python\Python39\Scripts' which is not on PATH. 不确定是否会造成问题。然后我运行了 py -m pip install SQLAlchemy 命令,结果显示 Installing collected packages: greenlet, SQLAlchemy Successfully installed SQLAlchemy-1.4.29 greenlet-1.1.2 ,但是当我运行 pip list 命令时,这两个软件包都没有列出来...... 我已经不知道怎么办了。 - Duke3e33
5个回答

2
以下命令解决了我在 M1 Mac 上的问题 -
- brew install graphviz
- python3 -m pip install \           
    --global-option=build_ext \
    --global-option="-I$(brew --prefix graphviz)/include/" \
    --global-option="-L$(brew --prefix graphviz)/lib/" \
    pygraphviz

1

py -m pip 中的 pip 与 pip list 中的 pip 不同。您可以通过 py -m pip --versionpip --version 来获取 pip 的位置。

我可以通过以下方式成功安装 greenlet 包:

pip install greenlet --no-cache-dir

我正在使用Python310,看起来与Python39有一些问题。如果不行,可以像@FlyingTeller建议的那样手动下载。

正如你所描述的那样,greenlet-1.1.2-cp39-cp39-win_amd64.whl不起作用,那么你尝试过greenlet‑1.1.2‑cp39‑cp39‑win32.whl了吗?

>>> import platform
>>> platform.architecture()

你可以通过以上代码获取架构。


你是在建议我手动下载源文件类型从这里吗? - Duke3e33
@Duke3e33 很抱歉晚了,platform.architecture() 的结果是什么? - Steven-MSFT
这是你要找的信息吗?运行该命令后,输出结果为 `>>> import platform
platform.architecture() ('64bit', 'WindowsPE') `
- Duke3e33
@msys64 抱歉,您能尝试安装普通的 Python 吗?而不是与 msys64 相关的版本? - Steven-MSFT
我们能否重新审视一下这个问题?我已经下载了Python 3.10.2并尝试再次进行pip安装,但仍然存在问题。不过,由于使用了更新版本的pip,我已经获得了更多有关错误信息的信息。请查看更新。 - Duke3e33
显示剩余2条评论

0

我在 Mac M1 上的 PyCharm 中安装 greenlet 2.0.1 遇到了问题。

我已经进行了升级:

pip install --upgrade pip

pip install --upgrade setuptools wheel

还要感谢 @joydeba 的评论 - 我已经安装了 Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

*请按照安装结束时的说明进行操作

完成这些步骤后,我能够在PyCharm中轻松安装greenlet!


0

您可以从这里下载适当的whl文件并进行安装。

对于您来说,greenlet-1.1.2-cp39-cp39-win_amd64.whl应该是正确的。下载后,cd到您的下载目录并运行

C:\msys64\mingw64\bin\python.exe -m pip install greenlet‑1.1.2‑cp39‑cp39‑win_amd64.whl

然后再尝试您的原始安装。

注意

同一网站上还有一个名为Flask_SQLAlchemy‑2.5.1‑py3‑none‑any.whl的whl文件可供下载和安装。


1
你好,当我运行从我的下载中的命令时,出现以下错误: C:\Users\t\Downloads>C:\msys64\mingw64\bin\python.exe -m pip install greenlet-1.1.2-cp39-cp39-win_amd64.whl ERROR: greenlet-1.1.2-cp39-cp39-win_amd64.whl 不支持当前平台。 - Duke3e33

0

我更新了 pipsetuptoolswheel,问题得到了解决。

pip install --upgrade pip
pip install --upgrade setuptools wheel

注意:如果你的pip被别名为pip3(Python 3),请使用pip3而不是pip

 pip3 install --upgrade pip
 pip3 install --upgrade setuptools wheel

请参考此链接获取更多信息: https://bobbyhadz.com/blog/python-error-legacy-install-failure


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接