jayaprakash reddy
jayaprakash reddy

Reputation: 43

Security policy error importing matplotlib

After installing matplotlib. I am getting this error while using this command :

$ import matplotlib
import-im6.q16: attempt to perform an operation not allowed by the security policy `PS` @ error/constitute.c/IsCoderAuthorized/408.

Can anyone help me solve this?

Upvotes: 4

Views: 6945

Answers (4)

knb
knb

Reputation: 9295

See the other, older answers. They are very good.

Another possible reason: It might be a cut-and-paste-from-clipboard error.

You may have blanks before your #!/usr/bin/env python3 line, and at the beginning of all following lines. Thus your script is still a valid python-script but the shell cannot interpret the #!/usr/bin/env python3 line. It thus reads your script as a bash script.

It might help to remove the whitespace; or call the script with python3 myscript.py

Upvotes: 1

Mauro F.
Mauro F.

Reputation: 392

You are calling import matplotlib not from the python shell, but from the system shell. The error you are seeing is from the import command, which according to man import saves a portion of a screen to an image. This also happens if you execute a script by calling it without putting a shabang on the first line (like #!/usr/bin/env python3)

Upvotes: 6

Simone Starace
Simone Starace

Reputation: 166

Depends on how you do import matplotlib

The problem can be solved with just one of the following solutions.

  1. If you're using the Python interpreter, the one from the command line, then this shouldn't happen because you are simply importing the module.
  2. If you wrote the line of code in a Python file, suppose we call the file myfile.py, and you're trying to execute it on the command line like ./myfile.py then it's wrong because you have to write on the command line python myfile.py or python3 myfile.py, if you're using Python3
  3. You can simply specify the python interpreter on your file by adding at the first line of the file #!/bin/python or #!/usr/bin/python and then on the command line you can simply run your file like a bash file ./myfile.py

Upvotes: 1

Stefan_EOX
Stefan_EOX

Reputation: 1529

This happens to me if I run import from the shell. Demonstration:

$ import
import-im6.q16: missing an image filename `import' @ error/import.c/ImportImageCommand/1289.

This askubuntu question tells me that import is a built-in ImageMagick command.

Solution

You first have to start a Python interactive prompt:

python
>>> import matplotlib

Upvotes: 1

Related Questions