1

I am running python3.5 on a RPi3 and have installed matplotlib and numpy. I can import when in the shell, but not from within the terminal, per below:

Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] on linux
Type "copyright", "credits" or "license()" for more information.
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> 

.

pi@raspberrypi:~ $ python3 -V
Python 3.5.3
pi@raspberrypi:~ $ import numpy as np
bash: import: command not found
pi@raspberrypi:~ $ import numpy
bash: import: command not found
pi@raspberrypi:~ $ import matplotlib.pyplot as plt
bash: import: command not found
pi@raspberrypi:~ $ 

Any ideas on why this would be the case?

1
  • 1
    python3 -V runs once to print the version then exits. Use python3 with no special flags to get an interpreter shell. Or code your python stuff in a file with nano myprog.py then run it with python3 myprog.py. Commented Mar 4, 2019 at 6:20

1 Answer 1

4

To run python inside a Linux terminal, you first have to execute python using the command python3.

Example on my Raspberry Pi:

pi@raspberrypi ~ $ python3
Python 3.2.3 (default, Mar 25 2017, 13:24:50)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Test")
Test
>>> exit()
pi@raspberrypi ~ $

Changed to python 3 example after @Dougie 's comment.

1
  • 4
    We should all be encouraging new programmers to forget about python2 and always use python3 for their new code. Commented Mar 4, 2019 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.