简体   繁体   English

为什么NumPy可以和预装的Python 3.8一起使用,而不能和我另外安装的Python 3.9一起使用?

[英]Why can I use NumPy with Python 3.8 which was preinstalled but not with Python 3.9 which I installed in addition?

I installed Ubuntu 20.04, and python3 (3.8) is installed by default.我安装的是Ubuntu 20.04,默认安装的是python3(3.8)。 To install python3.9, I executed:为了安装 python3.9,我执行了:

sudo apt install python3.9

Thus, I have two versions of Python at my laptop: 3.8 and 3.9.因此,我的笔记本电脑上有两个版本的 Python:3.8 和 3.9。

I'm trying to launch the simple script:我正在尝试启动简单的脚本:

import numpy

With Python 3.8 it works correctly.使用 Python 3.8 它可以正常工作。 But, when I interp my script by Python 3.9 the error occurs:但是,当我通过 Python 3.9 插入我的脚本时,会发生错误:

在此处输入图像描述

How to solve this problem?如何解决这个问题呢?

I've already tried to update numpy using pip, nothing has happened.我已经尝试使用 pip 更新 numpy,但没有任何反应。

pip3 install numpy --upgrade

Likely what is happening here is, because you have 2 versions of python installed, your pip3 command is only installing things for one of the versions, 3.8 in this case.可能这里发生的事情是,因为你安装了 python 的 2 个版本,你的pip3命令只为其中一个版本安装东西,在本例中为 3.8。

Specifying the python version you want to run your command with will help solve this issue.指定要用于运行命令的 python 版本将有助于解决此问题。

For example,例如,

python3.9 -m pip install numpy

or或者

python3.8 -m pip install numpy

You can install a package for a specific version of Python with您可以为 Python 的特定版本安装 package

python3.9 -m pip install numpy

For a more consistent python environment look at python venv or a container.要获得更一致的 python 环境,请查看 python venv或容器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何卸载由 macOS 64 位 Intel 安装程序安装的 python3.9? - How can I uninstall python3.9 which installed by macOS 64-bit Intel installer? 为什么我不能将 Python package 与 Python 要求“>=3.8,<3.11”安装到 Python 版本“^3.9”的 Poetry 项目中? - Why can't I install a Python package with the Python requirement ">=3.8,<3.11" into a Poetry project with the Python version "^3.9"? 如何在 mac os x 上将 gunicorn 与 python3.8 而不是 python3.9 一起使用? - How can I use gunicorn with python3.8 instead of python3.9 on mac os x? 如何将 NumPy 1.18.5 for Python3.8 与 Anaconda 一起使用? - How can i use NumPy 1.18.5 for Python3.8 with Anaconda? 切换 Homebrew 安装的 Python 版本(3.9→3.8) - Switching Python version (3.9 → 3.8) installed by Homebrew 我卸载了python3.9并安装了python3.8,现在它显示错误“'pip'不被识别为内部或外部命令” - I uninstall python3.9 and installed python3.8 now it shows error “'pip' is not recognized as an internal or external command” 为什么我不能将已安装的模块用于python? - Why I can not use an installed module for python? 我可以在 Python 3.9 中使用带有浮点值和比较器的 Enum 并且仍然利用 numpy 操作的效率吗? - Can I use an Enum with floating point values and comparators in Python 3.9 and still leverage the efficiency of numpy operations? 在哪些情况下我可以在python中使用缩进? - In which cases can I use indentations in python? python无法检查我安装的模块 - python failed to check module which I installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM