Python print statement ambiguity - python

I am running the following print statement in a file test.py within the Eclipse PyDev environment which gives the required output:
print(f"Epoch {j}: {self.evaluate(test_data)} / {n_test}")
However, when I attempt to run the same code from the file at the command prompt (OSX Terminal), I get the following
% python test.py
Traceback (most recent call last):
File "test.py", line 7, in <module>
import simple_nn
File "/Users/davidklemitz/eclipse-workspace/_neural/simple_nn.py", line 47
print(f"Epoch {j}: {self.evaluate(test_data)} / {n_test}")
^
SyntaxError: invalid syntax
Anybody have some clues to resolve the issue, thanks ?

Looks like you use two different python versions in Eclipse and your terminal. Try
python3 test.py
in your terminal

Related

Error running the pyAudioAnalysis sample program

I installed pyAudioAnalysis on python2.7 using pycharm (linux). Trying to run audioBasicIO.py gives the following error. I have installed eyeD3 but it does not work.
/usr/bin/python2.7 /usr/local/lib/python2.7/dist-packages/pyAudioAnalysis/audioBasicIO.py
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pyAudioAnalysis/audioBasicIO.py", line 6, in <module>
import eyed3
File "/home/.local/lib/python2.7/site-packages/eyed3/__init__.py", line 31, in <module>
from .utils.log import log # noqa: E402
File "/home/.local/lib/python2.7/site-packages/eyed3/utils/__init__.py", line 361
msg = f"invalid level choice: {level} (choose from {parser.log_levels})"
^
SyntaxError: invalid syntax
Is my installation incorrect? This is the first time I use this library, does anyone have any suggestions.
f-strings aren't supported for python 2.7. You need python 3.6 or above to use them. Here is a good workaround, in which you can use f-strings in below python 3.6.

How to change python command to use python2 again

I'm running a script and I get a comma error:
dbconfigure -a abc -d ...
Traceback (most recent call last):
File "/usr/local/bin/dbconf", line 6, in <module>
from dbconf import main
File "/usr/local/lib/python3.7/site-packages/dbconf/__init__.py", line 308
except SDBResponseError, exc:
^
SyntaxError: invalid syntax
So I think the script uses a python command but the python command on my computer points to a python3 version. How do I fix this?
You can put the shebang header on Unix (including mac os). First line of your script should be #! /usr/bin/env python2

Requesting solution for an error with python3.7 based aux module

I am running a python code using python3.7 in Ubuntu 18.10.
The code requires use of aux module of python.
So, I installed the aux python module.
After that if I run the code it shows the following error,
Traceback (most recent call last):
File "models.py", line 5, in <module>
from aux.ptb_aux import *
File "/home/rstudio/anaconda3/lib/python3.7/site-packages/aux/__init__.py", line 40
except Exception, e:
^
SyntaxError: invalid syntax
Can anyone please tell me what might be the source of error and the possible solution.
Thanks in advance.

SublimeREPL on Sublime Text 3 not importing Python 2.7 modules

I have been trying to configure SublimeText 3 to run SublimeREPL, setting everything so it runs as IDLE, or PyCharm IDE, but, after trying different options I checked in SO, it keeps returning:
>>> import pandas
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named pandas
>>> import os
>>> os.environ['PYTHONPATH']
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'PYTHONPATH'
I have tried editing the SublimeREPL.sublime-settings file with the default extend path file you can see at the FAQ site of SublimeREPL, but still does not work.
Does anyone know how this could be solved?
I don't know if this is the problem for you, but I was getting the exact same error and learned that by opening sublime text from the command line (e.g. 'subl .' to open the directory, once you have that shortcut set up) you get one PATH- and if you open sublime text from Spotlight Search you get another PATH. Try opening sublime text from the command line once you've confirmed you can import pandas in an interactive command line session and hopefully it will work.

Cygwin gives error using python

I want to execute below command but cygwin gives the error.
Please help me.
Python makeReadingsFile.py eichstaett.net.xml test.readings.xml
Traceback (most recent call last):
File "makeReadingsFile.py", line 75, in <module>
import argparse
ImportError: No module named argparse
As noted, the error message
$ Python makeReadingsFile.py eichstaett.net.xml test.readings.xml
Python: can't open file 'makeReadingsFile.py': [Errno 2] No such file or directory
occurs because there's no such file where you're telling it to look for one. Your second command looks to my eyes just like the first command:
Python makeReadingsFile.py eichstaett.net.xml test.readings.xml
Traceback (most recent call last):
File "makeReadingsFile.py", line 75, in <module>
import argparse
ImportError: No module named argparse
and you say that this is using the full address path, but since the given path is the same I think you must mean something like "when you change to the right directory". Anyway, the error message here is probably due to the fact you're using Python 2.6 or before: the argparse module was only introduced in Python 2.7.

Categories

Resources