为啥 python 使用 3.8.1 和 3.9,然后无法安装包(错误:包 pkg 需要不同的 Python:3.8.1 不在 '>=3.9.0' 中)?

Posted

技术标签:

【中文标题】为啥 python 使用 3.8.1 和 3.9,然后无法安装包(错误:包 pkg 需要不同的 Python:3.8.1 不在 \'>=3.9.0\' 中)?【英文标题】:Why is python using 3.8.1 and 3.9, then fail to install packages (ERROR: Package pkg requires a different Python: 3.8.1 not in '>=3.9.0')?为什么 python 使用 3.8.1 和 3.9,然后无法安装包(错误:包 pkg 需要不同的 Python:3.8.1 不在 '>=3.9.0' 中)? 【发布时间】:2022-01-15 07:15:29 【问题描述】:

我正在尝试测试my ultimate-utils library 的安装,但出现了这个奇怪的错误:

(meta_learning) brandomiranda~/ultimate-utils ❯ pip install -e .
Obtaining file:///Users/brandomiranda/ultimate-utils
  Preparing metadata (setup.py) ... done
Collecting dill
  Using cached dill-0.3.4-py2.py3-none-any.whl (86 kB)
Collecting networkx>=2.5
  Using cached networkx-2.6.3-py3-none-any.whl (1.9 MB)
Requirement already satisfied: scipy in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from ultimate-utils==0.5.3) (1.7.3)
Collecting scikit-learn
  Using cached scikit_learn-1.0.1-cp38-cp38-macosx_10_13_x86_64.whl (7.9 MB)
Collecting lark-parser
  Using cached lark_parser-0.12.0-py2.py3-none-any.whl (103 kB)
Collecting torchtext==0.10.1
  Using cached torchtext-0.10.1-cp38-cp38-macosx_10_9_x86_64.whl (1.6 MB)
Collecting tensorboard
  Using cached tensorboard-2.7.0-py3-none-any.whl (5.8 MB)
Collecting pandas
  Using cached pandas-1.3.4-cp38-cp38-macosx_10_9_x86_64.whl (11.4 MB)
Collecting progressbar2
  Using cached progressbar2-3.55.0-py2.py3-none-any.whl (26 kB)
Collecting transformers
  Using cached transformers-4.13.0-py3-none-any.whl (3.3 MB)
Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from ultimate-utils==0.5.3) (2.26.0)
Collecting aiohttp
  Using cached aiohttp-3.8.1-cp38-cp38-macosx_10_9_x86_64.whl (574 kB)
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from ultimate-utils==0.5.3) (1.21.4)
Collecting plotly
  Using cached plotly-5.4.0-py2.py3-none-any.whl (25.3 MB)
Collecting wandb
  Using cached wandb-0.12.7-py2.py3-none-any.whl (1.7 MB)
Collecting matplotlib
  Using cached matplotlib-3.5.0-cp38-cp38-macosx_10_9_x86_64.whl (7.3 MB)
Requirement already satisfied: torch<1.10.0,>=1.4.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from ultimate-utils==0.5.3) (1.9.1)
Requirement already satisfied: torchvision<0.11.0,>=0.5.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from ultimate-utils==0.5.3) (0.10.1)
Requirement already satisfied: torchaudio<0.10.0,>=0.9.1 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from ultimate-utils==0.5.3) (0.9.1)
ERROR: Package 'ultimate-utils' requires a different Python: 3.8.1 not in '>=3.9.0'

但是,如果您检查依赖项似乎已正确安装 - 所以我很困惑这条消息的含义。

此外,如果您更仔细地阅读该消息,您还会看到它出于某种原因引用了 3.8(python 3.8?不确定),请参阅:

Requirement already satisfied: torch<1.10.0,>=1.4.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from ultimate-utils==0.5.3) (1.9.1)
Requirement already satisfied: torchvision<0.11.0,>=0.5.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from ultimate-utils==0.5.3) (0.10.1)
Requirement already satisfied: torchaudio<0.10.0,>=0.9.1 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from ultimate-utils==0.5.3) (0.9.1)
ERROR: Package 'ultimate-utils' requires a different Python: 3.8.1 not in '>=3.9.0'

