2

I am a beginner in Python using MacBook

I want to import pandas in my Python script and I'm typing the following command below:

import pandas as pd

which results in:

Error: -bash: import: command not found

Questions:

  1. How can I enable import command. I used #!/usr/bin/python and #!/usr/bin/env python3 as well but nothing happens after hitting enter.

  2. I am importing pandas in a folder under Documents. I hope that's OK. I can't put the path where my Python is installed, since it is in Applications folder.

2
  • sounds like you’re typing that in the terminal? maybe you should reference the documentation on how to open a REPL shell for Python Commented Sep 23, 2019 at 19:07
  • Are you running the import command from a Python prompt of directly from your bash command line? Commented Sep 23, 2019 at 19:08

2 Answers 2

4

Sounds like you need to open the Python prompt first.

Try this:

$ python
>>> import pandas as pd

Where $ is the prompt in your bash shell, and the >>> is the prompt in your Python prompt. Don't type these in.

Sign up to request clarification or add additional context in comments.

3 Comments

In that case I get error: "Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named pandas"
That's fine, this is progress. This simply means pandas is not installed. From your bash shell run: 'pip install pandas'. (Without the quotes, of course.)
I am trying but since I am new here, I am not able to due to minimum rep points. Sorry
0

I think you are running python code on shell script. I tried to get the same result by running shell script with python "import command" in it.

I created a file test.sh

#!/usr/local/bin/python

import pandas as pd

and the output was: test.sh: line 3: import: command not found

You need to run it as "/usr/local/bin/python test.py" or just "python test.py"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.