Reputation: 13
I'm trying to run python scripts in Miniconda/Anaconda on WSL 2 Ubuntu 20.04 LTS.
I've created an environment with Python 3.7.10 and I got an error message when I try to import packages every time. The message is:
Command 'import' not found, but can be installed with: sudo apt install imagemagick-6.q16 # version 8:6.9.10.23+dfsg-2.1ubuntu11.2, or sudo apt install imagemagick-6.q16hdri # version 8:6.9.10.23+dfsg-2.1ubuntu11.2 sudo apt install graphicsmagick-imagemagick-compat # version 1.4+really1.3.35-1
If I'm correct, the import
command should be included in Python, and graphicsmagick-imagemagick-compat package is a set of applications to manipulate image files so I think installing these imagemagick packages won't provide help.
I also tried to use #!/home/usr/miniconda3/envs/venv/bin/python, but it doesn't work.
All I had done after installing Ubuntu and Anaconda/Miniconda include:
conda create -n venv python=3.7.10 numpy conda activate venv import numpy
Otherwise, in the venv environment, both of which python
and python --version
work, but the environment can't find import
command. I'm confused that it can find python and its path, but it can't find the import
command which is belonged to Python.
But, if I only input python
, it works. However, in this situation, I may not find and import packages that are already installed in the environment (in another environment that contains other packages I want to use).
which python /home/chihhao/miniconda3/envs/venv/bin/python python --version Python 3.7.10
Could anyone provide some help?
Thanks.
Upvotes: 1
Views: 8673
Reputation: 19250
First off, you should go through a python tutorial. You can start with https://docs.python.org/3/tutorial/index.html.
You want to run import
in a python shell or a python script. Right now, you are running it in a bash terminal, and bash doesn't know what import
means.
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
>>>
If you have a python script with the name script.py
and the contents
import numpy
you can run it with python script.py
.
Upvotes: 3