简体   繁体   中英

Running a Python Script using Pyzo from the Editor

This is my first time to use python. I am using IDE Pyzo and trying to run the following script.

import matplotlib.pyplot as plt 
from numpy.random import normal,rand
x = normal(size=200)
plt.hist(x, bins=30)
plt.show()

When I run it line by line from the shell it is working. But when I try to run it from the editor "Run the file as script" it gives the following error:

>>> %cd "c:\program files (x86)\pyzo"
  File "<console>", line 1
    %cd "c:\program files (x86)\pyzo"
    ^
SyntaxError: invalid syntax

>>> %run -i "C:\Program Files (x86)\pyzo\Test.py"
  File "<console>", line 1
    %run -i "C:\Program Files (x86)\pyzo\Test.py"
    ^
SyntaxError: invalid syntax

Any idea how to run the script without error?

Try specifying the two imports on different lines

import matplotlib.pyplot as plt 
from numpy.random import normal,rand

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM