Apache Zeppelin: configuration of python interpreter on Windows - python

I'm having some troubles with running Zeppelin Python notebook on Windows. It looks like some output problem with several SyntaxError: invalid syntax errors. E.g. the code
%python
import numpy as np
print np.random.randn(10)
results in
^
SyntaxError: invalid syntax
[ 0.3144414 0.2340006 0.86525395 -0.24519029 -1.19862891 -0.88127259
-1.64757093 1.39753151 -0.50873422 -1.39649112]
File "<stdin>", line 1
z._displayhook()
^
SyntaxError: invalid syntax
File "<stdin>", line 1
^
SyntaxError: invalid syntax
File "<stdin>", line 1
Similarly when plotting with matplotlib the code is executed, but the actual figures are not shown (perhaps due to the output problems):
%python
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
gives an error:
^
SyntaxError: invalid syntax
[<matplotlib.lines.Line2D object at 0x0000000004D737B8>]
File "<stdin>", line 1
z._displayhook()
^
SyntaxError: invalid syntax
File "<stdin>", line 1
^
SyntaxError: invalid syntax
File "<stdin>", line 1
ERROR
I'd appreciate any suggestions or help!

There is an easy work around. In the Interpreters management section
under the python interpreter set the following zeppelin.python property value to python -i
zeppelin.python python -i
(worked for me with v2.7.13)

It appears that Zeppelin doesn't currently support Windows's using python interpreter. You'll need to spin up a different envirornment using a VM.
https://issues.apache.org/jira/browse/ZEPPELIN-1436

Related

Same code differs in output across IDE's & pyshell

I was running this code on VScode.
age_1 = int(input("age : "))
print(age_1)
It shows this at it's terminal output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'print(age_1)
In Pycharm it shows this output after taking input as 12 :
age : 12
12
In PyShell it works like the Pycharm one. What did I do wrong in the VScode ?
Update :
When ran on a new file on VScode, it ran properly like the Pycharm one. But only for once . Then it shows up same error like before along with some new kinds of error everytime it ran.
Here's the correct one in VScode when ran the 1st time.
PS I:\CSE\LEARNING\PYTHON 3.0\practice> & "C:/Users/Alvi Adhikary Niloy/AppData/Local/Programs/Python/Python39/python.exe" "i:/CSE/LEARNING/PYTHON 3.0/practice/tempCodeRunnerFile.py"
age : 12
12
Here's one error when ran another time.
& "C:/Users/Alvi Adhikary Niloy/AppData/Local/Programs/Python/Python39/python.exe" "i:/CSE/LEARNING/PYTHON 3.0/practice/tempCodeRunnerFile.py"
File "<stdin>", line 1
& "C:/Users/Alvi Adhikary Niloy/AppData/Local/Programs/Python/Python39/python.exe" "i:/CSE/LEARNING/PYTHON 3.0/practice/tempCodeRunnerFile.py"
^
SyntaxError: invalid syntax
Here's another error :
>>>print(age_1) age1 = int(input("age : "))
File "<stdin>", line 1
print(age_1) age1 = int(input("age : "))
^
SyntaxError: invalid syntax
& here's the final one .
>>> print(age1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'age1' is not defined
P.S. I ain't skilled in coding. Explaining with some codes patiently will be appretiated.
The Python ValueError: invalid literal for int() with base 10 error is raised when you try to convert a string value that is not formatted as an integer. ... Then, you can use int() to convert your number to an integer. If this does not work, make sure that the value of a string does not contain any letters.I think you wrote a word that does not change int in the input. Maybe it's a space

Trying to make a log function

I want to make a log function in my script but I don`t know why it gives me this error
File "c:/Users/x/x/x", line 33
log = open(f"Log/{realDate.strftime("%x")}.txt", "a")
^
SyntaxError: invalid syntax
Here`s the code that is causing the problem
realDate = datetime.datetime.now()
log = open(f"Log/{realDate.strftime("%x")}.txt", "a")
log.write("Hello Stackoverflow!")
log.close()
Can somebody please help me?
The problem is that you are trying to nest double quotes inside double quotes; f-strings don't allow that. You would need to change one or the other to another style of quotes. For example:
log = open(f'Log/{realDate.strftime("%x")}.txt', "a")
The main problem is that you aren't using a version of Python that supports f-strings. Make sure you are using Python 3.6 or later. (Update: Even in Python 3.6 or later, the identified location of the error can shift:
>>> f"{print("%x")}"
File "<stdin>", line 1
f"{print("%x")}"
^
SyntaxError: invalid syntax
>>> f"{print("x")}"
File "<stdin>", line 1
f"{print("x")}"
^
SyntaxError: invalid syntax
)

python console to call function

I know this is an easy fix, but could someone tell me how to call a python file in the python Console who have this symbol: -.
Here is my mistake:
>>> import main #no error here
>>> import a1-devoir1
File "<input>", line 1
import a1-devoir1
Syntax Error: invalid syntax
You must name your files so that they only contains letters, underscores, or numbers (but not as the first character). All libraries and modules must follow this.
So rename your .py file to a1_devoir and then try import a1_devoir

How to fix SyntaxError: invalid syntax on a Raspberry Pi?

I have code wrote on Windows, compiles and works correctly, but fails on the raspberry pi
wrote some simple test code to see if it spits out the same error
a = input('this is a test string to split at space \n').split()
print(a)
typed 15:00 (need this data point for the bigger project) and i got this error
15:00
Traceback (most recent call last):
File "test.py", line 1, in <module>
a = input('this is a test string to split at : \n').split(':')
File "<string>", line 1
15:00
^
SyntaxError: invalid syntax
then tried 15 00 at the request of someone on discord, got this message
15 00
Traceback (most recent call last):
File "test.py", line 2, in <module>
a = input('this is a test string to split at : \n').split(':')
File "<string>", line 1
15 00
^
SyntaxError: unexpected EOF while parsing
You may be running different versions of python from windows to Raspberry Pi.
Thanks to this answer:
Note: this is only for Python 2. For Python 3, raw_input() has become
plain input() and the Python 2 input() has been removed.
Reference
a = raw_input('this is a test string to split at space \n').split(':')
print(a)

Invalid literal for int() with base 16

I have a problem with the below code. I am running python script to run exe and pass parameters to it. I get the below error:
ValueError invalid literal for int() with base 16:
However if i put an extra semi colon (which I don't need) after 0 and before double quote it will work. Is something wrong with my string?
program="C:\Program Files (x86)\program.exe"
args='"21022019;A0A1A2A3A4A5A6A7;B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF;1;1982;0"-e fixed -k aa11bb22cc33dd44ee55ff6600112233 -f jf_Creds_python.hex'
subprocess.call([program,args])
This is the full error:
Traceback (most recent call last):
File "<string>", line 249, in <module>
File "<string>", line 53, in main
ValueError: invalid literal for int() with base 16: '"21022019'
I have found a fix but do not really understand it.
program="C:\Program Files (x86)\program.exe"
args='"21022019;A0A1A2A3A4A5A6A7;B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF;1;1982;0"-e fixed -k aa11bb22cc33dd44ee55ff6600112233 -f jf_Creds_python.hex'
subprocess.call([program,{args}])
If I place curly braces around args, it will be successful. It works now, but I'm not fully sure how it is working, if someone might explain it would be great?

Categories