但如果我要求 pythons 版本,它是我期望的 3.9:

(meta_learning) brandomiranda~/ultimate-utils ❯ python
Python 3.9.7 (default, Sep 16 2021, 08:50:36)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

所以我很困惑到底发生了什么。我想知道pycharm是否与此有关。但是为什么说它没有安装我的 uutils 库呢?

检查点子列表确认它不存在:

(meta_learning) brandomiranda~/ultimate-utils ❯ pip list
Package                Version
---------------------- ---------
argcomplete            1.12.3
astroid                2.3.3
boto                   2.49.0
certifi                2021.10.8
cffi                   1.15.0
charset-normalizer     2.0.9
cloudpickle            2.0.0
crcmod                 1.7
cryptography           36.0.0
fasteners              0.16.3
gcs-oauth2-boto-plugin 3.0
google-apitools        0.5.32
google-reauth          0.1.1
gsutil                 5.5
gym                    0.21.0
httplib2               0.20.2
idna                   3.3
isort                  4.3.21
lazy-object-proxy      1.4.3
learn2learn            0.1.6
mccabe                 0.6.1
monotonic              1.6
nodejs                 0.1.1
numpy                  1.21.4
oauth2client           4.1.3
optional-django        0.1.0
Pillow                 8.4.0
pip                    21.3.1
pyasn1                 0.4.8
pyasn1-modules         0.2.8
pycparser              2.21
pylint                 2.4.4
pyOpenSSL              21.0.0
pyparsing              3.0.6
pyu2f                  0.1.5
qpth                   0.0.15
requests               2.26.0
retry-decorator        1.1.1
rsa                    4.7.2
scipy                  1.7.3
setuptools             41.2.0
six                    1.14.0
torch                  1.9.1
torchaudio             0.9.1
torchvision            0.10.1
tqdm                   4.62.3
typing_extensions      4.0.1
urllib3                1.26.7
wrapt                  1.11.2

从 uutils 运行导入确认它没有安装:

(meta_learning) brandomiranda~/ultimate-utils ❯ python -c "import uutils; uutils.hello()"
python -c "import uutils; uutils.torch_uu.hello()"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'uutils'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'uutils'

奇怪的是,这在 python 3.9 之前已经有效。所以有些东西改变了,我不知道是什么。


这一定是python路径问题,因为现在它在删除python 3.8(我从未安装过......)后打开了2.7。我认为 conda init 没有正确启动我的 shell。在哪里:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/brandomiranda/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/brandomiranda/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/brandomiranda/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/brandomiranda/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

假设进入.zshrc 文件?


参考/相关链接:

Can't install new packages for Python (Python 3.9.0, Windows 10) Why does Pip claim that a version of Python is not in a given range? How does one install PyTorch and related tools from within the setup.py install_requires list? https://github.com/brando90/ultimate-utils Python OSX $ which Python gives /Library/Frameworks/Python.framework/Versions/2.7/bin/python Why is conda init updating my .bash_profile incorrectly? How to uninstall Anaconda completely from macOS https://superuser.com/questions/121870/how-do-i-reset-the-path-variable-on-mac-os-x https://github.com/brando90/.dotfiles/blob/master/README.md

【问题讨论】:

您是否检查了环境变量中python文件夹的路径是旧版本的python还是旧版本?尝试使用python -m pip install &lt;package&gt; 我真的不知道 conda 文件应该在哪里,但如果你说你在 python -V 上的 python 版本 >= 3.9.0 python -m pip install &lt;package&gt; 应该可以工作。 @merv 是的,这是正确的。看来我的PATH 搞砸了。但不知何故,在初始化我的 shell 之后,我的 .zshrc 不知何故不足以或正确地拥有正确的 PATH。我怀疑 conda 可能也会发生一些奇怪的事情。所以我从头开始重新安装 conda 并查看是否可以修复它。如果您对如何设置 PATH 有任何想法,请告诉我,我以前从未遇到过这么多问题... @merv 它在 mac 终端中被 borken。我不知道问题是什么。我的.zshenv 除了采购.zshrc 之外什么都没有。我不知道该怎么办。我将首先尝试让我的.zshrc 文件以全新的PATH 开头。例如PATH=/usr/bin:/bin:/usr/sbin:/sbin然后在.zshrc 文件中执行export PATH。看起来很老套,但我需要从某个地方开始。 @merv 似乎已经解决了。基本上我只是用原始路径覆盖我的路径。 【参考方案1】:

