"Command 'import' not found, but can be installed with" 在 MiniConda 中

"Command 'import' not found, but can be installed with" in MiniConda

我正在尝试 运行 python WSL 2 Miniconda/Anaconda 中的脚本 Ubuntu 20.04 LTS。

我用 Python 3.7.10 创建了一个环境,每次尝试导入包时都收到错误消息。消息是:

命令 'import' 未找到,但可以通过以下方式安装:

sudo apt install imagemagick-6.q16 # version 8:6.9.10.23+dfsg-2.1ubuntu11.2, 或者
sudo apt install imagemagick-6.q16hdri # 版本 8:6.9.10.23+dfsg-2.1ubuntu11.2
sudo apt 安装 graphicsmagick-imagemagick-compat # version 1.4+really1.3.35-1

如果我是对的,import 命令应该包含在 Python 中,而 graphicsmagick-imagemagick-compat 包是一组处理图像文件的应用程序,所以我认为安装这些 imagemagick软件包不会提供帮助。

我也试过用#!/home/usr/miniconda3/envs/venv/bin/python,但是不行。

我在安装 Ubuntu 和 Anaconda/Miniconda 之后所做的一切包括:

conda create -n venv python=3.7.10 numpy
畅达激活静脉
导入 numpy

否则在venv环境下,which pythonpython --version都可以,但是环境找不到import命令。我很困惑它可以找到 python 及其路径,但找不到属于 Python.

import 命令

但是,如果我只输入 python,就可以了。 但是,在这种情况下,我可能无法找到并导入环境中已安装的包(在包含我要使用的其他包的另一个环境中)。

python
/home/chihhao/miniconda3/envs/venv/bin/python

python --版本
Python 3.7.10

有人可以提供帮助吗?

谢谢。

首先,您应该学习 python 教程。您可以从 https://docs.python.org/3/tutorial/index.html.

开始

您想在 python shell 或 python 脚本中 运行 import。现在,您正在 运行 将其连接到 bash 终端,而 bash 不知道 import 是什么意思。

user@foo:~$ conda activate venv
user@foo:~$ python
Python 3.8.6 | packaged by conda-forge | (default, Oct  7 2020, 19:08:05) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> 

如果您有一个名为 script.py 且内容为

的 python 脚本
import numpy

你可以 运行 它与 python script.py