一旦我开始使用 python 3.9(而不是 3.10,可能使用最新版本的 python 是个坏主意,所以我学会了落后于大多数软件版本以避免奇怪的错误),然后我确定我的mac 的新默认 shell zsh 有一个全新的原始路径:

PATH=/usr/bin:/bin:/usr/sbin:/sbin
export PATH

在它的顶部。

# In my 2013 mac this seems to be needed
PATH=/usr/bin:/bin:/usr/sbin:/sbin
export PATH

# let zplug manage itself
zplug "zplug/zplug"

## Plugins for zsh

# new `jump`
zplug "plugins/wd", from:oh-my-zsh

## prompt
## to test do: print -P '%B%Fredco%Fgreenlo%Fbluers%f%b'
# ref: http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Prompt-Expansion
# ref: reference: https://wiki.archlinux.org/index.php/Zsh#Colors
# ref: https://scriptingosx.com/2019/07/moving-to-zsh-06-customizing-the-zsh-prompt/
# %Fcolor sets colour until next color of %f, %B infront of that changes tone

PROMPT="%B%Fmagenta%n%B%Fred%~%B%Fgreen %Fcyan❯%f "


## jump TODO: switch to zsh's wd

#conda activate metalearning
# conda activate synthesis
conda activate meta_learning

## Aliases
alias grep='grep --color=auto'
alias intel='ssh -i ~/.ssh/intel_id_rsa miranda9@ssh-iam.intel-research.net'
alias hal='ssh miranda9@hal.ncsa.illinois.edu'
alias vision='ssh miranda9@vision-submit.cs.illinois.edu'
alias nano='ssh miranda9@nano.ncsa.illinois.edu'
alias dgx='ssh miranda9@hal-dgx.ncsa.illinois.edu'
alias sshcc='ssh miranda9@cc-login.campuscluster.illinois.edu'

#alias tb='tensorboard --logdir'
alias tbb='sh /Users/brando/ultimate-utils/run_tb.sh'

export WANDB_API_KEY=MY SCRETE MUAHAHAHA

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/brandomiranda/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/brandomiranda/opt/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/brandomiranda/opt/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/brandomiranda/opt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

我还重新安装了 python,删除了 python 框架 3.8 并重新安装了 conda 作为图形界面,但我不认为这些是让事情正常运行的原因。我相当有信心这是正确的。

【讨论】:

这是否解决了您的问题,或者这是您问题的更多信息?既然你已经回答了自己的问题,从旁观者看来你的问题已经解决了 @nanotek 确实这似乎已经解决了我的问题(目前)。但我确实更愿意接受别人的答案,而不是我自己对我的问题的回答。通常他们会更好。尤其是在这种情况下,我觉得我不了解 Python 中的 PATH 问题/细微差别,并且感觉更像是当前正在运行的 hack。

以上是关于为啥 python 使用 3.8.1 和 3.9,然后无法安装包(错误:包 pkg 需要不同的 Python:3.8.1 不在 '>=3.9.0' 中)?的主要内容,如果未能解决你的问题,请参考以下文章

为啥使用 Make 3.8.1 构建与 Make 4.1 不同?

python ≥3.9 中的只读类属性,支持 `help()`

Sanic over alpine:latest(3.9) 的 Docker 镜像使用 python json 而不是 ujson

Python 3.9:使用标准库构造 DST 有效时间戳

如何在 Python 3.9 中从 re.sub 中删除反斜杠

Python 3.9 – 使用 pandas 读取 google sheet 文件会导致回溯错误